Edit dashboard's help tab

时间:2012-12-26 作者:Keith

我希望编辑仪表板“帮助”选项卡中的文本。我可以将帮助添加到其他页面,但我想更改“帮助”选项卡右侧带有链接的灰色框中的文本。

它位于“了解更多信息:”部分。我想添加到我的支持页面的链接,而不是WordPress支持论坛。

function my_contextual_help( $contextual_help, $screen_id, $screen ) {
    if ( \'product\' == $screen->id ) {
        $contextual_help = \'<h2>Products</h2>
                            <p>Products show the details of the items that we sell on the website. You can see a list of them on this page in reverse chronological order - the latest one we added is first.</p> 
                            <p>You can view/edit the details of each product by clicking on its name, or you can perform bulk actions using the dropdown menu and selecting multiple items.</p>\';

    }
    return $contextual_help;
}

add_action( \'contextual_help\', \'my_contextual_help\', 10, 3 );
这将添加左侧选项卡“Products”,中间有帮助文本,但它没有右侧部分。如何添加此内容?

enter image description here

1 个回复
最合适的回答,由SO网友:brasofilo 整理而成

这个documentation 在法典中似乎过时了。

使用以下代码(请参阅注释):

// Priority 5 allows the removal of default tabs and insertion of other plugin\'s tabs 
add_filter( \'contextual_help\', \'wpse_77308_products_help\', 5, 3 );

function wpse_77308_products_help( $old_help, $screen_id, $screen )
{
    // Not our screen, exit earlier
    // Adjust for your correct screen_id, see plugin recommendation bellow
    if( \'edit-magazine\' != $screen_id )
        return;

    // Remove default tabs
    $screen->remove_help_tabs();

    // Add one help tab
    // For new ones: duplicate this, change id\'s and create custom callbacks
    $screen->add_help_tab( array(
        \'id\'      => \'products-help\',
        \'title\'   => \'Products\',
        \'content\' => \'\', // left empty on purpose, we use the callback bellow
        \'callback\' => \'wpse_77308_print_help\'
    ));

    // This sets the sidebar, which is common for all tabs of this screen
    get_current_screen()->set_help_sidebar(
        \'<p><strong>\' . __(\'For more information:\') . \'</strong></p>\' .
        \'<p>\' . __(\'<a href="http://wordpress.stackexchange.com/" title="WordPress StackExchange" target="_blank">WordPress Answers</a>\') . \'</p>\' .
        \'<p>\' . __(\'<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>\') . \'</p>\'
    );

    return $old_help;
}


function wpse_77308_print_help()
{
    echo \'
        <p>Products show the details of the items that we sell on the website. 
        You can see a list of them on this page in reverse chronological order 
        - the latest one we added is first.</p> 

        <p>You can view/edit the details of each product
        by clicking on its name, or you can perform bulk actions 
        using the dropdown menu and selecting multiple items.</p>
    \';
}

Result:

cpt help tab

获取正确的$screen_id, 使用插件Current Admin Info, 出生于两位伟大的Stack贡献者(kaiser和Stephen Harris)。

显示有关当前管理屏幕及其全局、上下文挂钩等的信息。

该信息显示在管理屏幕右上角»上下文帮助«-面板的新选项卡中。

结束

相关推荐