I just tried to add a simple help tab, from within a class (example to test below). I wanted to use a helper/callback fn to prepare the content for different help tabs. According to core, the function takes some args:
WP 3.3 /wp-admin/includes/screen.php LINE 722
// If it exists, fire tab callback.
if ( ! empty( $tab['callback'] ) )
call_user_func_array( $tab['callback'], array( $this, $tab ) );
For some reason I get the complete WP_Screen
object in the callback, instead of just the tab. See PasteBin here.
Here's the example. For your convenience, as a plugin, so testing is easier (on post screens).
<?php
/**
* Plugin Name: Help Tab Test Case
* Plugin URI: http://unserkaiser.com
* Description: Add Help Tab test case
*/
class example_help
{
public $tabs = array(
'EXAMPLE' => array(
'title' => 'TEST ME!'
,'content' => 'FOO'
)
);
static public function init()
{
$class = __CLASS__ ;
new $class;
}
public function __construct()
{
add_action( "load-{$GLOBALS['pagenow']}", array( $this, 'add_tabs' ), 20 );
}
public function add_tabs()
{
foreach ( $this->tabs as $id => $data )
{
get_current_screen()->add_help_tab( array(
'id' => $id
,'title' => __( $data['title'], 'some_textdomain' )
,'content' => $data['content']
,'callback' => array( $this, 'prepare' )
) );
}
}
/* HELPER */
public function prepare( $tab )
{
error_reporting( E_ALL );
// FAILS: return blank
// _dump( $tab['tabs'] );
// No error output on screen
var_dump( $tab );
// I can dump it using my own function,
// that adds the data to a global and then calls & prints it on shutdown
// See pastebin for content
// _dump( $tab );
return printf(
'<p>%s</p>'
,__( 'test', 'dmb_textdomain' )
);
}
}
add_action( 'load-post.php', array( 'example_help', 'init' ) );
add_action( 'load-post-new.php', array( 'example_help', 'init' ) );
Edit:
If I just output print $tab
in the callback, I get Array
as output string above the actual content (WP_Screen
is an object). I tried dumping all parts of the array without any result (white screen, no error).