WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/30/2016 01:01:35 AM (5 years ago)
Author:
helen
Message:

Introduce an expanded meta registration API.

register_meta() has been altered to accept an array of arguments as the third parameter in order to support its usage beyond XML-RPC, notably in the REST API and other projects that may build on top of meta, such as a potential Fields API. Arguments are whitelisted to reserve the right for core to add more later.

New functions added to complement this expansion are:

  • registered_meta_key_exists()
  • unregister_meta_key()
  • get_registered_meta_keys()
  • get_registered_metadata()
  • A "private" function for the aforementioned whitelisting.

There still need to be lots of tests written for previous and new behaviors, and many things are subject to change. Maybe things will explode. #yolo

props jeremyfelt, ericlewis, sc0ttkclark, helen, rmccue, ocean90, voldemortensen.
see #35658.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/capabilities.php

    r37518 r37924  
    244244        }
    245245
     246        $post_type = get_post_type( $post );
     247
    246248        $caps = map_meta_cap( 'edit_post', $user_id, $post->ID );
    247249
    248250        $meta_key = isset( $args[ 1 ] ) ? $args[ 1 ] : false;
    249251
    250         if ( $meta_key && has_filter( "auth_post_meta_{$meta_key}" ) ) {
     252        if ( $meta_key && ( has_filter( "auth_post_meta_{$meta_key}" ) || has_filter( "auth_post_{$post_type}_meta_{$meta_key}" ) ) ) {
    251253            /**
    252254             * Filters whether the user is allowed to add post meta to a post.
     
    265267             */
    266268            $allowed = apply_filters( "auth_post_meta_{$meta_key}", false, $meta_key, $post->ID, $user_id, $cap, $caps );
     269
     270            /**
     271             * Filters whether the user is allowed to add post meta to a post of a given type.
     272             *
     273             * The dynamic portions of the hook name, `$meta_key` and `$post_type`,
     274             * refer to the meta key passed to map_meta_cap() and the post type, respectively.
     275             *
     276             * @since 4.6.0
     277             *
     278             * @param bool   $allowed  Whether the user can add the post meta. Default false.
     279             * @param string $meta_key The meta key.
     280             * @param int    $post_id  Post ID.
     281             * @param int    $user_id  User ID.
     282             * @param string $cap      Capability name.
     283             * @param array  $caps     User capabilities.
     284             */
     285            $allowed = apply_filters( "auth_post_{$post_type}_meta_{$meta_key}", $allowed, $meta_key, $post->ID, $user_id, $cap, $caps );
     286
    267287            if ( ! $allowed )
    268288                $caps[] = $cap;
Note: See TracChangeset for help on using the changeset viewer.