auth_(object_type)_meta_(meta_key) filter-hookWP 4.6.0

Filters whether the user is allowed to edit a specific meta key of a specific object type.

Return true to have the mapped meta caps from edit_{$object_type} apply.

The dynamic portion of the hook name, $object_type refers to the object type being filtered. The dynamic portion of the hook name, $meta_key, refers to the meta key passed to map_meta_cap().

Usage

add_filter( 'auth_(object_type)_meta_(meta_key)', 'wp_kama_auth_object_type_meta_key_filter', 10, 6 );

/**
 * Function for `auth_(object_type)_meta_(meta_key)` filter-hook.
 * 
 * @param bool     $allowed   Whether the user can add the object meta.
 * @param string   $meta_key  The meta key.
 * @param int      $object_id Object ID.
 * @param int      $user_id   User ID.
 * @param string   $cap       Capability name.
 * @param string[] $caps      Array of the user's capabilities.
 *
 * @return bool
 */
function wp_kama_auth_object_type_meta_key_filter( $allowed, $meta_key, $object_id, $user_id, $cap, $caps ){

	// filter...
	return $allowed;
}
$allowed(true|false)
Whether the user can add the object meta.
Default: false
$meta_key(string)
The meta key.
$object_id(int)
Object ID.
$user_id(int)
User ID.
$cap(string)
Capability name.
$caps(string[])
Array of the user's capabilities.

Changelog

Since 4.6.0 Introduced.
Since 3.3.0 As auth_post_meta_{$meta_key}.

Where the hook is called

map_meta_cap()
auth_(object_type)_meta_(meta_key)
wp-includes/capabilities.php 509
$allowed = apply_filters( "auth_{$object_type}_meta_{$meta_key}", $allowed, $meta_key, $object_id, $user_id, $cap, $caps );

Where the hook is used in WordPress

wp-includes/meta.php 1499
add_filter( "auth_{$object_type}_meta_{$meta_key}_for_{$object_subtype}", $args['auth_callback'], 10, 6 );
wp-includes/meta.php 1501
add_filter( "auth_{$object_type}_meta_{$meta_key}", $args['auth_callback'], 10, 6 );
wp-includes/meta.php 1644
remove_filter( "auth_{$object_type}_meta_{$meta_key}_for_{$object_subtype}", $args['auth_callback'] );
wp-includes/meta.php 1646
remove_filter( "auth_{$object_type}_meta_{$meta_key}", $args['auth_callback'] );