: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @param string $option Option ID.
* @param mixed $args Option-dependent arguments.
public function add_option( $option, $args = array() ) {
$this->_options[ $option ] = $args;
* Removes an option from the screen.
* @param string $option Option ID.
public function remove_option( $option ) {
unset( $this->_options[ $option ] );
* Removes all options from the screen.
public function remove_options() {
$this->_options = array();
* Gets the options registered for the screen.
* @return array Options with arguments.
public function get_options() {
* Gets the arguments for an option for the screen.
* @param string $option Option name.
* @param string|false $key Optional. Specific array key for when the option is an array.
* @return string The option value if set, null otherwise.
public function get_option( $option, $key = false ) {
if ( ! isset( $this->_options[ $option ] ) ) {
if ( isset( $this->_options[ $option ][ $key ] ) ) {
return $this->_options[ $option ][ $key ];
return $this->_options[ $option ];
* Gets the help tabs registered for the screen.
* @since 4.4.0 Help tabs are ordered by their priority.
* @return array Help tabs with arguments.
public function get_help_tabs() {
$help_tabs = $this->_help_tabs;
foreach ( $help_tabs as $help_tab ) {
if ( isset( $priorities[ $help_tab['priority'] ] ) ) {
$priorities[ $help_tab['priority'] ][] = $help_tab;
$priorities[ $help_tab['priority'] ] = array( $help_tab );
foreach ( $priorities as $list ) {
foreach ( $list as $tab ) {
$sorted[ $tab['id'] ] = $tab;
* Gets the arguments for a help tab.
* @param string $id Help Tab ID.
* @return array Help tab arguments.
public function get_help_tab( $id ) {
if ( ! isset( $this->_help_tabs[ $id ] ) ) {
return $this->_help_tabs[ $id ];
* Adds a help tab to the contextual help for the screen.
* Call this on the `load-$pagenow` hook for the relevant screen,
* or fetch the `$current_screen` object, or use get_current_screen()
* and then call the method from the object.
* You may need to filter `$current_screen` using an if or switch statement
* to prevent new help tabs from being added to ALL admin screens.
* @since 4.4.0 The `$priority` argument was added.
* Array of arguments used to display the help tab.
* @type string $title Title for the tab. Default false.
* @type string $id Tab ID. Must be HTML-safe and should be unique for this menu.
* It is NOT allowed to contain any empty spaces. Default false.
* @type string $content Optional. Help tab content in plain text or HTML. Default empty string.
* @type callable $callback Optional. A callback to generate the tab content. Default false.
* @type int $priority Optional. The priority of the tab, used for ordering. Default 10.
public function add_help_tab( $args ) {
$args = wp_parse_args( $args, $defaults );
$args['id'] = sanitize_html_class( $args['id'] );
// Ensure we have an ID and title.
if ( ! $args['id'] || ! $args['title'] ) {
// Allows for overriding an existing tab with that ID.
$this->_help_tabs[ $args['id'] ] = $args;
* Removes a help tab from the contextual help for the screen.
* @param string $id The help tab ID.
public function remove_help_tab( $id ) {
unset( $this->_help_tabs[ $id ] );
* Removes all help tabs from the contextual help for the screen.
public function remove_help_tabs() {
$this->_help_tabs = array();
* Gets the content from a contextual help sidebar.
* @return string Contents of the help sidebar.
public function get_help_sidebar() {
return $this->_help_sidebar;
* Adds a sidebar to the contextual help for the screen.
* Call this in template files after admin.php is loaded and before admin-header.php is loaded
* to add a sidebar to the contextual help.
* @param string $content Sidebar content in plain text or HTML.
public function set_help_sidebar( $content ) {
$this->_help_sidebar = $content;
* Gets the number of layout columns the user has selected.
* The layout_columns option controls the max number and default number of
* columns. This method returns the number of columns within that range selected
* by the user via Screen Options. If no selection has been made, the default
* provisioned in layout_columns is returned. If the screen does not support
* selecting the number of layout columns, 0 is returned.
* @return int Number of columns to display.
public function get_columns() {
* Gets the accessible hidden headings and text used in the screen.
* @see set_screen_reader_content() For more information on the array format.
* @return string[] An associative array of screen reader text strings.
public function get_screen_reader_content() {
return $this->_screen_reader_content;
* Gets a screen reader text string.
* @param string $key Screen reader text array named key.
* @return string Screen reader text string.
public function get_screen_reader_text( $key ) {
if ( ! isset( $this->_screen_reader_content[ $key ] ) ) {
return $this->_screen_reader_content[ $key ];
* Adds accessible hidden headings and text for the screen.
* @param array $content {
* An associative array of screen reader text strings.
* @type string $heading_views Screen reader text for the filter links heading.
* Default 'Filter items list'.
* @type string $heading_pagination Screen reader text for the pagination heading.
* Default 'Items list navigation'.
* @type string $heading_list Screen reader text for the items list heading.
public function set_screen_reader_content( $content = array() ) {
'heading_views' => __( 'Filter items list' ),
'heading_pagination' => __( 'Items list navigation' ),
'heading_list' => __( 'Items list' ),
$content = wp_parse_args( $content, $defaults );
$this->_screen_reader_content = $content;
* Removes all the accessible hidden headings and text for the screen.
public function remove_screen_reader_content() {
$this->_screen_reader_content = array();
* Renders the screen's help section.
* This will trigger the deprecated filters for backward compatibility.
* @global string $screen_layout_columns
public function render_screen_meta() {
* Filters the legacy contextual help list.
* @deprecated 3.3.0 Use {@see get_current_screen()->add_help_tab()} or
* {@see get_current_screen()->remove_help_tab()} instead.
* @param array $old_compat_help Old contextual help.
* @param WP_Screen $screen Current WP_Screen instance.
self::$_old_compat_help = apply_filters_deprecated(
array( self::$_old_compat_help, $this ),
'get_current_screen()->add_help_tab(), get_current_screen()->remove_help_tab()'
$old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : '';
* Filters the legacy contextual help text.
* @deprecated 3.3.0 Use {@see get_current_screen()->add_help_tab()} or
* {@see get_current_screen()->remove_help_tab()} instead.
* @param string $old_help Help text that appears on the screen.
* @param string $screen_id Screen ID.
* @param WP_Screen $screen Current WP_Screen instance.
$old_help = apply_filters_deprecated(
array( $old_help, $this->id, $this ),
'get_current_screen()->add_help_tab(), get_current_screen()->remove_help_tab()'
// Default help only if there is no old-style block of text and no new-style help tabs.
if ( empty( $old_help ) && ! $this->get_help_tabs() ) {
* Filters the default legacy contextual help text.
* @deprecated 3.3.0 Use {@see get_current_screen()->add_help_tab()} or
* {@see get_current_screen()->remove_help_tab()} instead.
* @param string $old_help_default Default contextual help text.
$default_help = apply_filters_deprecated(
'default_contextual_help',
'get_current_screen()->add_help_tab(), get_current_screen()->remove_help_tab()'
$old_help = '<p>' . $default_help . '</p>';
'id' => 'old-contextual-help',
'title' => __( 'Overview' ),
$help_sidebar = $this->get_help_sidebar();
$help_class .= ' no-sidebar';
<div id="screen-meta" class="metabox-prefs">
<div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>" tabindex="-1" aria-label="<?php esc_attr_e( 'Contextual Help Tab' ); ?>">
<div id="contextual-help-back"></div>
<div id="contextual-help-columns">
<div class="contextual-help-tabs">
$class = ' class="active"';
foreach ( $this->get_help_tabs() as $tab ) :
$link_id = "tab-link-{$tab['id']}";
$panel_id = "tab-panel-{$tab['id']}";
<li id="<?php echo esc_attr( $link_id ); ?>"<?php echo $class; ?>>
<a href="<?php echo esc_url( "#$panel_id" ); ?>" aria-controls="<?php echo esc_attr( $panel_id ); ?>">
<?php echo esc_html( $tab['title'] ); ?>
<?php if ( $help_sidebar ) : ?>
<div class="contextual-help-sidebar">
<?php echo $help_sidebar; ?>
<div class="contextual-help-tabs-wrap">
$classes = 'help-tab-content active';
foreach ( $this->get_help_tabs() as $tab ) :
$panel_id = "tab-panel-{$tab['id']}";
<div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo $classes; ?>">
// If it exists, fire tab callback.
if ( ! empty( $tab['callback'] ) ) {
call_user_func_array( $tab['callback'], array( $this, $tab ) );
$classes = 'help-tab-content';
* Filters the array of screen layout columns.
* This hook provides back-compat for plugins using the back-compat
* Filters instead of add_screen_option().
* @param array $empty_columns Empty array.
* @param string $screen_id Screen ID.
* @param WP_Screen $screen Current WP_Screen instance.
$columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) ) {
$this->add_option( 'layout_columns', array( 'max' => $columns[ $this->id ] ) );
if ( $this->get_option( 'layout_columns' ) ) {
$this->columns = (int) get_user_option( "screen_layout_$this->id" );
if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) ) {
$this->columns = $this->get_option( 'layout_columns', 'default' );
$GLOBALS['screen_layout_columns'] = $this->columns; // Set the global for back-compat.
if ( $this->show_screen_options() ) {
$this->render_screen_options();
if ( ! $this->get_help_tabs() && ! $this->show_screen_options() ) {
<div id="screen-meta-links">
<?php if ( $this->show_screen_options() ) : ?>
<div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
<button type="button" id="show-settings-link" class="button show-settings" aria-controls="screen-options-wrap" aria-expanded="false"><?php _e( 'Screen Options' ); ?></button>
if ( $this->get_help_tabs() ) :
<div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
<button type="button" id="contextual-help-link" class="button show-settings" aria-controls="contextual-help-wrap" aria-expanded="false"><?php _e( 'Help' ); ?></button>
* @global array $wp_meta_boxes Global meta box state.
public function show_screen_options() {
if ( is_bool( $this->_show_screen_options ) ) {
return $this->_show_screen_options;
$columns = get_column_headers( $this );
$show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' );