Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have working code which adds a help tab to all screens in the admin which already have help options or a help screen - however, screens which don't have contextual help - such as the plugin I writing, also don't recognize the add_action call - how can I ensure that the help_tab appears on each and every screen in the admin?

Some simple code - but it's more or less exactly like in the Codex.

I add the action in the class __construct

// add help tab to admin UI ##
add_action( "load-{$GLOBALS['pagenow']}", array( $this, 'add_help_tab' ), 20 );

This calls a method in the class "add_help_tab":

public function add_help_tab() {
        foreach ( $this->help_tabs as $id => $data ) {
            get_current_screen()->add_help_tab( 
                array(
                    'id'       => $id
                   ,'title'    => __( $data['title'], 'q_support' )
                   // Use the content only if you want to add something
                   // static on every help tab. Example: Another title inside the tab
                   ,'callback' => array( $this, 'callback_function' )
                ) 
            );
        }
}

Which in turn calls the callback method "callback_function" - this all works as expected, except on screens without pre-existing help tabs - is there a way I can ensure each and every page includes the help tab feature?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

This is how you can add help tabs to all admin pages—no matter if there already are any, or not:

add_action('in_admin_header', 'wpse_124979_add_help_tabs');

function wpse_124979_add_help_tabs() {
    if ($screen = get_current_screen()) {
        $help_tabs = $screen->get_help_tabs();
        $screen->remove_help_tabs();

        $screen->add_help_tab(array(
            'id' => 'my_help_tab',
            'title' => 'My Help',
            'content' => 'My help content...',
        ));

        if (count($help_tabs))
            foreach ($help_tabs as $help_tab)
                $screen->add_help_tab($help_tab);
    }
} // function wpse_124979_add_help_tabs

In your OOP setting this should look something like the following:

// This could go in your constructor, for instance
add_action('in_admin_header', array($this, 'add_help_tabs'));

function add_help_tabs() {
    if ($screen = get_current_screen()) {
        $help_tabs = $screen->get_help_tabs();
        $screen->remove_help_tabs();

        foreach ($this->help_tabs as $id => $data)
            $screen->add_help_tab(array(
                'id' => $id,
                'title' => __($data['title'], 'q_support'),
                'callback' => array($this, 'callback_function'),
            ));

        if (count($help_tabs))
            foreach ($help_tabs as $help_tab)
                $screen->add_help_tab($help_tab);
    }
} // function add_help_tabs

in_admin_header is pretty much the last action hook before the screen meta (and so the help) is being rendered.

So, what do you get from this?

  • Add help tabs to every single Admin page (core, plugin, other);
  • your tabs will come before/on top of the original help tabs (if there are any);
  • even if there are no help tabs at all, your tabs will be added to the screen meta.
share|improve this answer
    
Yeh - that's perfect - thanks a million! –  Q Studio Jan 3 at 9:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.