WP_Customize_Nav_Menus_Panel
概述
WP_Customize_Nav_Menus_Panel 是 WordPress 自定义器中用于管理导航菜单的面板类,继承自 WP_Customize_Panel。它扩展了导航菜单的屏幕选项功能,并提供了特定的内容模板。
关键要点
- 继承自 WP_Customize_Panel,类型为 'nav_menus',用于自定义器中的导航菜单管理。
- 包含方法如 check_capabilities 检查用户权限和主题支持,content_template 提供 JS 模板,render_screen_options 渲染屏幕选项。
- wp_nav_menu_manage_columns 方法已弃用,建议使用 wp_nav_menu_manage_columns 函数。
- 从 WordPress 4.3.0 版本引入,用于增强导航菜单的自定义体验。
代码示例
public function render_screen_options() {
// Adds the screen options.
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' );
// Display screen options.
$screen = WP_Screen::get( 'nav-menus.php' );
$screen->render_screen_options( array( 'wrap' => false ) );
}注意事项
- wp_nav_menu_manage_columns 方法在 4.5.0 版本后已弃用,应改用 wp_nav_menu_manage_columns 函数。
- content_template 方法使用 Underscore.js 模板,用于定义面板内容,但不包括容器。
Customize Nav Menus Panel Class
Description
Needed to add screen options.
See also
Methods
| Name | Description |
|---|---|
| WP_Customize_Nav_Menus_Panel::check_capabilities | Checks required user capabilities and whether the theme has the feature support required by the panel. |
| WP_Customize_Nav_Menus_Panel::content_template | An Underscore (JS) template for this panel’s content (but not its container). |
| WP_Customize_Nav_Menus_Panel::render_screen_options | Render screen options for Menus. |
| WP_Customize_Nav_Menus_Panel::wp_nav_menu_manage_columns | Returns the advanced options for the nav menus page. — deprecated |
Source
class WP_Customize_Nav_Menus_Panel extends WP_Customize_Panel {
/**
* Control type.
*
* @since 4.3.0
* @var string
*/
public $type = 'nav_menus';
/**
* Render screen options for Menus.
*
* @since 4.3.0
*/
public function render_screen_options() {
// Adds the screen options.
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' );
// Display screen options.
$screen = WP_Screen::get( 'nav-menus.php' );
$screen->render_screen_options( array( 'wrap' => false ) );
}
/**
* Returns the advanced options for the nav menus page.
*
* Link title attribute added as it's a relatively advanced concept for new users.
*
* @since 4.3.0
* @deprecated 4.5.0 Deprecated in favor of wp_nav_menu_manage_columns().
*/
public function wp_nav_menu_manage_columns() {
_deprecated_function( __METHOD__, '4.5.0', 'wp_nav_menu_manage_columns' );
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
return wp_nav_menu_manage_columns();
}
/**
* An Underscore (JS) template for this panel's content (but not its container).
*
* Class variables for this panel class are available in the `data` JS object;
* export custom variables by overriding WP_Customize_Panel::json().
*
* @since 4.3.0
*
* @see WP_Customize_Panel::print_template()
*/
protected function content_template() {
?>
<li class="panel-meta customize-info accordion-section <# if ( ! data.description ) { #> cannot-expand<# } #>">
<button type="button" class="customize-panel-back" tabindex="-1">
<span class="screen-reader-text">
</span>
</button>
<div class="accordion-section-title">
<span class="preview-notice">
{{ data.title }}</strong>' );
?>
</span>
<button type="button" class="customize-help-toggle dashicons dashicons-editor-help" aria-expanded="false">
<span class="screen-reader-text">
</span>
</button>
<button type="button" class="customize-screen-options-toggle" aria-expanded="false">
<span class="screen-reader-text">
</span>
</button>
</div>
<# if ( data.description ) { #>
<div class="description customize-panel-description">{{{ data.description }}}</div>
<# } #>
<div id="screen-options-wrap">
render_screen_options(); ?>
</div>
</li>
<li class="customize-control-title customize-section-title-nav_menus-heading"></li>
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-nav-menus-panel.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/customize/class-wp-customize-nav-menus-panel.php#L19">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/customize/class-wp-customize-nav-menus-panel.php#L19-L116">View on GitHub</a></p></section>
<section class="wp-block-wporg-code-reference-related" data-nosnippet="true"><h2 id="related" class="is-toc-heading wp-block-heading has-heading-5-font-size" tabindex="-1" ><a href="#related">Related</a></h2> <section style="margin-top:var(--wp--preset--spacing--20)" class="wp-block-wporg-code-table" id="uses"><figure class="wp-block-table "><table><thead><tr><th scope="col">Uses</th><th scope="col">Description</th></tr></thead><tbody><tr class=""><td><a href="https://developer.wordpress.org/reference/classes/wp_customize_panel/">WP_Customize_Panel</a><code>wp-includes/class-wp-customize-panel.php
Changelog
| Version | Description |
|---|---|
| 4.3.0 | Introduced. |