wp_get_entity_view_config( string $kind, string $name ): array

Returns the view configuration for the given entity.

Description

Builds the default configuration shared by all entities and then exposes it through the dynamic get_entity_view_config_{$kind}_{$name} filter — with the dynamic portions lowercased, see wp_get_entity_view_config_hook_name() — so that core and third parties can provide the configuration for a specific entity.

Parameters

$kindstringrequired
The entity kind (e.g. postType).
$namestringrequired
The entity name (e.g. page).

Return

array The view configuration for the entity.
  • default_view array
    Default view configuration.
  • default_layouts array
    Default layouts configuration.
  • view_list array
    List of available views.
  • form array
    Form configuration.

Source

function wp_get_entity_view_config( $kind, $name ) {
	$default_view    = array(
		'type'       => 'table',
		'filters'    => array(),
		'sort'       => array(
			'field'     => 'title',
			'direction' => 'asc',
		),
		'perPage'    => 20,
		'fields'     => array( 'author', 'status' ),
		'titleField' => 'title',
	);
	$default_layouts = array(
		'table' => array(),
		'grid'  => array(),
		'list'  => array(),
	);
	$all_items_title = __( 'All items' );
	if ( 'postType' === $kind ) {
		$post_type_object = get_post_type_object( $name );
		if ( $post_type_object && ! empty( $post_type_object->labels->all_items ) ) {
			$all_items_title = $post_type_object->labels->all_items;
		}
	}
	$view_list = array(
		array(
			'title' => $all_items_title,
			'slug'  => 'all',
		),
	);

	$config = array(
		'default_view'    => $default_view,
		'default_layouts' => $default_layouts,
		'view_list'       => $view_list,
		'form'            => 'postType' === $kind ? _wp_get_default_posttype_form() : array(),
	);

	$data = new WP_View_Config_Data( $config );

	return $data->apply_filters( $kind, $name );
}

Changelog

VersionDescription
7.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.