Make WordPress Core


Ignore:
Timestamp:
10/26/2010 07:11:27 PM (14 years ago)
Author:
scribu
Message:

Add filters to *_metadata() functions. Props sc0ttkclark. Fixes #14766

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/meta.php

    r15917 r15983  
    4646    $meta_key = stripslashes($meta_key);
    4747
     48    $check = apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique );
     49    if ( null !== $check )
     50        return (bool) $check;
     51
    4852    if ( $unique && $wpdb->get_var( $wpdb->prepare(
    4953        "SELECT COUNT(*) FROM $table WHERE meta_key = %s AND $column = %d",
     
    108112    // expected_slashed ($meta_key)
    109113    $meta_key = stripslashes($meta_key);
     114
     115    $check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value );
     116    if ( null !== $check )
     117        return (bool) $check;
    110118
    111119    if ( ! $meta_id = $wpdb->get_var( $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) ) )
     
    181189    $meta_value = maybe_serialize( stripslashes_deep($meta_value) );
    182190
     191    $check = apply_filters( "delete_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $delete_all );
     192    if ( null !== $check )
     193        return (bool) $check;
     194
    183195    $query = $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s", $meta_key );
    184196
     
    232244        return false;
    233245
     246    $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single );
     247    if ( null !== $check ) {
     248        if ( !is_array( $check ) )
     249            return $check;
     250        elseif ( $single )
     251            return maybe_unserialize( $check[0] );
     252        else
     253            return array_map( 'maybe_unserialize', $check );
     254    }
     255
    234256    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    235257
     
    239261    }
    240262
    241     if ( ! $meta_key )
     263    if ( !$meta_key )
    242264        return $meta_cache;
    243265
Note: See TracChangeset for help on using the changeset viewer.