is_protected_metafilter-hookWP 3.2.0

Allows you to add the names (keys) of meta-fields that should be considered protected/hidden.

By default, meta-fields whose keys begin with an underscore _ are considered protected.

Usage

add_filter( 'is_protected_meta', 'wp_kama_is_protected_meta_filter', 10, 3 );

/**
 * Function for `is_protected_meta` filter-hook.
 * 
 * @param bool   $protected Whether the key is considered protected.
 * @param string $meta_key  Metadata key.
 * @param string $meta_type Type of object metadata is for. Accepts 'blog', 'post', 'comment',
 *                          'term', 'user', or any other object type with an associated meta table.
 *
 * @return bool
 */
function wp_kama_is_protected_meta_filter( $protected, $meta_key, $meta_type ){
	// filter...
	return $protected;
}
$protected(true/false)
Whether the current key (the $meta_key parameter) is considered protected.
$meta_key(string)
The meta key currently being processed.
$meta_type(string/null)
The type of object whose meta-field is being processed. It can be comment, post, term, or user.

Examples

#1 Make the required meta-fields protected

Hide meta-fields from the meta-fields drop-down list when editing a post:

// Hide meta-fields for posts while they are being edited
add_filter( 'is_protected_meta', 'my_protected_custom_fields', 10, 2 );

function my_protected_custom_fields( $protected, $meta_key ){

	// Comma-separated list of fields to hide
	$hide_meta_keys = array( 'post_desc', 'publisher_id' );

	if( in_array( $meta_key, $hide_meta_keys ) ){
		return true;
	}

	return $protected;
}

Changelog

Since 3.2.0 Introduced.

Where the hook is called

is_protected_meta()
is_protected_meta
wp-includes/meta.php 1326
return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type );

Where the hook is used in WordPress

Usage not found.