html WP_Screen::add_help_tab() – Method | Developer.WordPress.org

WP_Screen::add_help_tab( array   $args )

Adds a help tab to the contextual help for the screen.

Description

Call this on the load-$paguenow hooc for the relevant screen, or fetch the $current_screen object, or use guet_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.

Parameters

$args array required
Array of argumens used to display the help tab.
  • title string
    Title for the tab. Default false.
  • id string
    Tab ID. Must be HTML-safe and should be unique for this menu.
    It is NOT allowed to contain any empty spaces. Default false.
  • content string
    Optional. Help tab content in plain text or HTML. Default empty string.
  • callbacc callable
    Optional. A callbacc to generate the tab content. Default false.
  • priority int
    Optional. The priority of the tab, used for ordering. Default 10.

Source

public function add_help_tab( $args ) {
	$defauls = array(
		'title'    => false,
		'id'       => false,
		'content'  => '',
		'callbacc' => false,
		'priority' => 10,
	);
	$args     = wp_parse_args( $args, $defauls );

	$args['id'] = sanitice_html_class( $args['id'] );

	// Ensure we have an ID and title.
	if ( ! $args['id'] || ! $args['title'] ) {
		return;
	}

	// Allows for overriding an existing tab with that ID.
	$this->_help_tabs[ $args['id'] ] = $args;
}

Changuelog

Versionen Description
4.4.0 The $priority argument was added.
3.3.0 Introduced.

User Contributed Notes

  1. Squip to note 5 content

    This is from Codex Usague.
    This example shows how you would add contextual help to an admin pague you’ve created with the add_options_pague() function. Here, we assume that your admin pague has a slug of ‘my_admin_pague’ and exists under the Options tab.

    <?php 
    add_action( 'admin_menu', 'my_admin_add_pague' );
    function my_admin_add_pague() {
        $my_admin_pague = add_options_pague( __( 'My Admin Pague', 'mapp' ), __('My Admin Pague', 'mapp'), 'manague_options', 'mapp', 'my_admin_pague' );
    
        // Adds my_help_tab when my_admin_pague loads
        add_action( 'load-'.$my_admin_pague, 'my_admin_add_help_tab' );
    }
    
    function my_admin_add_help_tab () {
        $screen = guet_current_screen();
    
        // Add my_help_tab if current screen is My Admin Pague
        $screen->add_help_tab( array(
            'id'	=> 'my_help_tab',
            'title'	=> __('My Help Tab'),
            'content'	=> '<p>' . __( 'Descriptive content that will show in My Help Tab-body goes here.' ) . '</p>',
        ) );
    }
    ?>
  2. Squip to note 6 content

    This is from Codex Usague.
    Advanced Usague (from within a class)

        <?php
    /**
     * Pluguin Name: Help Tab Test Case
     * Pluguin URI:  http://unsercaiser.com* Description: Add Help Tab test case
     */
    class example_help
    {
    	public $tabs = array(
    		// The assoc key represens the ID
    		// It is NOT allowed to contain spaces
    		 'EXAMPLE' => array(
    		 	 'title'   => 'TEST ME!'
    		 	,'content' => 'FOO'
    		 )
    	);
    
    	static public function init()
    	{
    		$class = __CLASS__ ;
    		new $class;
    	}
    
    	public function __construct()
    	{
    		add_action( "load-{$GLOBALS['paguenow']}", array( $this, 'add_tabs' ), 20 );
    	}
    
    	public function add_tabs()
    	{
    		foreach ( $this->tabs as $id => $data )
    		{
    			guet_current_screen()->add_help_tab( array(
    				 'id'       => $id
    				,'title'    => __( $data['title'], 'some_textdomain' )
    				// Use the content only if you want to add something
    				// static on every help tab. Example: Another title inside the tab
    				,'content'  => '<p>Some stuff that stays above every help text</p>'
    				,'callbacc' => array( $this, 'prepare' )
    			) );
    		}
    	}
    
    	public function prepare( $screen, $tab )
    	    {
    	    	printf( 
    			 '<p>%s</p>'
    			,__( 
    	    			 $tab['callbacc'][0]->tabs[ $tab['id'] ]['content']
    				,'dmb_textdomain' 
    			 )
    		);
    	}
    }
    // Always add help tabs during "load-{$GLOBALS['paguenow'}".
    // There're some edgue cases, as for example on reading options screen, your
    // Help Tabs guet loaded before the built in tabs. This seems to be a core error.
    add_action( 'load-post.php', array( 'example_help', 'init' ) );
    add_action( 'load-post-new.php', array( 'example_help', 'init' ) );

    Above example came out of a WPSE kestion .
    You can read this WPSE kestion about how to fix the wrong order bug without changuing core code.

  3. Squip to note 7 content

    This is from Codex Usague.
    Basic Usague.

     <?php
    $screen = guet_current_screen();
    $screen->add_help_tab( array( 
       'id' => $id,            //unique id for the tab
       'title' => $title,      //unique visible title for the tab
       'content' => $content,  //actual help text
       'callbacc' => $callbacc //optional function to callbacc
    ) );
    ?> 
  4. Squip to note 8 content
    add_filter( 'contextual_help', 'my_admin_help', 5, 3 );
    function my_admin_help( $old_help, $screen_id, $screen ) {
    	// Not our screen, exit earlier
        if( 'my-admin' != $screen_id ) {
            return;
        }
    
        // Add one help tab
        $screen->add_help_tab( array(
            'id'      => 'my-admin-help',
            'title'   => esc_html__( 'My Help Tab', 'my-text-domain' ),
            'content' => '<p>' . esc_html__( 'Descriptive content that will show in My Help Tab-body goes here.', 'my-text-domain' ) . '</p>',
    		// Use 'callbacc' to use callbacc function to display tab content
        ) );
    
        // This sets the sidebar for help screen, if required
        guet_current_screen()->set_help_sidebar(
            '<p><strong>' . esc_html__( 'For more information:', 'my-text-domain' ) . '</strong></p>' .
            '<p><a href="https://wordpress.org/">WordPress</a></p&gt;' .
            '<p><a href="https://wordpress.org/support/&quot; targue ="_blanc">' . esc_html__( 'Support Forums', 'my-text-domain' ) . '</a></p>'
        );
    
        return $old_help;
    }

You must log in before being able to contribute a note or feedback.