函数文档

_add_plugin_file_editor_to_tools()

💡 云策文档标注

概述

此函数用于在块主题的 WordPress 后台工具菜单中添加“插件文件编辑器”子菜单项。它仅在活动主题为块主题时执行,确保功能仅在适用环境中启用。

关键要点

  • 函数 _add_plugin_file_editor_to_tools() 在工具菜单中插入“插件文件编辑器”项,位于“主题文件编辑器”之后。
  • 使用 wp_is_block_theme() 检查活动主题是否为块主题,若非块主题则函数直接返回,不添加菜单。
  • 通过 add_submenu_page() 添加子菜单,需要 edit_plugins 权限,并链接到 plugin-editor.php 页面。
  • 此函数自 WordPress 5.9.0 版本引入,专为块主题设计。

代码示例

function _add_plugin_file_editor_to_tools() {
    if ( ! wp_is_block_theme() ) {
        return;
    }
    add_submenu_page(
        'tools.php',
        __( 'Plugin File Editor' ),
        __( 'Plugin File Editor' ),
        'edit_plugins',
        'plugin-editor.php'
    );
}

📄 原文内容

Adds the ‘Plugin File Editor’ menu item after the ‘Themes File Editor’ in Tools for block themes.

Source

function _add_plugin_file_editor_to_tools() {
	if ( ! wp_is_block_theme() ) {
		return;
	}
	add_submenu_page(
		'tools.php',
		__( 'Plugin File Editor' ),
		__( 'Plugin File Editor' ),
		'edit_plugins',
		'plugin-editor.php'
	);
}

Changelog

Version Description
5.9.0 Introduced.