Changeset 20632
- Timestamp:
- 04/28/2012 06:48:10 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-wp-xmlrpc-server.php
r20608 r20632 496 496 * @access protected 497 497 * 498 * @param array|object $taxonomy The unprepared taxonomy data498 * @param object $taxonomy The unprepared taxonomy data 499 499 * @return array The prepared taxonomy data 500 500 */ 501 protected function _prepare_taxonomy( $taxonomy ) { 502 $_taxonomy = (array) $taxonomy; 503 504 unset( $_taxonomy['update_count_callback'] ); 505 506 return apply_filters( 'xmlrpc_prepare_taxonomy', $_taxonomy, $taxonomy ); 501 protected function _prepare_taxonomy( $taxonomy, $fields ) { 502 $_taxonomy = array( 503 'name' => $taxonmy->name, 504 'label' => $taxonomy->label, 505 'hierarchical' => (bool) $taxonomy->hierarchical, 506 'public' => (bool) $taxonomy->public, 507 'show_ui' => (bool) $taxonomy->show_ui, 508 '_builtin' => (bool) $taxnomy->_builtin, 509 ); 510 511 if ( in_array( 'labels', $fields ) ) 512 $_taxonomy['labels'] = (array) $taxonomy->labels; 513 514 if ( in_array( 'capabilities', $fields ) ) 515 $_taxonomy['cap'] = (array) $post_type->cap; 516 517 if ( in_array( 'object_types', $fields ) ) 518 $_taxonomy['taxonomies'] = array_unique( (array) $taxonomy->object_type ); 519 520 return apply_filters( 'xmlrpc_prepare_taxonomy', $_taxonomy, $taxonomy, $fields ); 507 521 } 508 522 … … 653 667 * @access protected 654 668 * 655 * @param array|object $post_type The unprepared post type data669 * @param object $post_type Post type object 656 670 * @param array $fields The subset of post fields to return 657 671 * @return array The prepared post type data 658 672 */ 659 protected function _prepare_post_type( $post_type, $fields ) { 660 $post_type = (array) $post_type; 661 673 public function _prepare_post_type( $post_type, $fields ) { 662 674 $_post_type = array( 663 'name' => $post_type['name'], 664 'label' => $post_type['label'], 665 'description' => $post_type['description'], 666 'hierarchical' => $post_type['hierarchical'], 667 'public' => $post_type['public'], 668 '_builtin' => $post_type['_builtin'], 669 'supports' => get_all_post_type_supports( $post_type['name'] ) 675 'name' => $post_type->name, 676 'label' => $post_type->label, 677 'hierarchical' => (bool) $post_type->hierarchical, 678 'public' => (bool) $post_type->public, 679 'show_ui' => (bool) $post_type->show_ui, 680 '_builtin' => (bool) $post_type->_builtin, 681 'has_archive' => (bool) $post_type->has_archive, 682 'supports' => get_all_post_type_supports( $post_type->name ), 670 683 ); 671 684 672 685 if ( in_array( 'labels', $fields ) ) { 673 $_post_type['labels'] = (array) $post_type ['labels'];686 $_post_type['labels'] = (array) $post_type->labels; 674 687 } 675 688 676 689 if ( in_array( 'capabilities', $fields ) ) { 677 $_post_type['cap'] = (array) $post_type['cap']; 678 $_post_type['capability_type'] = $post_type['capability_type']; 679 $_post_type['map_meta_cap'] = $post_type['map_meta_cap']; 680 } 681 682 if ( in_array( 'admin', $fields ) ) { 683 $_post_type['publicly_queryable'] = $post_type['publicly_queryable']; 684 $_post_type['exclude_from_search'] = $post_type['exclude_from_search']; 685 $_post_type['_edit_link'] = $post_type['_edit_link']; 686 $_post_type['rewrite'] = $post_type['rewrite']; 687 $_post_type['has_archive'] = $post_type['has_archive']; 688 $_post_type['query_var'] = $post_type['query_var']; 690 $_post_type['cap'] = (array) $post_type->cap; 691 $_post_type['map_meta_cap'] = (bool) $post_type->map_meta_cap; 689 692 } 690 693 691 694 if ( in_array( 'menu', $fields ) ) { 692 $_post_type['show_ui'] = $post_type['show_ui']; 693 $_post_type['menu_position'] = $post_type['menu_position']; 694 $_post_type['menu_icon'] = $post_type['menu_icon']; 695 $_post_type['show_in_nav_menus'] = $post_type['show_in_nav_menus']; 696 $_post_type['show_in_menu'] = $post_type['show_in_menu']; 697 $_post_type['show_in_admin_bar'] = $post_type['show_in_admin_bar']; 698 } 699 700 if ( in_array( 'taxonomies', $fields ) ) { 701 $_post_type['taxonomies'] = get_object_taxonomies( $_post_type['name'] ); 702 } 695 $_post_type['menu_position'] = (int) $post_type->menu_position; 696 $_post_type['menu_icon'] = $post_type->menu_icon; 697 $_post_type['show_in_menu'] = (bool) $post_type->show_in_menu; 698 } 699 700 if ( in_array( 'taxonomies', $fields ) ) 701 $_post_type['taxonomies'] = get_object_taxonomies( $_post_type->name, 'names' ); 703 702 704 703 return apply_filters( 'xmlrpc_prepare_post_type', $_post_type, $post_type ); … … 737 736 /** 738 737 * Create a new post for any registered post type. 738 * 739 * @since 3.4.0 739 740 * 740 741 * @uses wp_insert_post() … … 785 786 /* 786 787 * Helper method for filtering out elements from an array. 787 */ 788 function _is_greater_than_one( $count ){ 788 * 789 * @since 3.4.0 790 */ 791 function _is_greater_than_one( $count ) { 789 792 return $count > 1; 790 793 } … … 792 795 /* 793 796 * Helper method for wp_newPost and wp_editPost, containing shared logic. 794 */ 795 function _insert_post( $user, $content_struct ) { 797 * 798 * @since 3.4.0 799 */ 800 protected function _insert_post( $user, $content_struct ) { 796 801 $defaults = array( 'post_status' => 'draft', 'post_type' => 'post', 'post_author' => 0, 797 'post_password' => '', 'post_excerpt' => '', 'post_content' => '', 'post_title' => '' , 'sticky' => 0);802 'post_password' => '', 'post_excerpt' => '', 'post_content' => '', 'post_title' => '' ); 798 803 799 804 $post_data = wp_parse_args( $content_struct, $defaults ); 800 805 801 806 $post_type = get_post_type_object( $post_data['post_type'] ); 802 if ( ! ( (bool) $post_type ))807 if ( ! $post_type ) 803 808 return new IXR_Error( 403, __( 'Invalid post type' ) ); 804 809 805 $update = false; 806 if ( ! empty( $post_data[ 'ID' ] ) ) 807 $update = true; 810 $update = ! empty( $post_data['ID'] ); 808 811 809 812 if ( $update ) { 810 if ( ! current_user_can( $post_type->cap->edit_post, $post_data[ 'ID'] ) )813 if ( ! current_user_can( $post_type->cap->edit_post, $post_data['ID'] ) ) 811 814 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); 815 if ( $post_data['post_type'] != get_post_type( $post_data['ID'] ) ) 816 return new IXR_Error( 401, __( 'The post type may not be changed.' ) ); 812 817 } else { 813 818 if ( ! current_user_can( $post_type->cap->edit_posts ) ) … … 821 826 case 'private': 822 827 if ( ! current_user_can( $post_type->cap->publish_posts ) ) 823 return new IXR_Error( 401, __( 'Sorry, you are not allowed to create private posts in this post type' ) );828 return new IXR_Error( 401, __( 'Sorry, you are not allowed to create private posts in this post type' ) ); 824 829 break; 825 830 case 'publish': 826 831 case 'future': 827 832 if ( ! current_user_can( $post_type->cap->publish_posts ) ) 828 return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts in this post type' ) );833 return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts in this post type' ) ); 829 834 break; 830 835 default: … … 849 854 } 850 855 851 if ( isset( $post_data['comment_status'] ) ) { 852 if ( ! post_type_supports( $post_data['post_type'], 'comments' ) || ( $post_data['comment_status'] != 'open' && $post_data['comment_status'] != 'closed' ) ) { 853 unset( $post_data['comment_status'] ); 854 } 855 } 856 857 if ( isset( $post_data['ping_status'] ) ) { 858 if ( ! post_type_supports( $post_data['post_type'], 'trackbacks' ) || ( $post_data['ping_status'] != 'open' && $post_data['ping_status'] != 'closed' ) ) { 859 unset( $post_data['ping_status'] ); 860 } 861 } 856 if ( isset( $post_data['comment_status'] ) && $post_data['comment_status'] != 'open' && $post_data['comment_status'] != 'closed' ) 857 unset( $post_data['comment_status'] ); 858 859 if ( isset( $post_data['ping_status'] ) && $post_data['ping_status'] != 'open' && $post_data['ping_status'] != 'closed' ) 860 unset( $post_data['ping_status'] ); 862 861 863 862 // Do some timestamp voodoo 864 863 if ( ! empty( $post_data['post_date_gmt'] ) ) { 865 864 // We know this is supposed to be GMT, so we're going to slap that Z on there by force 866 $dateCreated = str_replace( 'Z', '', $post_data['post_date_gmt']->getIso()) . 'Z';865 $dateCreated = rtrim( $post_data['post_date_gmt']->getIso(), 'Z' ) . 'Z'; 867 866 } elseif ( ! empty( $post_data['post_date'] ) ) { 868 867 $dateCreated = $post_data['post_date']->getIso(); … … 874 873 } 875 874 876 if ( ! isset( $post_data['ID'] ) ) {875 if ( ! isset( $post_data['ID'] ) ) 877 876 $post_data['ID'] = get_default_post_to_edit( $post_data['post_type'], true )->ID; 878 }879 877 $post_ID = $post_data['ID']; 880 878 881 $sticky = $post_data['sticky'] ? true : false; 882 883 if ( $post_data['post_type'] == 'post' && $sticky == true ) { 884 if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) 885 return new IXR_Error( 401, __( 'Sorry, you are not allowed to stick this post.' ) ); 886 887 if ( $post_data['post_status'] != 'publish' ) 888 return new IXR_Error( 401, __( 'Only published posts can be made sticky.' ) ); 889 890 stick_post( $post_ID ); 891 } 892 893 if ( isset ( $post_data['post_thumbnail'] ) ) { 879 if ( $post_data['post_type'] == 'post' ) { 880 // Private and password-protected posts cannot be stickied. 881 if ( $post_data['status'] == 'private' || ! empty( $post_data['post_password'] ) ) { 882 // Error if the client tried to stick the post, otherwise, silently unstick. 883 if ( ! empty( $post_data['sticky'] ) ) 884 return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) ); 885 if ( $update ) 886 unstick_post( $post_ID ); 887 } elseif ( isset( $post_data['sticky'] ) ) { 888 if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) 889 return new IXR_Error( 401, __( 'Sorry, you are not allowed to stick this post.' ) ); 890 if ( $post_data['sticky'] ) 891 stick_post( $post_ID ); 892 else 893 unstick_post( $post_ID ); 894 } 895 } 896 897 if ( isset( $post_data['post_thumbnail'] ) ) { 894 898 // empty value deletes, non-empty value adds/updates 895 if ( empty( $post_data['post_thumbnail'] ) ) {899 if ( ! $post_data['post_thumbnail'] ) 896 900 delete_post_thumbnail( $post_ID ); 897 } 898 else { 899 if ( set_post_thumbnail( $post_ID, $post_data['post_thumbnail'] ) === false ) 901 elseif ( ! set_post_thumbnail( $post_ID, $post_data['post_thumbnail'] ) ) 900 902 return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); 901 }902 903 unset( $content_struct['post_thumbnail'] ); 903 904 } 904 905 905 if ( isset ( $post_data['custom_fields'] ) && post_type_supports( $post_data['post_type'], 'custom-fields' ) ) {906 if ( isset( $post_data['custom_fields'] ) ) 906 907 $this->set_custom_fields( $post_ID, $post_data['custom_fields'] ); 907 }908 908 909 909 if ( isset( $post_data['terms'] ) || isset( $post_data['terms_names'] ) ) { … … 988 988 989 989 $post_data['tax_input'] = $terms; 990 unset( $post_data['terms'] ); 991 unset( $post_data['terms_names'] ); 990 unset( $post_data['terms'], $post_data['terms_names'] ); 992 991 } else { 993 992 // do not allow direct submission of 'tax_input', clients must use 'terms' and/or 'terms_names' 994 unset( $post_data['tax_input'] );993 unset( $post_data['tax_input'], $post_data['post_category'], $post_data['tags_input'] ); 995 994 } 996 995 … … 1024 1023 /** 1025 1024 * Edit a post for any registered post type. 1025 * 1026 * @since 3.4.0 1026 1027 * 1027 1028 * The $content_struct parameter only needs to contain fields that … … 1040 1041 $this->escape( $args ); 1041 1042 1042 $blog_id = (int) $args[0]; // we will support this in the near future1043 $blog_id = (int) $args[0]; 1043 1044 $username = $args[1]; 1044 1045 $password = $args[2]; … … 1051 1052 do_action( 'xmlrpc_call', 'wp.editPost' ); 1052 1053 1053 // User Capabilities are checked in _insert_post.1054 1055 1054 $post = get_post( $post_id, ARRAY_A ); 1056 1055 1057 if ( empty( $post[ "ID"] ) )1056 if ( empty( $post['ID'] ) ) 1058 1057 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); 1059 1058 … … 1080 1079 /** 1081 1080 * Delete a post for any registered post type. 1081 * 1082 * @since 3.4.0 1082 1083 * 1083 1084 * @uses wp_delete_post() … … 1120 1121 /** 1121 1122 * Retrieve a post. 1123 * 1124 * @since 3.4.0 1122 1125 * 1123 1126 * The optional $fields parameter specifies what fields will be included … … 1180 1183 $post = wp_get_single_post( $post_id, ARRAY_A ); 1181 1184 1182 if ( empty( $post[ "ID"] ) )1185 if ( empty( $post['ID'] ) ) 1183 1186 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); 1184 1187 … … 1192 1195 /** 1193 1196 * Retrieve posts. 1197 * 1198 * @since 3.4.0 1194 1199 * 1195 1200 * The optional $filter parameter modifies the query used to retrieve posts. … … 1210 1215 * - array $filter optional 1211 1216 * - array $fields optional 1212 * @return array c ntains a collection of posts.1217 * @return array contains a collection of posts. 1213 1218 */ 1214 1219 function wp_getPosts( $args ) { … … 1280 1285 /** 1281 1286 * Create a new term. 1287 * 1288 * @since 3.4.0 1282 1289 * 1283 1290 * @uses wp_insert_term() … … 1361 1368 /** 1362 1369 * Edit a term. 1370 * 1371 * @since 3.4.0 1363 1372 * 1364 1373 * @uses wp_update_term() … … 1456 1465 * Delete a term. 1457 1466 * 1467 * @since 3.4.0 1468 * 1458 1469 * @uses wp_delete_term() 1459 1470 * @param array $args Method parameters. Contains: … … 1508 1519 /** 1509 1520 * Retrieve a term. 1521 * 1522 * @since 3.4.0 1510 1523 * 1511 1524 * @uses get_term() … … 1563 1576 * Retrieve all terms for a taxonomy. 1564 1577 * 1578 * @since 3.4.0 1579 * 1565 1580 * The optional $filter parameter modifies the query used to retrieve terms. 1566 1581 * Accepted keys are 'number', 'offset', 'orderby', 'order', 'hide_empty', and 'search'. … … 1637 1652 * Retrieve a taxonomy. 1638 1653 * 1654 * @since 3.4.0 1655 * 1639 1656 * @uses get_taxonomy() 1640 1657 * @param array $args Method parameters. Contains: … … 1653 1670 $taxonomy = $args[3]; 1654 1671 1672 if ( isset( $args[4] ) ) 1673 $fields = $args[4]; 1674 else 1675 $fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'capabilities', 'object_types' ), 'wp.getTaxonomy' ); 1676 1655 1677 if ( ! $user = $this->login( $username, $password ) ) 1656 1678 return $this->error; … … 1666 1688 return new IXR_Error( 401, __( 'You are not allowed to assign terms in this taxonomy.' ) ); 1667 1689 1668 return $this->_prepare_taxonomy( $taxonomy );1690 return $this->_prepare_taxonomy( $taxonomy, $fields ); 1669 1691 } 1670 1692 1671 1693 /** 1672 1694 * Retrieve all taxonomies. 1695 * 1696 * @since 3.4.0 1673 1697 * 1674 1698 * @uses get_taxonomies() … … 1685 1709 $username = $args[1]; 1686 1710 $password = $args[2]; 1711 $filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); 1712 1713 if ( isset( $args[4] ) ) 1714 $fields = $args[4]; 1715 else 1716 $fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'capabilities', 'object_types' ), 'wp.getTaxonomies' ); 1687 1717 1688 1718 if ( ! $user = $this->login( $username, $password ) ) … … 1691 1721 do_action( 'xmlrpc_call', 'wp.getTaxonomies' ); 1692 1722 1693 $taxonomies = get_taxonomies( array(), 'objects' );1723 $taxonomies = get_taxonomies( $filter, 'objects' ); 1694 1724 1695 1725 // holds all the taxonomy data … … 1701 1731 continue; 1702 1732 1703 $struct[] = $this->_prepare_taxonomy( $taxonomy );1733 $struct[] = $this->_prepare_taxonomy( $taxonomy, $fields ); 1704 1734 } 1705 1735 … … 2064 2094 * Get list of all tags 2065 2095 * 2066 * @since 2.7 2096 * @since 2.7.0 2067 2097 * 2068 2098 * @param array $args Method parameters. … … 2470 2500 // Do some timestamp voodoo 2471 2501 if ( !empty( $content_struct['date_created_gmt'] ) ) { 2472 $dateCreated = str_replace( 'Z', '', $content_struct['date_created_gmt']->getIso() ) . 'Z'; // We know this is supposed to be GMT, so we're going to slap that Z on there by force 2502 // We know this is supposed to be GMT, so we're going to slap that Z on there by force 2503 $dateCreated = rtrim( $post_data['post_date_gmt']->getIso(), 'Z' ) . 'Z'; 2473 2504 $comment_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); 2474 2505 $comment_date_gmt = iso8601_to_datetime($dateCreated, 'GMT'); … … 2957 2988 /** 2958 2989 * Retrieves a post type 2990 * 2991 * @since 3.4.0 2959 2992 * 2960 2993 * @uses get_post_type_object() … … 2984 3017 $post_type_name = $args[3]; 2985 3018 2986 if ( isset( $args[4] ) ) 2987 $fields = $args[4]; 2988 else 2989 $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'capabilities', 'taxonomies' ), 'wp.getPostType' ); 3019 if ( isset( $args[4] ) ) 3020 $fields = $args[4]; 3021 else 3022 $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'capabilities', 'taxonomies' ), 'wp.getPostType' ); 2990 3023 2991 3024 if ( !$user = $this->login( $username, $password ) ) … … 3008 3041 * Retrieves a post types 3009 3042 * 3010 * @ access private3043 * @since 3.4.0 3011 3044 * 3012 3045 * @uses get_post_types() … … 3025 3058 $username = $args[1]; 3026 3059 $password = $args[2]; 3027 $filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); 3028 3029 if ( isset( $args[4] ) ) 3030 $fields = $args[4]; 3031 else 3032 $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'capabilities', 'taxonomies' ), 'wp.getPostTypes' ); 3060 $filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); 3061 3062 if ( isset( $args[4] ) ) 3063 $fields = $args[4]; 3064 else 3065 $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'capabilities', 'taxonomies' ), 'wp.getPostTypes' ); 3033 3066 3034 3067 if ( ! $user = $this->login( $username, $password ) ) … … 3530 3563 $this->escape($args); 3531 3564 3532 $blog_ID = (int) $args[0]; // we will support this in the near future3565 $blog_ID = (int) $args[0]; 3533 3566 $username = $args[1]; 3534 3567 $password = $args[2]; … … 3727 3760 // Do some timestamp voodoo 3728 3761 if ( !empty( $content_struct['date_created_gmt'] ) ) 3729 $dateCreated = str_replace( 'Z', '', $content_struct['date_created_gmt']->getIso() ) . 'Z'; // We know this is supposed to be GMT, so we're going to slap that Z on there by force 3762 // We know this is supposed to be GMT, so we're going to slap that Z on there by force 3763 $dateCreated = rtrim( $post_data['post_date_gmt']->getIso(), 'Z' ) . 'Z'; 3730 3764 elseif ( !empty( $content_struct['dateCreated']) ) 3731 3765 $dateCreated = $content_struct['dateCreated']->getIso(); … … 4045 4079 // Do some timestamp voodoo 4046 4080 if ( !empty( $content_struct['date_created_gmt'] ) ) 4047 $dateCreated = str_replace( 'Z', '', $content_struct['date_created_gmt']->getIso() ) . 'Z'; // We know this is supposed to be GMT, so we're going to slap that Z on there by force 4081 // We know this is supposed to be GMT, so we're going to slap that Z on there by force 4082 $dateCreated = rtrim( $post_data['post_date_gmt']->getIso(), 'Z' ) . 'Z'; 4048 4083 elseif ( !empty( $content_struct['dateCreated']) ) 4049 4084 $dateCreated = $content_struct['dateCreated']->getIso();
Note: See TracChangeset
for help on using the changeset viewer.