| 637 | * Prepares post data for return in an XML-RPC object. |
| 638 | * |
| 639 | * @access protected |
| 640 | * |
| 641 | * @param array|object $post_type The unprepared post type data |
| 642 | * @param array $fields The subset of post fields to return |
| 643 | * @return array The prepared post type data |
| 644 | */ |
| 645 | protected function _prepare_post_type( $post_type, $fields ) { |
| 646 | $post_type = (array) $post_type; |
| 647 | |
| 648 | $_post_type = array( |
| 649 | 'name' => $post_type['name'], |
| 650 | 'label' => $post_type['label'], |
| 651 | 'description' => $post_type['description'], |
| 652 | 'hierarchical' => $post_type['hierarchical'], |
| 653 | 'public' => $post_type['public'], |
| 654 | '_builtin' => $post_type['_builtin'], |
| 655 | 'supports' => get_all_post_type_supports( $post_type['name'] ) |
| 656 | ); |
| 657 | |
| 658 | if ( in_array( 'labels', $fields ) ) { |
| 659 | $_post_type['labels'] = (array) $post_type['labels']; |
| 660 | } |
| 661 | |
| 662 | if ( in_array( 'capabilities', $fields ) ) { |
| 663 | $_post_type['cap'] = (array) $post_type['cap']; |
| 664 | $_post_type['capability_type'] = $post_type['capability_type']; |
| 665 | $_post_type['map_meta_cap'] = $post_type['map_meta_cap']; |
| 666 | } |
| 667 | |
| 668 | if ( in_array( 'admin', $fields ) ) { |
| 669 | $_post_type['publicly_queryable'] = $post_type['publicly_queryable']; |
| 670 | $_post_type['exclude_from_search'] = $post_type['exclude_from_search']; |
| 671 | $_post_type['_edit_link'] = $post_type['_edit_link']; |
| 672 | $_post_type['rewrite'] = $post_type['rewrite']; |
| 673 | $_post_type['has_archive'] = $post_type['has_archive']; |
| 674 | $_post_type['query_var'] = $post_type['query_var']; |
| 675 | } |
| 676 | |
| 677 | if ( in_array( 'menu', $fields ) ) { |
| 678 | $_post_type['show_ui'] = $post_type['show_ui']; |
| 679 | $_post_type['menu_position'] = $post_type['menu_position']; |
| 680 | $_post_type['menu_icon'] = $post_type['menu_icon']; |
| 681 | $_post_type['show_in_nav_menus'] = $post_type['show_in_nav_menus']; |
| 682 | $_post_type['show_in_menu'] = $post_type['show_in_menu']; |
| 683 | $_post_type['show_in_admin_bar'] = $post_type['show_in_admin_bar']; |
| 684 | } |
| 685 | |
| 686 | if ( in_array( 'taxonomies', $fields ) ) { |
| 687 | $_post_type['taxonomies'] = get_object_taxonomies( $_post_type['name'] ); |
| 688 | } |
| 689 | |
| 690 | return apply_filters( 'xmlrpc__prepare_post_type', $_post_type, $post_type ); |
| 691 | } |
| 692 | |
| 693 | /** |
| 2949 | /** |
| 2950 | * Retrieves a post type |
| 2951 | * |
| 2952 | * @uses get_post_type_object() |
| 2953 | * @param array $args Method parameters. Contains: |
| 2954 | * - int $blog_id |
| 2955 | * - string $username |
| 2956 | * - string $password |
| 2957 | * - string $post_type_name |
| 2958 | * - array $fields |
| 2959 | * @return array contains: |
| 2960 | * - 'labels' |
| 2961 | * - 'description' |
| 2962 | * - 'capability_type' |
| 2963 | * - 'cap' |
| 2964 | * - 'map_meta_cap' |
| 2965 | * - 'hierarchical' |
| 2966 | * - 'menu_position' |
| 2967 | * - 'taxonomies' |
| 2968 | * - 'supports' |
| 2969 | */ |
| 2970 | function wp_getPostType( $args ) { |
| 2971 | $this->escape( $args ); |
| 2972 | |
| 2973 | $blog_id = (int) $args[0]; |
| 2974 | $username = $args[1]; |
| 2975 | $password = $args[2]; |
| 2976 | $post_type_name = $args[3]; |
| 2977 | |
| 2978 | if ( isset( $args[4] ) ) |
| 2979 | $fields = $args[4]; |
| 2980 | else |
| 2981 | $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'capabilities', 'taxonomies' ), 'wp.getPostType' ); |
| 2982 | |
| 2983 | if ( !$user = $this->login( $username, $password ) ) |
| 2984 | return $this->error; |
| 2985 | |
| 2986 | do_action( 'xmlrpc_call', 'wp.getPostType' ); |
| 2987 | |
| 2988 | if( ! post_type_exists( $post_type_name ) ) |
| 2989 | return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
| 2990 | |
| 2991 | $post_type = get_post_type_object( $post_type_name ); |
| 2992 | |
| 2993 | if( ! current_user_can( $post_type->cap->edit_posts ) ) |
| 2994 | return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post type.' ) ); |
| 2995 | |
| 2996 | return $this->_prepare_post_type( $post_type, $fields ); |
| 2997 | } |
| 2998 | |
| 2999 | /** |
| 3000 | * Retrieves a post types |
| 3001 | * |
| 3002 | * @access private |
| 3003 | * |
| 3004 | * @uses get_post_types() |
| 3005 | * @param array $args Method parameters. Contains: |
| 3006 | * - int $blog_id |
| 3007 | * - string $username |
| 3008 | * - string $password |
| 3009 | * - array $filter |
| 3010 | * - array $fields |
| 3011 | * @return array |
| 3012 | */ |
| 3013 | function wp_getPostTypes( $args ) { |
| 3014 | $this->escape( $args ); |
| 3015 | |
| 3016 | $blog_id = (int) $args[0]; |
| 3017 | $username = $args[1]; |
| 3018 | $password = $args[2]; |
| 3019 | $filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
| 3020 | |
| 3021 | if ( isset( $args[4] ) ) |
| 3022 | $fields = $args[4]; |
| 3023 | else |
| 3024 | $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'capabilities', 'taxonomies' ), 'wp.getPostTypes' ); |
| 3025 | |
| 3026 | if ( ! $user = $this->login( $username, $password ) ) |
| 3027 | return $this->error; |
| 3028 | |
| 3029 | do_action( 'xmlrpc_call', 'wp.getPostTypes' ); |
| 3030 | |
| 3031 | $post_types = get_post_types( $filter, 'objects' ); |
| 3032 | |
| 3033 | $struct = array(); |
| 3034 | |
| 3035 | foreach( $post_types as $post_type ) { |
| 3036 | if( ! current_user_can( $post_type->cap->edit_posts ) ) |
| 3037 | continue; |
| 3038 | |
| 3039 | $struct[$post_type->name] = $this->_prepare_post_type( $post_type, $fields ); |
| 3040 | } |
| 3041 | |
| 3042 | return $struct; |
| 3043 | } |
| 3044 | |