Make WordPress Core

Ticket #18434: wp.getPostTerms.2.patch

File wp.getPostTerms.2.patch, 2.3 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.getPostTerms'               => 'this:wp_getPostTerms',
    6768
    6869                        // Blogger API
    6970                        'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
     
    17021703                return $formats;
    17031704        }
    17041705
     1706        /**
     1707         * Prepares term data for return in an XML-RPC object
     1708         *
     1709         * @param array $term The unprepared term data
     1710         * @return array The prepared term data
     1711         */
     1712        function prepare_term( $term ) {
     1713                $_term = (array) $term;
     1714
     1715                return apply_filters( 'xmlrpc_prepare_term', $_term, $term );
     1716        }
     1717
     1718        /**
     1719         * Retrieve post terms
     1720         *
     1721         * @uses wp_get_object_terms()
     1722         * @param array $args Method parameters. Contains:
     1723         *  - int     $blog_id
     1724         *  - string  $username
     1725         *  - string  $password
     1726         *  - int     $post_id
     1727         * @return array term data
     1728         */
     1729        function wp_getPostTerms( $args ) {
     1730                $this->escape( $args );
     1731
     1732                $blog_id            = (int) $args[0];
     1733                $username           = $args[1];
     1734                $password           = $args[2];
     1735                $post_id            = (int) $args[3];
     1736
     1737                if ( ! $user = $this->login( $username, $password ) )
     1738                        return $this->error;
     1739
     1740                do_action( 'xmlrpc_call', 'wp.getPostTerms' );
     1741
     1742                $post = wp_get_single_post( $post_id, ARRAY_A );
     1743                if ( empty( $post['ID'] ) )
     1744                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
     1745
     1746                $post_type = get_post_type_object( $post['post_type'] );
     1747
     1748                if( ! current_user_can( $post_type->cap->edit_post , $post_id ) )
     1749                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
     1750
     1751                $taxonomies = get_taxonomies( '' );
     1752
     1753                $terms = wp_get_object_terms( $post_id , $taxonomies );
     1754
     1755                if ( is_wp_error( $terms ) )
     1756                        return new IXR_Error( 500 , $terms->get_error_message() );
     1757
     1758                $struct = array();
     1759
     1760                foreach ( $terms as $term ) {
     1761                        $struct[] = $this->prepare_term( $term );
     1762                }
     1763
     1764                return $struct;
     1765        }
     1766
    17051767        /* Blogger API functions.
    17061768         * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
    17071769         */