Make WordPress Core


Ignore:
Timestamp:
11/09/2016 03:41:07 AM (10 years ago)
Author:
rmccue
Message:

Roles/Capabilities: Add meta-caps for comment, term, and user meta.

Additionally, use these meta-caps in the REST API endpoints.

Previously, register_meta()'s auth_callback had no effect for non-post meta. This introduces {add,edit,delete}_{comment,term,user}_meta meta-caps to match the existing post meta capabilities. These are currently only used in the REST API.

Props tharsheblows, boonebgorges.
Fixes #38303, fixes #38412.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php

    r39058 r39179  
    123123        public function update_value( $request, $object_id ) {
    124124                $fields = $this->get_registered_fields();
    125 
    126125                foreach ( $fields as $name => $args ) {
    127126                        if ( ! array_key_exists( $name, $request ) ) {
    … …  
    160159         */
    161160        protected function delete_meta_value( $object_id, $name ) {
    162                 if ( ! current_user_can( 'delete_post_meta', $object_id, $name ) ) {
     161                $meta_type = $this->get_meta_type();
     162                if ( ! current_user_can( "delete_{$meta_type}_meta", $object_id, $name ) ) {
    163163                        return new WP_Error(
    164164                                'rest_cannot_delete',
    … …  
    168168                }
    169169
    170                 if ( ! delete_metadata( $this->get_meta_type(), $object_id, wp_slash( $name ) ) ) {
     170                if ( ! delete_metadata( $meta_type, $object_id, wp_slash( $name ) ) ) {
    171171                        return new WP_Error(
    172172                                'rest_meta_database_error',
    … …  
    193193         */
    194194        protected function update_multi_meta_value( $object_id, $name, $values ) {
    195                 if ( ! current_user_can( 'edit_post_meta', $object_id, $name ) ) {
     195                $meta_type = $this->get_meta_type();
     196                if ( ! current_user_can( "edit_{$meta_type}_meta", $object_id, $name ) ) {
    196197                        return new WP_Error(
    197198                                'rest_cannot_update',
    … …  
    201202                }
    202203
    203                 $current = get_metadata( $this->get_meta_type(), $object_id, $name, false );
     204                $current = get_metadata( $meta_type, $object_id, $name, false );
    204205
    205206                $to_remove = $current;
    … …  
    228229
    229230                foreach ( $to_remove as $value ) {
    230                         if ( ! delete_metadata( $this->get_meta_type(), $object_id, wp_slash( $name ), wp_slash( $value ) ) ) {
     231                        if ( ! delete_metadata( $meta_type, $object_id, wp_slash( $name ), wp_slash( $value ) ) ) {
    231232                                return new WP_Error(
    232233                                        'rest_meta_database_error',
    … …  
    238239
    239240                foreach ( $to_add as $value ) {
    240                         if ( ! add_metadata( $this->get_meta_type(), $object_id, wp_slash( $name ), wp_slash( $value ) ) ) {
     241                        if ( ! add_metadata( $meta_type, $object_id, wp_slash( $name ), wp_slash( $value ) ) ) {
    241242                                return new WP_Error(
    242243                                        'rest_meta_database_error',
    … …  
    262263         */
    263264        protected function update_meta_value( $object_id, $name, $value ) {
    264                 if ( ! current_user_can( 'edit_post_meta', $object_id, $name ) ) {
     265                $meta_type = $this->get_meta_type();
     266                if ( ! current_user_can(  "edit_{$meta_type}_meta", $object_id, $name ) ) {
    265267                        return new WP_Error(
    266268                                'rest_cannot_update',
    … …  
    270272                }
    271273
    272                 $meta_type  = $this->get_meta_type();
    273274                $meta_key   = wp_slash( $name );
    274275                $meta_value = wp_slash( $value );
Note: See TracChangeset for help on using the changeset viewer.