[wp-trac] [WordPress Trac] #64036: Filters the value of metadata after it is retrieved.

WordPress Trac noreply at wordpress.org
Wed Sep 24 08:24:08 UTC 2025


#64036: Filters the value of metadata after it is retrieved.
--------------------------------+-----------------------------
 Reporter:  eslamelsherif       |      Owner:  eslamelsherif
     Type:  feature request     |     Status:  assigned
 Priority:  normal              |  Milestone:  Awaiting Review
Component:  Options, Meta APIs  |    Version:  trunk
 Severity:  normal              |   Keywords:
  Focuses:  php-compatibility   |
--------------------------------+-----------------------------
 ## Change

 Extended the get_metadata() function to apply two levels of filters after
 retrieving metadata:

 `{$meta_type}_metadata `→ runs for all meta keys of a given object type
 (e.g. user_metadata).

 `{$meta_type}_metadata_{$meta_key} `→ runs for a specific meta key (e.g.
 user_metadata_nickname).

 ## Why

 Aligns metadata handling with how get_option() works, which has both a
 general filter (option_{$option}) and the ability to target specific
 values.

 Provides developers more granular control:

 Use the general filter to adjust all metadata of a type.

 Use the meta-key-specific filter to target one field only.

 ## Example usage
 {{{#!php
 <?php
 // Affect all user metadata
 add_filter( 'user_metadata', function( $value, $user_id, $meta_key,
 $single ) {
     return $value === '' ? 'N/A' : $value;
 }, 10, 4 );

 // Affect only the nickname field
 add_filter( 'user_metadata_nickname', function( $value, $user_id, $single
 ) {
     return 'SuperHero';

 }, 10, 3 );

 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64036>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list