WordPress at a glance

is_protected_meta() WP 3.1.3

Determines whether a meta key is protected (internal).

WordPress uses the following mechanism: if the name of the meta key starts with an underscore _, for example, _edit_time, then it's considered as protected - it means this meta key is used for internal purposes, so the protected meta keys are not displayed in the Custom Fields panel when editing a post.

✈ 1 time = 0.00001s = speed of light | 50000 times = 0.03s = speed of light | PHP 7.0.8, WP 4.6
Hooks in function
Return

true/false. Whether the meta key is considered protected.

Usage

is_protected_meta( $meta_key, $meta_type );
$meta_key(string) (required)
Meta key.
$meta_type(string/null)
Type of object metadata is for (e.g., comment, post, term, or user).
Default: null

Examples

#1 Check whether it is a protected meta key

$meta_key = '_my_metakey';
if( is_protected_meta( $meta_key, 'post' ) ){
	echo 'Protected meta key';
}

Code of is protected meta: wp-includes/meta.php WP 5.2.2

<?php
function is_protected_meta( $meta_key, $meta_type = null ) {
	$protected = ( '_' == $meta_key[0] );

	/**
	 * Filters whether a meta key is considered protected.
	 *
	 * @since 3.2.0
	 *
	 * @param bool        $protected Whether the key is considered protected.
	 * @param string      $meta_key  Meta key.
	 * @param string|null $meta_type Type of object metadata is for (e.g., comment, post, term, or user).
	 */
	return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type );
}

Related Functions

From tag: Metadatas (any)

No comments
    Hello, !     Log In . Register