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



_wp_preload_entity_actions › WordPress Function

Seit7.2.0
Veraltetn/v
› _wp_preload_entity_actions ( $paths, $context )
Parameter: (2)
  • (array) $paths REST API paths to preload.
    Erforderlich: Ja
  • (WP_Block_Editor_Context) $context Block editor context.
    Erforderlich: Ja
Gibt zurück:
  • (array) Filtered preload paths.
Definiert in:
Codex:

Preloads the actions of the post types the editors list.

The editors read them from the /wp/v2/entity-actions route as they load, see useEntityActions() in packages/editor/src/dataviews/entity-actions-loader.ts in Gutenberg. The post editor reads those of the edited post in its actions menu. The site editor reads those of the edited post, if any, and of the post types of the screen it opens on, whose lists show the actions of their items. A path must match the request of the getEntityActionsConfig core data resolver, see packages/core-data/src/resolvers.js in Gutenberg.


Quellcode

function _wp_preload_entity_actions( $paths, $context ) {
	$post_types = array();
	if ( 'core/edit-post' === $context->name && isset( $context->post ) ) {
		$post_types[] = $context->post->post_type;
	} elseif ( 'core/edit-site' === $context->name ) {
		if ( isset( $context->post ) ) {
			$post_types[] = $context->post->post_type;
		}
		$post_types = array_merge( $post_types, _wp_get_site_editor_screen_post_types() );
	}

	foreach ( array_unique( $post_types ) as $post_type ) {
		if ( ! post_type_exists( $post_type ) ) {
			continue;
		}
		$paths[] = add_query_arg(
			array(
				'kind' => 'postType',
				'name' => $post_type,
			),
			'/wp/v2/entity-actions'
		);
	}

	return $paths;
}