9

Using the new WP_Screen class makes it pretty easy to add help text to a screen.

<?php
add_action( "load-{$somepage}", 'wpse_load_reading' );
function wpse_load_reading()
{
    get_current_screen()->add_help_tab( array(
        'id'        => 'my-help-tab',
        'title'     => __( 'My Title' ),
        'content'   => __( 'Help Content' )
    ) );
}

This is great for custom pages. But when adding a help tab to an existing screen, let's say options-reading.php, some weirdness happens.

The load-options-reading.php hook fires before the built in WP page adds its own help tabs. In other words, adding a help tab to an existing screen bumps all the built in help tabs to the bottom of the of list.

Here's some code, if you'd like to try this out:

<?php
add_action( "load-options-reading.php", 'wpse_load_reading2' );
function wpse_load_reading2()
{
    get_current_screen()->add_help_tab( array(
        'id'        => 'my-help-tab',
        'title'     => __( 'My Title' ),
        'content'   => __( 'Why is this tab above the built in tab?' )
    ) );
}

Is there any way to reorder the help tabs on a screen?

EDIT:

Found a way around this. The default help tabs are added before the admin-header.php file is included.

So you can hook into load-{$built_in_page}, and from there hook a function admin_head which takes care of setting up your help tabs.

<?php
add_action( 'load-options-reading.php', 'wpse45210_load' );
function wpse45210_load()
{
    add_action( 'admin_head', 'wpse45210_add_help' );
}

function wpse45210_add_help()
{
    get_current_screen()->add_help_tab( array(
        'id'        => 'my-help-tab',
        'title'     => __( 'My Title' ),
        'content'   => __( 'This tab is below the built in tab.' )
    ) );
}

Seems kind of like a hack. Is there a better way?

3 Answers 3

7

Use admin_head-$hook_suffix action, this is same method just removes exta action and callback.

0
6

As @Mamaduka suggested, you can hook into admin_head-{$page_hook} and add the contextual help there. admin_head fires after the default contextual help tabs have been added.

<?php
add_action( 'admin_head-options-reading.php', 'wpse45210_add_help' );
function wpse45210_add_help()
{
    get_current_screen()->add_help_tab( array(
        'id'        => 'my-help-tab',
        'title'     => __( 'My Title' ),
        'content'   => __( 'This tab is below the built in tab.' )
    ) );
}
1

I guess you have three chances:

  1. Use WP_Screen->$_help_tabs to reorder them manually.
  2. Grap the existing help tabs, save them temporarily somewhere else. Then use WP_Screen->remove_help_tab( $id ) and then add them back in manually.
  3. Use the admin_head filter to populate the help tabs or missuse one of the filters or hooks that fire before it in admin-header.php
1
  • 1
    WP_Screen::$_help_tabs is private. Can't access it directly, unfortunately. See my edit, I did your third suggestion! Commented Mar 11, 2012 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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