如何将添加上下文帮助翻译为Get_Current_Screen()->Add_Help_Tab()

时间:2014-01-24 作者:Michelle Cantin

我遵循了本教程:http://wp.tutsplus.com/tutorials/using-the-settings-api-part-1-create-a-theme-options-page/

有一个不推荐使用的标记

add_contextual_help
它说用这个代替

get_current_screen()->add_help_tab()
但是,我不明白如何翻译“添加上下文帮助”以获取“当前屏幕”(->“添加帮助”选项卡)()

这是使用add\\u Context\\u帮助的代码块

/**
 * The Admin menu page
 */
function wptuts_add_menu(){

$settings_output        = wptuts_get_settings();
// collect our contextual help text
$wptuts_contextual_help = $settings_output[\'wptuts_contextual_help\'];

// Display Settings Page link under the "Appearance" Admin Menu
// add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function);
$wptuts_settings_page = add_theme_page(__(\'Wptuts Options\'), __(\'Wptuts Options\',\'wptuts_textdomain\'), \'manage_options\', WPTUTS_PAGE_BASENAME, \'wptuts_settings_page_fn\');
    // contextual help
    if ($wptuts_settings_page) {
        add_contextual_help( $wptuts_settings_page, $wptuts_contextual_help );
    }
    // css & js
    add_action( \'load-\'. $wptuts_settings_page, \'wptuts_settings_scripts\' );    
}
我该怎么做?

2 个回复
SO网友:t31os

抱歉,只有时间提供快速修复。。。。

看看你能从这里走到哪里。。

/**
 * The Admin menu page
 */
function wptuts_add_menu(){

    // Display Settings Page link under the "Appearance" Admin Menu
    // add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function);
    $wptuts_settings_page = add_theme_page(__(\'Wptuts Options\'), __(\'Wptuts Options\',\'wptuts_textdomain\'), \'manage_options\', WPTUTS_PAGE_BASENAME, \'wptuts_settings_page_fn\');

    // css & js
    add_action( \'load-\'. $wptuts_settings_page, \'wptuts_settings_scripts\' );
    add_action( \'load-\'. $wptuts_settings_page, \'wptuts_add_help\' );
}
function wptuts_add_help() {

    $screen = get_current_screen();

    if( !method_exists( $screen, \'add_help_tab\' ) )
        return;

    $settings_output        = wptuts_get_settings();

    // collect our contextual help text
    $wptuts_contextual_help = $settings_output[\'wptuts_contextual_help\'];

    $sidebar = \'<ul>
        <li><a href="http://wordpress.org/extend/plugins/YOUR_PLUGIN/faq/">\' . __( \'FAQ\', \'your_text_domain\' ) . \'</a></li>
        <li><a href="http://wordpress.org/extend/plugins/YOUR_PLUGIN/other_notes/">\' . __( \'Other notes\', \'your_text_domain\' ) . \'</a></li>
        <li><a href="http://wordpress.org/extend/plugins/YOUR_PLUGIN/changelog/">\' . __( \'Change Log\', \'your_text_domain\' ) . \'</a></li>
        <li><a href="http://wordpress.org/support/plugin/YOUR_PLUGIN#topic">\' . __( \'Support\', \'your_text_domain\' ) . \'</a></li>
    </ul>\';


    $screen->add_help_tab( array( \'title\' => __( \'Title One\', \'your_text_domain\' ), \'id\' => \'id1\', \'content\' => \'text example\'));
    $screen->add_help_tab( array( \'title\' => __( \'Title Two\', \'your_text_domain\' ), \'id\' => \'id2\',    \'content\' => \'text example\'));
    $screen->add_help_tab( array( \'title\' => __( \'Title Three\', \'your_text_domain\' ), \'id\' => \'id3\', \'content\' => \'text example\'));
    $screen->set_help_sidebar( $sidebar );
}

SO网友:Otto

这其实很简单。您已经在使用add\\u theme\\u page添加选项页。添加如下内容:

add_action( \'load-\'. $wptuts_settings_page, \'mytheme_contextual_help\' );
现在,创建一个函数来添加上下文帮助选项卡,如下所示:

function mytheme_contextual_help() {
   $screen = get_current_screen();
   $screen->add_help_tab( array(
      \'id\'      => \'help-tab-1\',
      \'title\'   => \'Title of the first Help Tab\',
      \'content\' => \'<p>HTML for this help tab</p>\',
   ));

   $screen->add_help_tab( array(
      \'id\'      => \'help-tab-2\',
      \'title\'   => \'Title of the second Help Tab\',
      \'content\' => \'<p>HTML for this help tab</p>\',
   ));

}
等等。

您还可以在此函数中调用set\\u help\\u侧栏,为链接和类似内容添加右侧侧栏。

更多信息:

http://ottopress.com/2011/new-in-wordpress-3-3-more-useful-help-screens/

http://codex.wordpress.org/Class_Reference/WP_Screen/add_help_tab

http://codex.wordpress.org/Class_Reference/WP_Screen/set_help_sidebar

结束

相关推荐