Make WordPress Core

Ticket #18437: wp.getPostTypes.2.patch

File wp.getPostTypes.2.patch, 2.0 KB (added by maxcutler, 13 years ago)
  • wp-includes/class-wp-xmlrpc-server.php

     
    6464                        'wp.getMediaItem'               => 'this:wp_getMediaItem',
    6565                        'wp.getMediaLibrary'    => 'this:wp_getMediaLibrary',
    6666                        'wp.getPostFormats'     => 'this:wp_getPostFormats',
     67                        'wp.getPostTypes'               => 'this:wp_getPostTypes',
    6768
    6869                        // Blogger API
    6970                        'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
     
    17021703                return $formats;
    17031704        }
    17041705
     1706        /**
     1707         * Prepares post type data for return in an XML-RPC object
     1708         *
     1709         * @param array|object $post_type The unprepared post type data
     1710         * @return array The prepared post type data
     1711         */
     1712        function prepare_post_type( $post_type ) {
     1713                $_post_type = (array) $post_type;
     1714
     1715                $_post_type['taxonomies'] = get_object_taxonomies( $_post_type['name'] );
     1716
     1717                return apply_filters( 'xmlrpc_prepare_post_type', $_post_type, $post_type );
     1718        }
     1719
     1720        /**
     1721         * Retrieves a post types
     1722         *
     1723         * @uses get_post_types()
     1724         * @param array $args Method parameters. Contains:
     1725         *  - int     $blog_id
     1726         *  - string  $username
     1727         *  - string  $password
     1728         * @return array
     1729         */
     1730        function wp_getPostTypes( $args ) {
     1731                $this->escape( $args );
     1732
     1733                $blog_id            = (int) $args[0];
     1734                $username           = $args[1];
     1735                $password           = $args[2];
     1736
     1737                if ( ! $user = $this->login( $username, $password ) )
     1738                        return $this->error;
     1739
     1740                do_action( 'xmlrpc_call', 'wp.getPostTypes' );
     1741
     1742                $post_types = get_post_types( '', 'objects' );
     1743
     1744                $struct = array();
     1745
     1746                foreach( $post_types as $post_type ) {
     1747                        if( ! current_user_can( $post_type->cap->edit_posts ) )
     1748                                continue;
     1749
     1750                        $struct[$post_type->name] = $this->prepare_post_type( $post_type );
     1751                }
     1752
     1753                return $struct;
     1754        }
     1755
    17051756        /* Blogger API functions.
    17061757         * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
    17071758         */