函数文档

_add_themes_utility_last()

💡 云策文档标注

概述

_add_themes_utility_last() 函数用于在 WordPress 后台菜单中添加“主题文件编辑器”菜单项。根据活动主题是否为块主题,该菜单项会出现在不同的父菜单下。

关键要点

  • 函数功能:添加“主题文件编辑器”子菜单项,允许用户编辑主题文件。
  • 菜单位置:对于非块主题,菜单项位于“外观”菜单底部;对于块主题,则位于“工具”菜单底部。
  • 权限控制:需要 'edit_themes' 权限才能访问此菜单项。
  • 版本变更:自 WordPress 5.9.0 起,菜单项名称从“主题编辑器”更改为“主题文件编辑器”,且块主题下位置移至“工具”菜单。

代码示例

function _add_themes_utility_last() {
    add_submenu_page(
        wp_is_block_theme() ? 'tools.php' : 'themes.php',
        __( 'Theme File Editor' ),
        __( 'Theme File Editor' ),
        'edit_themes',
        'theme-editor.php'
    );
}

注意事项

  • 函数使用 wp_is_block_theme() 动态判断主题类型,确保菜单位置正确。
  • 菜单项文本通过 __() 函数进行国际化处理,支持多语言翻译。
  • 此函数通常由 WordPress 核心调用,开发者无需直接调用,但可参考其实现自定义菜单逻辑。

📄 原文内容

Adds the ‘Theme File Editor’ menu item to the bottom of the Appearance (non-block themes) or Tools (block themes) menu.

Source

function _add_themes_utility_last() {
	add_submenu_page(
		wp_is_block_theme() ? 'tools.php' : 'themes.php',
		__( 'Theme File Editor' ),
		__( 'Theme File Editor' ),
		'edit_themes',
		'theme-editor.php'
	);
}

Changelog

Version Description
5.9.0 Renamed ‘Theme Editor’ to ‘Theme File Editor’.
Relocates to Tools for block themes.
3.0.0 Introduced.