我只是尝试在类中添加一个简单的帮助选项卡(下面要测试的示例)。我想使用助手/回调fn为不同的帮助选项卡准备内容。根据core,该函数采用一些参数:
WP 3.3/WP管理/包括/屏幕。php第722行
// If it exists, fire tab callback.
if ( ! empty( $tab[\'callback\'] ) )
call_user_func_array( $tab[\'callback\'], array( $this, $tab ) );
出于某种原因,我得到了WP_Screen
对象,而不仅仅是选项卡。看见PasteBin here.下面是一个例子。为了您的方便,作为一个插件,测试更容易(在post屏幕上)。
<?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\' ) );
编辑:如果我只是输出print $tab
在回拨中,我得到Array
作为实际内容上方的输出字符串(WP_Screen
是一个对象)。我尝试转储阵列的所有部分,但没有任何结果(白色屏幕,没有错误)。