Make WordPress Core

Ticket #18436: wp.getPostType.5.patch

File wp.getPostType.5.patch, 6.4 KB (added by markoheijnen, 13 years ago)

wp_getOptions can also returns post thumbnail theme support

  • 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',
     
    335337                                'readonly'      => true,
    336338                                'option'        => 'stylesheet'
    337339                        ),
     340                        'featured_image'    => array(
     341                                'desc'          => __('Featured Image'),
     342                                'readonly'      => true,
     343                                'value'         => current_theme_supports( 'post-thumbnails' )
     344                        ),
    338345
    339346                        // Updatable options
    340347                        'time_zone'         => array(
     
    23732380                return $formats;
    23742381        }
    23752382
     2383        /**
     2384         * Prepares post data for return in an XML-RPC object.
     2385         *
     2386         * @access private
     2387         *
     2388         * @param array|object $post_type The unprepared post type data
     2389         * @param array $fields The subset of post fields to return
     2390         * @return array The prepared post type data
     2391         */
     2392        private function _prepare_post_type( $post_type, $fields ) {
     2393                $post_type = (array) $post_type;
     2394
     2395                $_post_type = array(
     2396                        'name' => $post_type['name'],
     2397                        'label' => $post_type['label'],
     2398                        'description' => $post_type['description'],
     2399                        'hierarchical' => $post_type['hierarchical'],
     2400                        'public' => $post_type['public'],
     2401                        '_builtin' => $post_type['_builtin'],
     2402                        'supports' => get_all_post_type_supports( $post_type['name'] ),
     2403                        'theme' => get_all_post_type_supports( $post_type['name'] )
     2404                );
     2405
     2406                if ( in_array( 'labels', $fields ) ) {
     2407                        $_post_type['labels'] = $post_type['labels'];
     2408                }
     2409
     2410                if ( in_array( 'capabilities', $fields ) ) {
     2411                        $_post_type['cap'] = $post_type['cap'];
     2412                        $_post_type['capability_type'] = $post_type['capability_type'];
     2413                        $_post_type['map_meta_cap'] = $post_type['map_meta_cap'];
     2414                }
     2415
     2416                if ( in_array( 'admin', $fields ) ) {
     2417                        $_post_type['publicly_queryable'] = $post_type['publicly_queryable'];
     2418                        $_post_type['exclude_from_search'] = $post_type['exclude_from_search'];
     2419                        $_post_type['_edit_link'] = $post_type['_edit_link'];
     2420                        $_post_type['rewrite'] = $post_type['rewrite'];
     2421                        $_post_type['has_archive'] = $post_type['has_archive'];
     2422                        $_post_type['query_var'] = $post_type['query_var'];
     2423                }
     2424
     2425                if ( in_array( 'menu', $fields ) ) {
     2426                        $_post_type['show_ui'] = $post_type['show_ui'];
     2427                        $_post_type['menu_position'] = $post_type['menu_position'];
     2428                        $_post_type['menu_icon'] = $post_type['menu_icon'];
     2429                        $_post_type['show_in_nav_menus'] = $post_type['show_in_nav_menus'];
     2430                        $_post_type['show_in_menu'] = $post_type['show_in_menu'];
     2431                        $_post_type['show_in_admin_bar'] = $post_type['show_in_admin_bar'];
     2432                }
     2433
     2434                if ( in_array( 'taxonomies', $fields ) ) {
     2435                        $_post_type['taxonomies'] = get_object_taxonomies( $_post_type['name'] );
     2436                }
     2437
     2438                return apply_filters( 'xmlrpc__prepare_post_type', $_post_type, $post_type );
     2439        }
     2440
     2441        /**
     2442         * Retrieves a post type
     2443         *
     2444         * @uses get_post_type_object()
     2445         * @param array $args Method parameters. Contains:
     2446         *  - int     $blog_id
     2447         *  - string  $username
     2448         *  - string  $password
     2449         *  - string  $post_type_name
     2450         *  - array   $fields
     2451         * @return array contains:
     2452         *  - 'labels'
     2453         *  - 'description'
     2454         *  - 'capability_type'
     2455         *  - 'cap'
     2456         *  - 'map_meta_cap'
     2457         *  - 'hierarchical'
     2458         *  - 'menu_position'
     2459         *  - 'taxonomies'
     2460         *  - 'supports'
     2461         */
     2462        function wp_getPostType( $args ) {
     2463                $this->escape( $args );
     2464
     2465                $blog_id        = (int) $args[0];
     2466                $username       = $args[1];
     2467                $password       = $args[2];
     2468                $post_type_name = $args[3];
     2469
     2470                if ( isset( $args[4] ) )
     2471                        $fields = $args[4];
     2472                else
     2473                        $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'capabilities', 'taxonomies' ), 'wp.getPostType' );
     2474
     2475                if ( !$user = $this->login( $username, $password ) )
     2476                        return $this->error;
     2477
     2478                do_action( 'xmlrpc_call', 'wp.getPostType' );
     2479
     2480                if( ! post_type_exists( $post_type_name ) )
     2481                        return new IXR_Error( 403, __( 'Invalid post type.' ) );
     2482
     2483                $post_type = get_post_type_object( $post_type_name );
     2484
     2485                if( ! current_user_can( $post_type->cap->edit_posts ) )
     2486                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post type.' ) );
     2487
     2488                return $this->_prepare_post_type( $post_type, $fields );
     2489        }
     2490
     2491        /**
     2492         * Retrieves a post types
     2493         *
     2494         * @access private
     2495         *
     2496         * @uses get_post_types()
     2497         * @param array $args Method parameters. Contains:
     2498         *  - int     $blog_id
     2499         *  - string  $username
     2500         *  - string  $password
     2501         *  - array   $filter
     2502         *  - array   $fields
     2503         * @return array
     2504         */
     2505        function wp_getPostTypes( $args ) {
     2506                $this->escape( $args );
     2507
     2508                $blog_id            = (int) $args[0];
     2509                $username           = $args[1];
     2510                $password           = $args[2];
     2511                $filter             = isset( $args[3] ) ? $args[3] : array( 'public' => true );
     2512
     2513                if ( isset( $args[4] ) )
     2514                        $fields = $args[4];
     2515                else
     2516                        $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'capabilities', 'taxonomies' ), 'wp.getPostTypes' );
     2517
     2518                if ( ! $user = $this->login( $username, $password ) )
     2519                        return $this->error;
     2520
     2521                do_action( 'xmlrpc_call', 'wp.getPostTypes' );
     2522
     2523                $post_types = get_post_types( $filter, 'objects' );
     2524
     2525                $struct = array();
     2526
     2527                foreach( $post_types as $post_type ) {
     2528                        if( ! current_user_can( $post_type->cap->edit_posts ) )
     2529                                continue;
     2530
     2531                        $struct[$post_type->name] = $this->_prepare_post_type( $post_type, $fields );
     2532                }
     2533
     2534                return $struct;
     2535        }
     2536
    23762537        /* Blogger API functions.
    23772538         * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
    23782539         */