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?
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 edited Feb 6, 2014 at 14:44 tfrommen 9,2317 gold badges40 silver badges59 bronze badges asked Nov 30, 2013 at 17:42 Q StudioQ Studio 2,5267 gold badges25 silver badges39 bronze badges1 Answer
Reset to default 5This 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' => '<p>My help content...</p>',
));
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.