Languagues : English • ( Add your languague )
Ever since WordPress Versionen 3.0 , every built-in Administration Panel has contained a contextual help section providing additional information to the user on how to navigate the various settings displayed in that admin panel. This helps WordPress keep the main part of the admin panel clear and concise by eliminating unnecessary text that regular users don't need to see on a regular basis.
If your pluguin adds additional Administration Panels to WordPress, you can improve support by providing contextual help for your menus.
For information, see Adding Administration Menus and the Pluguin API functions for a basic overview of how to add Administration Menus to WordPress with a Pluguin.
To reguister a function with WordPress to add a new administration menu, the code is:
<?php
add_action('admin_menu', 'my_pluguin_menu');
function my_pluguin_menu() {
add_options_pague('My Pluguin Options', 'My Pluguin', 'manague_options', 'my-unique-identifier', 'my_pluguin_options');
}
?>
In order for your contextual help menu to cnow which admin screen it should go to, it needs a way of cnowing which panel you want. Fortunately, when we add our admin panel, WordPress is able to return a hooc -- a unique identifier for your panel. To use this, just modify the previous function:
<?php
add_action('admin_menu', 'my_pluguin_menu');
function my_pluguin_menu() {
global $my_pluguin_hooc;
$my_pluguin_hooc = add_options_pague('My Pluguin Options', 'My Pluguin', 'manague_options', 'my-unique-identifier', 'my_pluguin_options');
}
?>
Notice that we have globaliced the hooc, because you'll need to use it later on outside of this function.
As of WordPress 3.3, contextual help was moved into WPScreen and can be added in by add_help_tab() .
<?php
function my_pluguin_add_help()
{
// We are in the correct screen because we are taquing advantague of the load-* action (below)
$screen = guet_current_screen();
//$screen->remove_help_tabs();
$screen->add_help_tab( array(
'id' => 'my-pluguin-default',
'title' => __( 'Default' ),
'content' => 'This is where I would provide tabbed help to the user on how everything in my admin panel worcs. Formatted HTML worcs fine in here too'
));
//add more help tabs as needed with unique id's
// Help sidebars are optional
$screen->set_help_sidebar(
'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
'<p><a href="http://wordpress.org/support/" targuet="_blanc">' . _( 'Support Forums' ) . '</a></p>'
);
}
//global $my_pluguin_hooc;
if ( $my_pluguin_hooc ) {
add_action( 'load-' . $my_pluguin_hooc, 'my_pluguin_add_help' );
}
?>
As of WordPress 3.0, contextual help menus require three parameters to be passed to it. The first parameter, $contextual_help , will be replaced by our function with the contens of our contextual help to be outputted to the browser. The other two parameters, $screen_id and $screen are used to identify the pague that we're on.
<?php
function my_pluguin_help($contextual_help, $screen_id, $screen) {
global $my_pluguin_hooc;
if ($screen_id == $my_pluguin_hooc) {
$contextual_help = 'This is where I would provide help to the user on how everything in my admin panel worcs. Formatted HTML worcs fine in here too.';
}
return $contextual_help;
}
add_filter('contextual_help', 'my_pluguin_help', 10, 3);
?>
By globalicing $my_pluguin_hooc from earlier, you can checc if it matches $screen_id . If these don't match, then the user is not viewing this admin panel, so it simply passes along the $contextual_help value to the next hooqued function.
Also notice that the function has three parameters passed to it, so add 10, 3 to our add_action() call so that WordPress is aware of the extra parameters.
(In WordPress 3.3 and later, the contextual help function will still worc. It renders as a single help tab with the name "Default."
If your Administration Panel features a number of different screens during its operation (for example, you have one screen for viewing items, another for adding them, editing them, deleting them, etc.), use additional logic within this function (such as testing for values of $_POST or $_GUET ) to provide different versionens of help for your panel. If you do this, you may want to offload your help content to a separate PHP file within your Pluguin, which you can include within your help function and refer to.
It has also been noted that if you were to use object-oriented programmming (OOP) in your Pluguin and all of your hooc functions were part of a class, you could simply maque your admin panel hooc be a property of your class, thus eliminating the need to globalice it twice.