Changeset 40916 for trunk/src/wp-includes/class-wp-xmlrpc-server.php
- Timestamp:
- 06/18/2017 10:39:12 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-xmlrpc-server.php
r40692 r40916 400 400 } elseif ( current_user_can( 'add_post_meta', $post_id, wp_unslash( $meta['key'] ) ) ) { 401 401 add_post_meta( $post_id, $meta['key'], $meta['value'] ); 402 } 403 } 404 } 405 406 /** 407 * Retrieve custom fields for a term. 408 * 409 * @since 4.9.0 410 * 411 * @param int $post_id Post ID. 412 * @return array Array of custom fields, if they exist. 413 */ 414 public function get_term_custom_fields( $term_id ) { 415 $term_id = (int) $term_id; 416 417 $custom_fields = array(); 418 419 foreach ( (array) has_term_meta( $term_id ) as $meta ) { 420 421 if ( ! current_user_can( 'edit_term_meta', $term_id ) ) { 422 continue; 423 } 424 425 $custom_fields[] = array( 426 'id' => $meta['meta_id'], 427 'key' => $meta['meta_key'], 428 'value' => $meta['meta_value'], 429 ); 430 } 431 432 return $custom_fields; 433 } 434 435 /** 436 * Set custom fields for a term. 437 * 438 * @since 4.9.0 439 * 440 * @param int $post_id Post ID. 441 * @param array $fields Custom fields. 442 */ 443 public function set_term_custom_fields( $term_id, $fields ) { 444 $term_id = (int) $term_id; 445 446 foreach ( (array) $fields as $meta ) { 447 if ( isset( $meta['id'] ) ) { 448 $meta['id'] = (int) $meta['id']; 449 $pmeta = get_metadata_by_mid( 'term', $meta['id'] ); 450 if ( isset( $meta['key'] ) ) { 451 $meta['key'] = wp_unslash( $meta['key'] ); 452 if ( $meta['key'] !== $pmeta->meta_key ) { 453 continue; 454 } 455 $meta['value'] = wp_unslash( $meta['value'] ); 456 if ( current_user_can( 'edit_term_meta', $term_id ) ) { 457 update_metadata_by_mid( 'term', $meta['id'], $meta['value'] ); 458 } 459 } elseif ( current_user_can( 'delete_term_meta', $term_id ) ) { 460 delete_metadata_by_mid( 'term', $meta['id'] ); 461 } 462 } elseif ( current_user_can( 'add_term_meta', $term_id ) ) { 463 add_term_meta( $term_id, $meta['key'], $meta['value'] ); 402 464 } 403 465 } … … 743 805 $_term['count'] = intval( $_term['count'] ); 744 806 807 // Get term meta. 808 $_term['custom_fields'] = $this->get_term_custom_fields( $_term['term_id'] ); 809 745 810 /** 746 811 * Filters XML-RPC-prepared data for the given term. … … 1944 2009 return new IXR_Error( 500, __( 'Sorry, your term could not be created.' ) ); 1945 2010 2011 // Add term meta. 2012 if ( isset( $content_struct['custom_fields'] ) ) { 2013 $this->set_term_custom_fields( $term['term_id'], $content_struct['custom_fields'] ); 2014 } 2015 1946 2016 return strval( $term['term_id'] ); 1947 2017 } … … 2042 2112 if ( ! $term ) 2043 2113 return new IXR_Error( 500, __( 'Sorry, editing the term failed.' ) ); 2114 2115 // Update term meta. 2116 if ( isset( $content_struct['custom_fields'] ) ) { 2117 $this->set_term_custom_fields( $term_id, $content_struct['custom_fields'] ); 2118 } 2044 2119 2045 2120 return true;
Note: See TracChangeset
for help on using the changeset viewer.