add_<meta_type>_metadata

Filters whether to add metadata of a specific type.

Description

apply_filters( 'add_<meta_type>_metadata', (null) $null, (int) $object_id, (string) $meta_key, (mixed) $meta_value, (bool) $unique ); 

The dynamic portion(s) of the hook refer to the meta object type (comment, post, or user). Returning a non-null value will effectively short-circuit the function.

Parameters (5)

0. $null (null) => null
Whether to allow adding metadata for the given type.
1. $object_id (int)
The object id.
2. $meta_key (string)
The meta key.
3. $meta_value (mixed)
Meta value. Must be serializable if non-scalar.
4. $unique — Optional. (bool)
Whether the specified meta key should be unique for the object. Optional. Default false.

Usage

To run the hook, copy the example below.
  1. $null = apply_filters( 'add_{$meta_type}_metadata', $null, $object_id, $meta_key, $meta_value, $unique ); 
  2.  
  3. if ( !empty( $null ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the add_<meta_type>_metadata callback 
  2. function filter_add_meta_type_metadata( $null, $object_id, $meta_key, $meta_value, $unique ) { 
  3. // make filter magic happen here... 
  4. return $null
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( "add_{$meta_type}_metadata", 'filter_add_meta_type_metadata', 10, 5 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( "add_{$meta_type}_metadata", 'filter_add_meta_type_metadata', 10, 5 ); 

Defined (1)

The filter is defined in the following location(s).

/wp-includes/meta.php  
  1. $check = apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique );