| 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 | |