Ticket #35991: 35991.patch
File 35991.patch, 3.8 KB (added by , 9 years ago) |
---|
-
src/wp-includes/class-wp-xmlrpc-server.php
386 386 } 387 387 388 388 /** 389 * Retrieve custom fields for term. 390 * 391 * @since 4.5.x 392 * 393 * @param int $post_id Post ID. 394 * @return array Custom fields, if exist. 395 */ 396 public function get_term_custom_fields($term_id) { 397 $term_id = (int) $term_id; 398 399 $custom_fields = array(); 400 401 foreach ( (array) has_term_meta($term_id) as $meta ) { 402 if ( ! current_user_can( 'edit_term_meta', $term_id , $meta['meta_key'] ) ) 403 continue; 404 $custom_fields[] = array( 405 "id" => $meta['meta_id'], 406 "key" => $meta['meta_key'], 407 "value" => $meta['meta_value'] 408 ); 409 } 410 411 return $custom_fields; 412 } 413 414 /** 415 * Set custom fields for term. 416 * 417 * @since 4.5.x 418 * 419 * @param int $post_id Post ID. 420 * @param array $fields Custom fields. 421 */ 422 public function set_term_custom_fields($term_id, $fields) { 423 $term_id = (int) $term_id; 424 425 foreach ( (array) $fields as $meta ) { 426 if ( isset($meta['id']) ) { 427 $meta['id'] = (int) $meta['id']; 428 $pmeta = get_metadata_by_mid( 'term', $meta['id'] ); 429 if ( isset($meta['key']) ) { 430 $meta['key'] = wp_unslash( $meta['key'] ); 431 if ( $meta['key'] !== $pmeta->meta_key ) 432 continue; 433 $meta['value'] = wp_unslash( $meta['value'] ); 434 if ( current_user_can( 'edit_term_meta', $term_id, $meta['key'] ) ) 435 update_metadata_by_mid( 'term', $meta['id'], $meta['value'] ); 436 } elseif ( current_user_can( 'delete_term_meta', $term_id, $pmeta->meta_key ) ) { 437 delete_metadata_by_mid( 'term', $meta['id'] ); 438 } 439 } elseif ( current_user_can( 'add_term_meta', $term_id, wp_unslash( $meta['key'] ) ) ) { 440 add_term_meta( $term_id, $meta['key'], $meta['value'] ); 441 } 442 } 443 } 444 445 /** 389 446 * Set up blog options property. 390 447 * 391 448 * Passes property through {@see 'xmlrpc_blog_options'} filter. … … 724 781 // Count we are happy to return as an integer because people really shouldn't use terms that much. 725 782 $_term['count'] = intval( $_term['count'] ); 726 783 784 // Get term meta 785 $_term['custom_fields'] = $this->get_term_custom_fields($_term['term_id']); 786 727 787 /** 728 788 * Filter XML-RPC-prepared data for the given term. 729 789 * … … 1897 1957 if ( ! $term ) 1898 1958 return new IXR_Error( 500, __( 'Sorry, your term could not be created. Something wrong happened.' ) ); 1899 1959 1960 if ( isset( $content_struct['custom_fields'] ) ) { 1961 $this->set_term_custom_fields( $term['term_id'], $content_struct['custom_fields'] ); 1962 } 1963 1900 1964 return strval( $term['term_id'] ); 1901 1965 } 1902 1966 … … 1995 2059 if ( ! $term ) 1996 2060 return new IXR_Error( 500, __( 'Sorry, editing the term failed.' ) ); 1997 2061 2062 // Update term meta 2063 if ( isset( $content_struct['custom_fields'] ) ) { 2064 $this->set_term_custom_fields( $term_id, $content_struct['custom_fields'] ); 2065 } 2066 1998 2067 return true; 1999 2068 } 2000 2069 -
src/wp-includes/taxonomy.php
1877 1877 } 1878 1878 1879 1879 /** 1880 * Get meta data for the given term ID. 1881 * 1882 * @since 4.4.x 1883 * 1884 * @global wpdb $wpdb WordPress database abstraction object. 1885 * 1886 * @param int $term_id 1887 * @return array|false 1888 */ 1889 function has_term_meta( $term_id ) { 1890 // Bail if term meta table is not installed. 1891 if ( get_option( 'db_version' ) < 34370 ) { 1892 return; 1893 } 1894 1895 global $wpdb; 1896 1897 return $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value, meta_id, term_id 1898 FROM $wpdb->termmeta WHERE term_id = %d 1899 ORDER BY meta_key,meta_id", $term_id), ARRAY_A ); 1900 } 1901 1902 /** 1880 1903 * Check if Term exists. 1881 1904 * 1882 1905 * Formerly is_term(), introduced in 2.3.0.