wp_xmlrpc_server::_prepare_post_type()protectedWP 3.4.0

Prepares post data for return in an XML-RPC object.

Method of the class: wp_xmlrpc_server{}

Hooks from the method

Return

Array. The prepared post type data.

Usage

// protected - for code of main (parent) or child class
$result = $this->_prepare_post_type( $post_type, $fields );
$post_type(WP_Post_Type) (required)
Post type object.
$fields(array) (required)
The subset of post fields to return.

Changelog

Since 3.4.0 Introduced.
Since 4.6.0 Converted the $post_type parameter to accept a WP_Post_Type object.

wp_xmlrpc_server::_prepare_post_type() code WP 6.4.3

protected function _prepare_post_type( $post_type, $fields ) {
	$_post_type = array(
		'name'         => $post_type->name,
		'label'        => $post_type->label,
		'hierarchical' => (bool) $post_type->hierarchical,
		'public'       => (bool) $post_type->public,
		'show_ui'      => (bool) $post_type->show_ui,
		'_builtin'     => (bool) $post_type->_builtin,
		'has_archive'  => (bool) $post_type->has_archive,
		'supports'     => get_all_post_type_supports( $post_type->name ),
	);

	if ( in_array( 'labels', $fields, true ) ) {
		$_post_type['labels'] = (array) $post_type->labels;
	}

	if ( in_array( 'cap', $fields, true ) ) {
		$_post_type['cap']          = (array) $post_type->cap;
		$_post_type['map_meta_cap'] = (bool) $post_type->map_meta_cap;
	}

	if ( in_array( 'menu', $fields, true ) ) {
		$_post_type['menu_position'] = (int) $post_type->menu_position;
		$_post_type['menu_icon']     = $post_type->menu_icon;
		$_post_type['show_in_menu']  = (bool) $post_type->show_in_menu;
	}

	if ( in_array( 'taxonomies', $fields, true ) ) {
		$_post_type['taxonomies'] = get_object_taxonomies( $post_type->name, 'names' );
	}

	/**
	 * Filters XML-RPC-prepared date for the given post type.
	 *
	 * @since 3.4.0
	 * @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object.
	 *
	 * @param array        $_post_type An array of post type data.
	 * @param WP_Post_Type $post_type  Post type object.
	 */
	return apply_filters( 'xmlrpc_prepare_post_type', $_post_type, $post_type );
}