本文档介绍了 WordPress 核心编辑站点(core/edit-site)命名空间下的选择器和操作,用于管理站点编辑器的状态和功能,包括用户权限、模板操作、编辑器模式等。
// 示例:使用 getCanUserCreateMedia 选择器
const canCreateMedia = getCanUserCreateMedia(state);
console.log(canCreateMedia); // 输出布尔值
// 示例:使用 revertTemplate 操作
revertTemplate(template, { allowUndo: true });Namespace: core/edit-site.
Returns whether the current user can create media or not.
Parameters
Object: Global application state.Returns
Object: Whether the current user can create media or not.Deprecated
Deprecated
Returns the template parts and their blocks for the current edited template.
Parameters
Object: Global application state.Returns
Array: Template parts and their blocks in an array.Deprecated
Returns the edited post’s context object.
Parameters
Object: Global application state.Returns
Object: Page.Deprecated
Returns the ID of the currently edited template or template part.
Parameters
Object: Global application state.Returns
?string: Post ID.Deprecated
Returns the current edited post type (wp_template or wp_template_part).
Parameters
Object: Global application state.Returns
?TemplateType: Template type.Returns the current editing mode.
Parameters
Object: Global application state.Returns
string: Editing mode.Deprecated
Deprecated
Deprecated
Returns the current page object.
Parameters
Object: Global application state.Returns
Object: Page.Returns any available Reusable blocks.
Parameters
Object: Global application state.Returns
Array: The available reusable blocks.Returns the site editor settings.
Parameters
Object: Global application state.Returns
Object: Settings.Deprecated
Whether or not the editor allows only page content to be edited.
Returns
boolean: Whether or not focus is on editing page content.Deprecated
Returns whether the given feature is enabled or not.
Parameters
Object: Global application state.string: Feature slug.Returns
boolean: Is active.Deprecated
Returns true if the inserter is opened.
Parameters
Object: Global application state.Returns
boolean: Whether the inserter is opened.Returns true if the list view is opened.
Parameters
Object: Global application state.Returns
boolean: Whether the list view is opened.Deprecated
Deprecated
Whether or not the editor has a page loaded into it.
Related
Parameters
Object: Global application state.Returns
boolean: Whether or not the editor has a page loaded into it.Returns the current opened/closed state of the save panel.
Parameters
Object: Global application state.Returns
boolean: True if the save panel should be open; false if closed.Deprecated
Action that adds a new template and sets it as the current template.
Parameters
Object: The template.Returns
Object: Action object used to set the current template.Action that closes the sidebar.
Action that opens an editor sidebar.
Parameters
?string: Sidebar name to be opened.Deprecated
Opens the navigation panel and sets its active menu at the same time.
Action that removes a template.
Parameters
Object: The template object.Reverts a template to its original theme-provided file.
Parameters
Object: The template to revert.[Object]:[boolean]: Whether to allow the user to undo reverting the template. Default true.Deprecated
Action that sets an edited entity.
Parameters
string: The entity’s post type.string: The entity’s ID.Object: The entity’s context.Returns
Object: Action object.Deprecated
Set’s the current block editor context.
Parameters
Object: The context object.Returns
Object: Action object.Sets whether or not the editor allows only page content to be edited.
Parameters
boolean: True to allow only page content to be edited, false to allow template to be edited.Deprecated
Deprecated
Returns an action object used to open/close the inserter.
Parameters
boolean|Object: Whether the inserter should be opened (true) or closed (false).Deprecated
Returns an action object used to open/close the list view.
Parameters
boolean: A boolean representing whether the list view should be opened or closed.Deprecated
Sets whether the navigation panel should be open.
Sets whether the save view panel should be open.
Parameters
boolean: If true, opens the save view. If false, closes it. It does not toggle the state, but sets it directly.Deprecated
Action that sets a navigation menu.
Parameters
string: The Navigation Menu Post ID.Returns
Object: Action object.Deprecated
Action that sets the active navigation panel menu.
Returns
Object: Action object.Deprecated
Resolves the template for a page and displays both. If no path is given, attempts to use the postId to generate a path like ?p=${ postId }.
Returns
Object: Action object.Action that sets a template, optionally fetching it from REST API.
Returns
Object: Action object.Deprecated
Action that sets a template part.
Parameters
string: The template part ID.Returns
Object: Action object.Deprecated
Triggers an action used to switch editor mode.
Parameters
string: The editor mode.Deprecated
Action that toggles Distraction free mode. Distraction free mode expects there are no sidebars, as due to the z-index values set, you can’t close sidebars.
Dispatches an action that toggles a feature flag.
Parameters
string: Feature name.Returns an action object used to update the settings.
Parameters
Object: New settings.Returns
Object: Action object.