screen_settings
云策文档标注
概述
screen_settings 过滤器用于修改在 WordPress 后台“屏幕选项”选项卡中显示的设置文本。它允许开发者动态调整或隐藏特定屏幕设置项,例如基于条件或插件需求。
关键要点
- screen_settings 过滤器接收两个参数:$screen_settings(字符串,屏幕设置文本)和 $screen(WP_Screen 对象)。
- 该过滤器在 WP_Screen::show_screen_options() 方法中被调用,位于 wp-admin/includes/class-wp-screen.php 文件中。
- 自 WordPress 3.0.0 版本引入,可用于自定义后台界面,如隐藏特定元框或设置选项。
代码示例
add_filter( 'screen_settings', function ( $screen_settings, $screen ) {
global $wp_meta_boxes;
unset( $wp_meta_boxes['shop_order']['normal']['default']['woocommerce-order-downloads'] );
}, 10, 2 );注意事项
- 使用此过滤器时需谨慎操作,避免影响其他插件或核心功能,建议在特定条件下应用。
- 参数 $screen 提供当前屏幕的 WP_Screen 对象,可用于基于屏幕上下文进行条件判断。
原文内容
Filters the screen settings text displayed in the Screen Options tab.
Parameters
Source
$this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this );
Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |
Skip to note 2 content
neosoir
Hide specific screen setting (in this case Woocommerce download option).
add_filter( 'screen_settings', function ( $screen_settings, $screen ) { global $wp_meta_boxes; unset( $wp_meta_boxes['shop_order']['normal']['default']['woocommerce-order-downloads'] ); }, 10, 2 );