| 1 | Index: wp-includes/class-wp-xmlrpc-server.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-includes/class-wp-xmlrpc-server.php (revision 20013) |
|---|
| 4 | +++ wp-includes/class-wp-xmlrpc-server.php (working copy) |
|---|
| 5 | @@ -69,6 +69,8 @@ |
|---|
| 6 | 'wp.getMediaItem' => 'this:wp_getMediaItem', |
|---|
| 7 | 'wp.getMediaLibrary' => 'this:wp_getMediaLibrary', |
|---|
| 8 | 'wp.getPostFormats' => 'this:wp_getPostFormats', |
|---|
| 9 | + 'wp.getPostType' => 'this:wp_getPostType', |
|---|
| 10 | + 'wp.getPostTypes' => 'this:wp_getPostTypes', |
|---|
| 11 | |
|---|
| 12 | // Blogger API |
|---|
| 13 | 'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs', |
|---|
| 14 | @@ -2363,6 +2365,150 @@ |
|---|
| 15 | return $formats; |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | + /** |
|---|
| 19 | + * Prepares post type data for return in an XML-RPC object |
|---|
| 20 | + * |
|---|
| 21 | + * @param array|object $post_type The unprepared post type data |
|---|
| 22 | + * @return array The prepared post type data |
|---|
| 23 | + */ |
|---|
| 24 | + function prepare_post_type( $post_type, $fields ) { |
|---|
| 25 | + $post_type = (array) $post_type; |
|---|
| 26 | + $_post_type = array( |
|---|
| 27 | + 'name' => $post_type['name'], |
|---|
| 28 | + 'label' => $post_type['label'], |
|---|
| 29 | + 'description' => $post_type['description'], |
|---|
| 30 | + 'hierarchical' => $post_type['hierarchical'], |
|---|
| 31 | + 'public' => $post_type['public'] |
|---|
| 32 | + ); |
|---|
| 33 | + |
|---|
| 34 | + if ( in_array( 'labels', $fields ) ) { |
|---|
| 35 | + $_post_type['labels'] = $post_type['labels']; |
|---|
| 36 | + } |
|---|
| 37 | + |
|---|
| 38 | + if ( in_array( 'capabilities', $fields ) ) { |
|---|
| 39 | + $_post_type['cap'] = $post_type['cap']; |
|---|
| 40 | + $_post_type['capability_type'] = $post_type['capability_type']; |
|---|
| 41 | + $_post_type['map_meta_cap'] = $post_type['map_meta_cap']; |
|---|
| 42 | + } |
|---|
| 43 | + |
|---|
| 44 | + if ( in_array( 'admin', $fields ) ) { |
|---|
| 45 | + $_post_type['publicly_queryable'] = $post_type['publicly_queryable']; |
|---|
| 46 | + $_post_type['exclude_from_search'] = $post_type['exclude_from_search']; |
|---|
| 47 | + $_post_type['_builtin'] = $post_type['_builtin']; |
|---|
| 48 | + $_post_type['_edit_link'] = $post_type['_edit_link']; |
|---|
| 49 | + $_post_type['_builtin'] = $post_type['_builtin']; |
|---|
| 50 | + $_post_type['rewrite'] = $post_type['rewrite']; |
|---|
| 51 | + $_post_type['has_archive'] = $post_type['has_archive']; |
|---|
| 52 | + $_post_type['query_var'] = $post_type['query_var']; |
|---|
| 53 | + } |
|---|
| 54 | + |
|---|
| 55 | + if ( in_array( 'menu', $fields ) ) { |
|---|
| 56 | + $_post_type['show_ui'] = $post_type['show_ui']; |
|---|
| 57 | + $_post_type['menu_position'] = $post_type['menu_position']; |
|---|
| 58 | + $_post_type['menu_icon'] = $post_type['menu_icon']; |
|---|
| 59 | + $_post_type['show_in_nav_menus'] = $post_type['show_in_nav_menus']; |
|---|
| 60 | + $_post_type['show_in_menu'] = $post_type['show_in_menu']; |
|---|
| 61 | + $_post_type['show_in_admin_bar'] = $post_type['show_in_admin_bar']; |
|---|
| 62 | + } |
|---|
| 63 | + |
|---|
| 64 | + if ( in_array( 'taxonomies', $fields ) ) { |
|---|
| 65 | + $_post_type['taxonomies'] = get_object_taxonomies( $_post_type['name'] ); |
|---|
| 66 | + } |
|---|
| 67 | + |
|---|
| 68 | + return apply_filters( 'xmlrpc_prepare_post_type', $_post_type, $post_type ); |
|---|
| 69 | + } |
|---|
| 70 | + |
|---|
| 71 | + /** |
|---|
| 72 | + * Retrieves a post type |
|---|
| 73 | + * |
|---|
| 74 | + * @uses get_post_type_object() |
|---|
| 75 | + * @param array $args Method parameters. Contains: |
|---|
| 76 | + * - int $blog_id |
|---|
| 77 | + * - string $username |
|---|
| 78 | + * - string $password |
|---|
| 79 | + * - string $post_type_name |
|---|
| 80 | + * @return array contains: |
|---|
| 81 | + * - 'labels' |
|---|
| 82 | + * - 'description' |
|---|
| 83 | + * - 'capability_type' |
|---|
| 84 | + * - 'cap' |
|---|
| 85 | + * - 'map_meta_cap' |
|---|
| 86 | + * - 'hierarchical' |
|---|
| 87 | + * - 'menu_position' |
|---|
| 88 | + * - 'taxonomies' |
|---|
| 89 | + */ |
|---|
| 90 | + function wp_getPostType( $args ) { |
|---|
| 91 | + $this->escape( $args ); |
|---|
| 92 | + |
|---|
| 93 | + $blog_id = (int) $args[0]; |
|---|
| 94 | + $username = $args[1]; |
|---|
| 95 | + $password = $args[2]; |
|---|
| 96 | + $post_type_name = $args[3]; |
|---|
| 97 | + |
|---|
| 98 | + if ( isset( $args[4] ) ) |
|---|
| 99 | + $fields = $args[4]; |
|---|
| 100 | + else |
|---|
| 101 | + $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'capabilities', 'taxonomies' ), 'wp.getPostType' ); |
|---|
| 102 | + |
|---|
| 103 | + if ( !$user = $this->login( $username, $password ) ) |
|---|
| 104 | + return $this->error; |
|---|
| 105 | + |
|---|
| 106 | + do_action( 'xmlrpc_call', 'wp.getPostType' ); |
|---|
| 107 | + |
|---|
| 108 | + if( ! post_type_exists( $post_type_name ) ) |
|---|
| 109 | + return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
|---|
| 110 | + |
|---|
| 111 | + $post_type = get_post_type_object( $post_type_name ); |
|---|
| 112 | + |
|---|
| 113 | + if( ! current_user_can( $post_type->cap->edit_posts ) ) |
|---|
| 114 | + return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post type.' ) ); |
|---|
| 115 | + |
|---|
| 116 | + return $this->prepare_post_type( $post_type, $fields ); |
|---|
| 117 | + } |
|---|
| 118 | + |
|---|
| 119 | + /** |
|---|
| 120 | + * Retrieves a post types |
|---|
| 121 | + * |
|---|
| 122 | + * @uses get_post_types() |
|---|
| 123 | + * @param array $args Method parameters. Contains: |
|---|
| 124 | + * - int $blog_id |
|---|
| 125 | + * - string $username |
|---|
| 126 | + * - string $password |
|---|
| 127 | + * - array $filter |
|---|
| 128 | + * @return array |
|---|
| 129 | + */ |
|---|
| 130 | + function wp_getPostTypes( $args ) { |
|---|
| 131 | + $this->escape( $args ); |
|---|
| 132 | + |
|---|
| 133 | + $blog_id = (int) $args[0]; |
|---|
| 134 | + $username = $args[1]; |
|---|
| 135 | + $password = $args[2]; |
|---|
| 136 | + $filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
|---|
| 137 | + |
|---|
| 138 | + if ( isset( $args[4] ) ) |
|---|
| 139 | + $fields = $args[4]; |
|---|
| 140 | + else |
|---|
| 141 | + $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'capabilities', 'taxonomies' ), 'wp.getPostTypes' ); |
|---|
| 142 | + |
|---|
| 143 | + if ( ! $user = $this->login( $username, $password ) ) |
|---|
| 144 | + return $this->error; |
|---|
| 145 | + |
|---|
| 146 | + do_action( 'xmlrpc_call', 'wp.getPostTypes' ); |
|---|
| 147 | + |
|---|
| 148 | + $post_types = get_post_types( $filter, 'objects' ); |
|---|
| 149 | + |
|---|
| 150 | + $struct = array(); |
|---|
| 151 | + |
|---|
| 152 | + foreach( $post_types as $post_type ) { |
|---|
| 153 | + if( ! current_user_can( $post_type->cap->edit_posts ) ) |
|---|
| 154 | + continue; |
|---|
| 155 | + |
|---|
| 156 | + $struct[$post_type->name] = $this->prepare_post_type( $post_type, $fields ); |
|---|
| 157 | + } |
|---|
| 158 | + |
|---|
| 159 | + return $struct; |
|---|
| 160 | + } |
|---|
| 161 | + |
|---|
| 162 | /* Blogger API functions. |
|---|
| 163 | * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/ |
|---|
| 164 | */ |
|---|