wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



_wp_get_entity_view_config_posttype_wp_block › WordPress Function

Seit7.1.0
Veraltetn/v
_wp_get_entity_view_config_posttype_wp_block ( $data )
Parameter:
  • (WP_View_Config_Data) $data The view configuration container for the entity.
    Erforderlich: Ja
Gibt zurück:
  • (WP_View_Config_Data) The updated view configuration container.
Definiert in:
Codex:

Provides the view configuration for the `wp_block` post type.



Quellcode

function _wp_get_entity_view_config_posttype_wp_block( $data ) {
	$default_layouts = array(
		'table' => array(
			'layout' => array(
				'styles' => array(
					'author' => array(
						'width' => '1%',
					),
				),
			),
		),
		'grid'  => array(
			'layout' => array(
				'badgeFields' => array( 'sync-status' ),
			),
		),
	);

	$default_view = array(
		'type'       => 'grid',
		'perPage'    => 20,
		'titleField' => 'title',
		'mediaField' => 'preview',
		'fields'     => array( 'sync-status' ),
		'filters'    => array(),
		'layout'     => $default_layouts['grid']['layout'],
	);

	$view_list = array(
		array(
			'title' => __( 'All patterns' ),
			'slug'  => 'all-patterns',
		),
		array(
			'title' => __( 'My patterns' ),
			'slug'  => 'my-patterns',
		),
	);

	// Gather categories from the block pattern categories registry.
	$registry   = WP_Block_Pattern_Categories_Registry::get_instance();
	$categories = array();

	foreach ( $registry->get_all_registered() as $category ) {
		$categories[ $category['name'] ] = $category['label'];
	}

	// Ensure "Uncategorized" is always included for patterns
	// that have no category assigned.
	$categories['uncategorized'] ??= __( 'Uncategorized' );

	// Also gather user-created pattern categories (wp_pattern_category taxonomy).
	$user_terms = get_terms(
		array(
			'taxonomy'   => 'wp_pattern_category',
			'hide_empty' => false,
		)
	);

	if ( ! is_wp_error( $user_terms ) ) {
		foreach ( $user_terms as $term ) {
			$categories[ $term->slug ] = $term->name;
		}
	}

	// Sort categories alphabetically by label.
	asort( $categories, SORT_NATURAL | SORT_FLAG_CASE );

	foreach ( $categories as $category_name => $label ) {
		$view_list[] = array(
			'title' => $label,
			'slug'  => $category_name,
		);
	}

	$form = array(
		'layout' => array( 'type' => 'panel' ),
		'fields' => array(
			array(
				'id'     => 'excerpt',
				'layout' => array(
					'type'          => 'panel',
					'labelPosition' => 'top',
				),
			),
			array(
				'id'     => 'post-content-info',
				'layout' => array(
					'type'          => 'regular',
					'labelPosition' => 'none',
				),
			),
			'sync-status',
			'revisions',
		),
	);

	$data->set(
		array(
			'default_view'    => $default_view,
			'default_layouts' => $default_layouts,
			'view_list'       => $view_list,
			'form'            => $form,
		),
		1
	);

	return $data;
}