<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[20271] trunk/wp-includes: XMLRPC: Add new wp.getPostType and wp.getPostTypes apis.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/20271">20271</a></dd>
<dt>Author</dt> <dd>westi</dd>
<dt>Date</dt> <dd>2012-03-23 17:53:14 +0000 (Fri, 23 Mar 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>XMLRPC: Add new wp.getPostType and wp.getPostTypes apis. See <a href="http://core.trac.wordpress.org/ticket/18436">#18436</a> props maxcutler, markoheijnen and nprasath002.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesclasswpxmlrpcserverphp">trunk/wp-includes/class-wp-xmlrpc-server.php</a></li>
<li><a href="#trunkwpincludespostphp">trunk/wp-includes/post.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesclasswpxmlrpcserverphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-wp-xmlrpc-server.php (20270 => 20271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-wp-xmlrpc-server.php        2012-03-23 15:35:44 UTC (rev 20270)
+++ trunk/wp-includes/class-wp-xmlrpc-server.php        2012-03-23 17:53:14 UTC (rev 20271)
</span><span class="lines">@@ -76,6 +76,8 @@
</span><span class="cx">                         'wp.getMediaItem'                =&gt; 'this:wp_getMediaItem',
</span><span class="cx">                         'wp.getMediaLibrary'        =&gt; 'this:wp_getMediaLibrary',
</span><span class="cx">                         'wp.getPostFormats'     =&gt; 'this:wp_getPostFormats',
</span><ins>+                        'wp.getPostType'                =&gt; 'this:wp_getPostType',
+                        'wp.getPostTypes'                =&gt; 'this:wp_getPostTypes',
</ins><span class="cx"> 
</span><span class="cx">                         // Blogger API
</span><span class="cx">                         'blogger.getUsersBlogs' =&gt; 'this:blogger_getUsersBlogs',
</span><span class="lines">@@ -347,6 +349,11 @@
</span><span class="cx">                                 'readonly'      =&gt; true,
</span><span class="cx">                                 'value'         =&gt; current_theme_supports( 'post-thumbnails' )
</span><span class="cx">                         ),
</span><ins>+                        'featured_image'    =&gt; array(
+                                'desc'          =&gt; __('Featured Image'),
+                                'readonly'      =&gt; true,
+                                'value'         =&gt; current_theme_supports( 'post-thumbnails' )
+                        ),
</ins><span class="cx"> 
</span><span class="cx">                         // Updatable options
</span><span class="cx">                         'time_zone'         =&gt; array(
</span><span class="lines">@@ -627,6 +634,63 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><ins>+         * Prepares post data for return in an XML-RPC object.
+         *
+         * @access protected
+         *
+         * @param array|object $post_type The unprepared post type data
+         * @param array $fields The subset of post fields to return
+         * @return array The prepared post type data
+         */
+        protected function _prepare_post_type( $post_type, $fields ) {
+                $post_type = (array) $post_type;
+
+                $_post_type = array(
+                        'name' =&gt; $post_type['name'],
+                        'label' =&gt; $post_type['label'],
+                        'description' =&gt; $post_type['description'],
+                        'hierarchical' =&gt; $post_type['hierarchical'],
+                        'public' =&gt; $post_type['public'],
+                        '_builtin' =&gt; $post_type['_builtin'],
+                        'supports' =&gt; get_all_post_type_supports( $post_type['name'] )
+                );
+
+                if ( in_array( 'labels', $fields ) ) {
+                        $_post_type['labels'] = (array) $post_type['labels'];
+                }
+
+                if ( in_array( 'capabilities', $fields ) ) {
+                        $_post_type['cap'] = (array) $post_type['cap'];
+                        $_post_type['capability_type'] = $post_type['capability_type'];
+                        $_post_type['map_meta_cap'] = $post_type['map_meta_cap'];
+                }
+
+                if ( in_array( 'admin', $fields ) ) {
+                        $_post_type['publicly_queryable'] = $post_type['publicly_queryable'];
+                        $_post_type['exclude_from_search'] = $post_type['exclude_from_search'];
+                        $_post_type['_edit_link'] = $post_type['_edit_link'];
+                        $_post_type['rewrite'] = $post_type['rewrite'];
+                        $_post_type['has_archive'] = $post_type['has_archive'];
+                        $_post_type['query_var'] = $post_type['query_var'];
+                }
+
+                if ( in_array( 'menu', $fields ) ) {
+                        $_post_type['show_ui'] = $post_type['show_ui'];
+                        $_post_type['menu_position'] = $post_type['menu_position'];
+                        $_post_type['menu_icon'] = $post_type['menu_icon'];
+                        $_post_type['show_in_nav_menus'] = $post_type['show_in_nav_menus'];
+                        $_post_type['show_in_menu'] = $post_type['show_in_menu'];
+                        $_post_type['show_in_admin_bar'] = $post_type['show_in_admin_bar'];
+                }
+
+                if ( in_array( 'taxonomies', $fields ) ) {
+                        $_post_type['taxonomies'] = get_object_taxonomies( $_post_type['name'] );
+                }
+
+                return apply_filters( 'xmlrpc__prepare_post_type', $_post_type, $post_type );
+        }
+
+        /**
</ins><span class="cx">          * Create a new post for any registered post type.
</span><span class="cx">          *
</span><span class="cx">          * @uses wp_insert_post()
</span><span class="lines">@@ -2882,6 +2946,102 @@
</span><span class="cx">                 return $formats;
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        /**
+         * Retrieves a post type
+         *
+         * @uses get_post_type_object()
+         * @param array $args Method parameters. Contains:
+         *  - int     $blog_id
+         *  - string  $username
+         *  - string  $password
+         *  - string  $post_type_name
+         *  - array   $fields
+         * @return array contains:
+         *  - 'labels'
+         *  - 'description'
+         *  - 'capability_type'
+         *  - 'cap'
+         *  - 'map_meta_cap'
+         *  - 'hierarchical'
+         *  - 'menu_position'
+         *  - 'taxonomies'
+         *  - 'supports'
+         */
+        function wp_getPostType( $args ) {
+                $this-&gt;escape( $args );
+
+                $blog_id        = (int) $args[0];
+                $username       = $args[1];
+                $password       = $args[2];
+                $post_type_name = $args[3];
+
+                if ( isset( $args[4] ) ) 
+                        $fields = $args[4]; 
+                else 
+                        $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'capabilities', 'taxonomies' ), 'wp.getPostType' ); 
+
+                if ( !$user = $this-&gt;login( $username, $password ) )
+                        return $this-&gt;error;
+
+                do_action( 'xmlrpc_call', 'wp.getPostType' );
+
+                if( ! post_type_exists( $post_type_name ) )
+                        return new IXR_Error( 403, __( 'Invalid post type.' ) );
+
+                $post_type = get_post_type_object( $post_type_name );
+
+                if( ! current_user_can( $post_type-&gt;cap-&gt;edit_posts ) )
+                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post type.' ) );
+
+                return $this-&gt;_prepare_post_type( $post_type, $fields );
+        }
+
+        /**
+         * Retrieves a post types
+         *
+         * @access private
+         *
+         * @uses get_post_types()
+         * @param array $args Method parameters. Contains:
+         *  - int     $blog_id
+         *  - string  $username
+         *  - string  $password
+         *  - array   $filter
+         *  - array   $fields
+         * @return array
+         */
+        function wp_getPostTypes( $args ) {
+                $this-&gt;escape( $args );
+
+                $blog_id            = (int) $args[0];
+                $username           = $args[1];
+                $password           = $args[2];
+                $filter             = isset( $args[3] ) ? $args[3] : array( 'public' =&gt; true ); 
+
+                if ( isset( $args[4] ) ) 
+                        $fields = $args[4]; 
+                else 
+                        $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'capabilities', 'taxonomies' ), 'wp.getPostTypes' ); 
+
+                if ( ! $user = $this-&gt;login( $username, $password ) )
+                        return $this-&gt;error;
+
+                do_action( 'xmlrpc_call', 'wp.getPostTypes' );
+
+                $post_types = get_post_types( $filter, 'objects' );
+
+                $struct = array();
+
+                foreach( $post_types as $post_type ) {
+                        if( ! current_user_can( $post_type-&gt;cap-&gt;edit_posts ) )
+                                continue;
+
+                        $struct[$post_type-&gt;name] = $this-&gt;_prepare_post_type( $post_type, $fields );
+                }
+
+                return $struct;
+        }
+
</ins><span class="cx">         /* Blogger API functions.
</span><span class="cx">          * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
</span><span class="cx">          */
</span></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (20270 => 20271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2012-03-23 15:35:44 UTC (rev 20270)
+++ trunk/wp-includes/post.php        2012-03-23 17:53:14 UTC (rev 20271)
</span><span class="lines">@@ -1300,6 +1300,23 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Get all the post type features
+ *
+ * @since 3.4.0
+ * @param string $post_type The post type
+ * @return array
+ */
+
+function get_all_post_type_supports( $post_type ) {
+        global $_wp_post_type_features;
+
+        if ( isset( $_wp_post_type_features[$post_type] ) )
+                return $_wp_post_type_features[$post_type];
+
+        return array();
+}
+
+/**
</ins><span class="cx">  * Checks a post type's support for a given feature
</span><span class="cx">  *
</span><span class="cx">  * @since 3.0.0
</span></span></pre>
</div>
</div>

</body>
</html>