Make WordPress Core

Ticket #18436: wp.getPostType.4.patch

File wp.getPostType.4.patch, 6.0 KB (added by markoheijnen, 13 years ago)

New get all theme support function, updated PHPDoc and little changes to _prepare_post_type

  • wp-includes/post.php

     
    12941294}
    12951295
    12961296/**
     1297 * Get all the post type features
     1298 *
     1299 * @since 3.4.0
     1300 * @param string $post_type The post type
     1301 * @return array
     1302 */
     1303
     1304function get_all_post_type_supports( $post_type ) {
     1305        global $_wp_post_type_features;
     1306
     1307        if ( isset( $_wp_post_type_features[$post_type] ) )
     1308                return $_wp_post_type_features[$post_type];
     1309
     1310        return array();
     1311}
     1312
     1313/**
    12971314 * Checks a post type's support for a given feature
    12981315 *
    12991316 * @since 3.0.0
  • wp-includes/class-wp-xmlrpc-server.php

     
    6969                        'wp.getMediaItem'               => 'this:wp_getMediaItem',
    7070                        'wp.getMediaLibrary'    => 'this:wp_getMediaLibrary',
    7171                        'wp.getPostFormats'     => 'this:wp_getPostFormats',
     72                        'wp.getPostType'                => 'this:wp_getPostType',
     73                        'wp.getPostTypes'               => 'this:wp_getPostTypes',
    7274
    7375                        // Blogger API
    7476                        'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
     
    23632365                return $formats;
    23642366        }
    23652367
     2368        /**
     2369         * Prepares post data for return in an XML-RPC object.
     2370         *
     2371         * @access private
     2372         *
     2373         * @param array|object $post_type The unprepared post type data
     2374         * @param array $fields The subset of post fields to return
     2375         * @return array The prepared post type data
     2376         */
     2377        private function _prepare_post_type( $post_type, $fields ) {
     2378                $post_type = (array) $post_type;
     2379
     2380                $_post_type = array(
     2381                        'name' => $post_type['name'],
     2382                        'label' => $post_type['label'],
     2383                        'description' => $post_type['description'],
     2384                        'hierarchical' => $post_type['hierarchical'],
     2385                        'public' => $post_type['public'],
     2386                        '_builtin' => $post_type['_builtin'],
     2387                        'supports' => get_all_post_type_supports( $post_type['name'] )
     2388                );
     2389
     2390                if ( in_array( 'labels', $fields ) ) {
     2391                        $_post_type['labels'] = $post_type['labels'];
     2392                }
     2393
     2394                if ( in_array( 'capabilities', $fields ) ) {
     2395                        $_post_type['cap'] = $post_type['cap'];
     2396                        $_post_type['capability_type'] = $post_type['capability_type'];
     2397                        $_post_type['map_meta_cap'] = $post_type['map_meta_cap'];
     2398                }
     2399
     2400                if ( in_array( 'admin', $fields ) ) {
     2401                        $_post_type['publicly_queryable'] = $post_type['publicly_queryable'];
     2402                        $_post_type['exclude_from_search'] = $post_type['exclude_from_search'];
     2403                        $_post_type['_edit_link'] = $post_type['_edit_link'];
     2404                        $_post_type['rewrite'] = $post_type['rewrite'];
     2405                        $_post_type['has_archive'] = $post_type['has_archive'];
     2406                        $_post_type['query_var'] = $post_type['query_var'];
     2407                }
     2408
     2409                if ( in_array( 'menu', $fields ) ) {
     2410                        $_post_type['show_ui'] = $post_type['show_ui'];
     2411                        $_post_type['menu_position'] = $post_type['menu_position'];
     2412                        $_post_type['menu_icon'] = $post_type['menu_icon'];
     2413                        $_post_type['show_in_nav_menus'] = $post_type['show_in_nav_menus'];
     2414                        $_post_type['show_in_menu'] = $post_type['show_in_menu'];
     2415                        $_post_type['show_in_admin_bar'] = $post_type['show_in_admin_bar'];
     2416                }
     2417
     2418                if ( in_array( 'taxonomies', $fields ) ) {
     2419                        $_post_type['taxonomies'] = get_object_taxonomies( $_post_type['name'] );
     2420                }
     2421
     2422                return apply_filters( 'xmlrpc__prepare_post_type', $_post_type, $post_type );
     2423        }
     2424
     2425        /**
     2426         * Retrieves a post type
     2427         *
     2428         * @uses get_post_type_object()
     2429         * @param array $args Method parameters. Contains:
     2430         *  - int     $blog_id
     2431         *  - string  $username
     2432         *  - string  $password
     2433         *  - string  $post_type_name
     2434         *  - array   $fields
     2435         * @return array contains:
     2436         *  - 'labels'
     2437         *  - 'description'
     2438         *  - 'capability_type'
     2439         *  - 'cap'
     2440         *  - 'map_meta_cap'
     2441         *  - 'hierarchical'
     2442         *  - 'menu_position'
     2443         *  - 'taxonomies'
     2444         *  - 'supports'
     2445         */
     2446        function wp_getPostType( $args ) {
     2447                $this->escape( $args );
     2448
     2449                $blog_id        = (int) $args[0];
     2450                $username       = $args[1];
     2451                $password       = $args[2];
     2452                $post_type_name = $args[3];
     2453
     2454                if ( isset( $args[4] ) )
     2455                        $fields = $args[4];
     2456                else
     2457                        $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'capabilities', 'taxonomies' ), 'wp.getPostType' );
     2458
     2459                if ( !$user = $this->login( $username, $password ) )
     2460                        return $this->error;
     2461
     2462                do_action( 'xmlrpc_call', 'wp.getPostType' );
     2463
     2464                if( ! post_type_exists( $post_type_name ) )
     2465                        return new IXR_Error( 403, __( 'Invalid post type.' ) );
     2466
     2467                $post_type = get_post_type_object( $post_type_name );
     2468
     2469                if( ! current_user_can( $post_type->cap->edit_posts ) )
     2470                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post type.' ) );
     2471
     2472                return $this->_prepare_post_type( $post_type, $fields );
     2473        }
     2474
     2475        /**
     2476         * Retrieves a post types
     2477         *
     2478         * @access private
     2479         *
     2480         * @uses get_post_types()
     2481         * @param array $args Method parameters. Contains:
     2482         *  - int     $blog_id
     2483         *  - string  $username
     2484         *  - string  $password
     2485         *  - array   $filter
     2486         *  - array   $fields
     2487         * @return array
     2488         */
     2489        function wp_getPostTypes( $args ) {
     2490                $this->escape( $args );
     2491
     2492                $blog_id            = (int) $args[0];
     2493                $username           = $args[1];
     2494                $password           = $args[2];
     2495                $filter             = isset( $args[3] ) ? $args[3] : array( 'public' => true );
     2496
     2497                if ( isset( $args[4] ) )
     2498                        $fields = $args[4];
     2499                else
     2500                        $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'capabilities', 'taxonomies' ), 'wp.getPostTypes' );
     2501
     2502                if ( ! $user = $this->login( $username, $password ) )
     2503                        return $this->error;
     2504
     2505                do_action( 'xmlrpc_call', 'wp.getPostTypes' );
     2506
     2507                $post_types = get_post_types( $filter, 'objects' );
     2508
     2509                $struct = array();
     2510
     2511                foreach( $post_types as $post_type ) {
     2512                        if( ! current_user_can( $post_type->cap->edit_posts ) )
     2513                                continue;
     2514
     2515                        $struct[$post_type->name] = $this->_prepare_post_type( $post_type, $fields );
     2516                }
     2517
     2518                return $struct;
     2519        }
     2520
    23662521        /* Blogger API functions.
    23672522         * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
    23682523         */