Ticket #38412: 38412.diff
| File 38412.diff, 3.5 KB (added by , 10 years ago) |
|---|
-
wp-includes/rest-api/fields/class-wp-rest-meta-fields.php
93 93 */ 94 94 public function update_value( $request, $object_id ) { 95 95 $fields = $this->get_registered_fields(); 96 97 96 foreach ( $fields as $name => $args ) { 98 97 if ( ! array_key_exists( $name, $request ) ) { 99 98 continue; … … 125 124 * @return bool|WP_Error True if meta field is deleted, error otherwise. 126 125 */ 127 126 protected function delete_meta_value( $object_id, $name ) { 128 if ( ! current_user_can( 'delete_post_meta', $object_id, $name ) ) { 127 $meta_type = $this->get_meta_type(); 128 if ( ! current_user_can( "delete_{$meta_type}_meta", $object_id, $name ) ) { 129 129 return new WP_Error( 130 130 'rest_cannot_delete', 131 131 sprintf( __( 'You do not have permission to edit the %s custom field.' ), $name ), … … 133 133 ); 134 134 } 135 135 136 if ( ! delete_metadata( $ this->get_meta_type(), $object_id, wp_slash( $name ) ) ) {136 if ( ! delete_metadata( $meta_type, $object_id, wp_slash( $name ) ) ) { 137 137 return new WP_Error( 138 138 'rest_meta_database_error', 139 139 __( 'Could not delete meta value from database.' ), … … 155 155 * @return bool|WP_Error True if meta fields are updated, error otherwise. 156 156 */ 157 157 protected function update_multi_meta_value( $object_id, $name, $values ) { 158 if ( ! current_user_can( 'edit_post_meta', $object_id, $name ) ) { 158 $meta_type = $this->get_meta_type(); 159 if ( ! current_user_can( "edit_{$meta_type}_meta", $object_id, $name ) ) { 159 160 return new WP_Error( 160 161 'rest_cannot_update', 161 162 sprintf( __( 'You do not have permission to edit the %s custom field.' ), $name ), … … 163 164 ); 164 165 } 165 166 166 $current = get_metadata( $ this->get_meta_type(), $object_id, $name, false );167 $current = get_metadata( $meta_type, $object_id, $name, false ); 167 168 168 169 $to_remove = $current; 169 170 $to_add = $values; … … 187 188 // once. 188 189 $to_remove = array_unique( $to_remove ); 189 190 foreach ( $to_remove as $value ) { 190 if ( ! delete_metadata( $ this->get_meta_type(), $object_id, wp_slash( $name ), wp_slash( $value ) ) ) {191 if ( ! delete_metadata( $meta_type, $object_id, wp_slash( $name ), wp_slash( $value ) ) ) { 191 192 return new WP_Error( 192 193 'rest_meta_database_error', 193 194 __( 'Could not update meta value in database.' ), … … 196 197 } 197 198 } 198 199 foreach ( $to_add as $value ) { 199 if ( ! add_metadata( $ this->get_meta_type(), $object_id, wp_slash( $name ), wp_slash( $value ) ) ) {200 if ( ! add_metadata( $meta_type, $object_id, wp_slash( $name ), wp_slash( $value ) ) ) { 200 201 return new WP_Error( 201 202 'rest_meta_database_error', 202 203 __( 'Could not update meta value in database.' ), … … 217 218 * @return bool|WP_Error True if meta field is updated, error otherwise. 218 219 */ 219 220 protected function update_meta_value( $object_id, $name, $value ) { 220 if ( ! current_user_can( 'edit_post_meta', $object_id, $name ) ) { 221 $meta_type = $this->get_meta_type(); 222 if ( ! current_user_can( "edit_{$meta_type}_meta", $object_id, $name ) ) { 221 223 return new WP_Error( 222 224 'rest_cannot_update', 223 225 sprintf( __( 'You do not have permission to edit the %s custom field.' ), $name ), … … 225 227 ); 226 228 } 227 229 228 $meta_type = $this->get_meta_type();229 230 $meta_key = wp_slash( $name ); 230 231 $meta_value = wp_slash( $value ); 231 232
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)