Filtering Site Editor Screens in WordPress 7.1

This work is part of the iteration issue DataViews, DataForm, et. al. in WordPress 7.1 and it has been tracked at #76544. Check the documentation: filters, properties.

WordPress 7.1 introduces four new filters to configure Site Editor screens:

PageFilterFilter Filters are one of the two types of Hooks https://codex.wordpress.org/Plugin_API/Hooks. They provide a way for functions to modify data of other functions. They are the counterpart to Actions. Unlike Actions, filters are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output. name
Pagesget_entity_view_config_posttype_page
Templatesget_entity_view_config_posttype_wp_template
Partsget_entity_view_config_posttype_wp_template_part
Patternsget_entity_view_config_posttype_wp_block

Each filter can configure the DataViews and DataForm components that power those screens:

  • default_view: the default DataViews configuration (e.g., what fields are visible, what is the default sort order, etc.)
  • default_layouts: the default DataViews layouts (e.g., what layouts are available for the user to choose from)
  • view_list: the preconfigured views displayed in the sidebarSidebar A sidebar in WordPress is referred to a widget-ready area used by WordPress themes to display information that is not a part of the main content. It is not always a vertical column on the side. It can be a horizontal rectangle below or above the content area, footer, header, or any where in the theme. (e.g. “All”, “Published”, “Drafts”, etc.)
  • form: the DataForm configuration used for the Quick Edit form (e.g. which fields are displayed in the form and their order)

Filter callbacks receive an object with the config for the given entity with a set of methods to work with data (API). For example, this code will update the Pages screen by setting grid as the default layout, sort it by ascending title, and add a new visible field date:

function example_filter_page_view_config( $data ) {
	$patch = array(
        'default_view' => array(
            'type'   => 'grid',
            'sort'   => array(
                'field'     => 'title',
                'direction' => 'asc',
            ),
            'fields' => array( 'date' ),
        ),
    );
    $data->merge( $patch, 1 );

    return $data;
}
add_filter( 'get_entity_view_config_posttype_page', 'example_filter_page_view_config' );

Next steps

This mechanism is designed to grow in the future by creating filters for other entities and updating screens to use them. The goal is to have a single place of configuration for an entity that works across screens and components. An example of this work is the experiment to power the editor inspector (built with DataForm) with the data coming from these filters, consolidating Site Editor’s QuickEdit and the editor inspectors.

Future work also includes registration of fields that work across DataViews and DataForm.

Props to @ntsekouras and @priethor for review.

#dev-notes #dev-notes-7-1 #7-1