好啊答案是NOT 很简单,但经过一些尝试和错误,阅读core等,我发现了问题所在:
回调(应该使用它来代替content
) 接受两个参数:$current_screen
和$tab
.
这里是什么$tab
看起来,当转储为单个选项卡时。
Array
(
[title] => TEST ME
[id] => EXAMPLE_A
[content] =>
[callback] => Array
(
[0] => dmb_help Object
(
[tabs] => Array
(
[EXAMPLE_A] => Array
(
[title] => TEST ME
[content] => FOO
)
[EXAMPLE_B] => Array
(
[title] => TEST ME ALSO
[content] => BAR
)
)
)
[1] => prepare
)
)
IMPORTANT INFO: 你不是!!(无论如何都不允许)使用
id
-一串然后可以从对象中获取实际内容:
public function prepare( $screen, $tab )
{
printf(
\'<p>%s</p>\'
,__(
$tab[\'callback\'][0]->tabs[ $tab[\'id\'] ][\'content\']
,\'some_textdomain\'
)
);
}
你应该放弃
content
完全在输入数组中(直到在多个帮助选项卡之间循环时不想添加一些重复的内容)。
最后一个工作示例:
这是作为插件的工作文本案例。
<?php
/**
* Plugin Name: Help Tab Test Case
* Plugin URI: http://unserkaiser.com
* Description: Add Help Tab test case
*/
class example_help
{
public $tabs = array(
// The assoc key represents the ID
// It is NOT allowed to contain spaces
\'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\' )
// Use the content only if you want to add something
// static on every help tab. Example: Another title inside the tab
,\'content\' => \'<p>Some stuff that stays above every help text</p>\'
,\'callback\' => array( $this, \'prepare\' )
) );
}
}
public function prepare( $screen, $tab )
{
printf(
\'<p>%s</p>\'
,__(
$tab[\'callback\'][0]->tabs[ $tab[\'id\'] ][\'content\']
,\'dmb_textdomain\'
)
);
}
}
// Always add help tabs during "load-{$GLOBALS[\'pagenow\'}".
// There\'re some edge cases, as for example on reading options screen, your
// Help Tabs get loaded before the built in tabs. This seems to be a core error.
add_action( \'load-post.php\', array( \'example_help\', \'init\' ) );
add_action( \'load-post-new.php\', array( \'example_help\', \'init\' ) );