最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

filters - Modify Contextual Help

programmeradmin0浏览0评论

Currently I have searched a lot of pages and information covering the contextual help tab (much like here:: 50787, 51861, 77308. Search term:: centextual help), and while there are many useful bits of information out there, it's not quiet honing in on what it is I'm looking for, failing that I'm not quite peicing the information together properly.

theme/ functions.php / Contextual Help Tab / Global

The aim is to "avoid installing any more plugins" than I have to. Additionally, I'm not interest in targeting any particular page, post or plugin, this is a global help as per defualt worpress help tab.

I have managed to cobble together fragments of coding to be able to start the adjustment of the current help tab, however, I'm falling short when it comes to calling and removing the old links.

As it stands, The below coding removes and adds/replaces the right sidebars global content, but with the left menu it is adding the new content but not removing/replacing the old.

function add_context_menu_help(){
// get the current screen object
    $current_screen = get_current_screen();
// content for help tab
    $content = '<p>Has this replaced it?</p>';
// register our main help tab - Overview
    $current_screen->add_help_tab( array(
            'id'        => 'overview-link',
            'title'     => __('Overview'),
            'content'   => $content
        )
    );
// content for help tab
    $content = '<p>Im a help tab, woo!</p>';
// register our main help tab
    $current_screen->add_help_tab( array(
            'id'        => 'sp_basic_help_tab',
            'title'     => __('Basic Help Tab'),
            'content'   => $content
        )
    );
// register our secondary help tab (with a callback instead of content)
    $current_screen->add_help_tab( array(
            'id'        => 'sp_help_tab_callback',
            'title'     => __('Help Tab With Callback'),
            'callback'  => 'display_help_tab'
        )
    );
// 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="/" title="SCS Help Files " target="_blank">SCS Knowledgebase</a>') . '</p>' .
        '<p>' . __('<a href="/" target="_blank">Support Forums</a>') . '</p>'
    );
}
add_filter('admin_head', 'add_context_menu_help');
//function used to display the second help tab
function display_help_tab(){
    $content = '<p>This is text from our output function</p>';
    echo $content;
}

I know I'm missing something, and not for looking; How do I call on the relevant 'id and title' to either remove and or overwrite it, or do I have to call on a link such as Dashboard / Home or Updates, etc?

Your help would be greatly appreciated

KR, John

Currently I have searched a lot of pages and information covering the contextual help tab (much like here:: 50787, 51861, 77308. Search term:: centextual help), and while there are many useful bits of information out there, it's not quiet honing in on what it is I'm looking for, failing that I'm not quite peicing the information together properly.

theme/ functions.php / Contextual Help Tab / Global

The aim is to "avoid installing any more plugins" than I have to. Additionally, I'm not interest in targeting any particular page, post or plugin, this is a global help as per defualt worpress help tab.

I have managed to cobble together fragments of coding to be able to start the adjustment of the current help tab, however, I'm falling short when it comes to calling and removing the old links.

As it stands, The below coding removes and adds/replaces the right sidebars global content, but with the left menu it is adding the new content but not removing/replacing the old.

function add_context_menu_help(){
// get the current screen object
    $current_screen = get_current_screen();
// content for help tab
    $content = '<p>Has this replaced it?</p>';
// register our main help tab - Overview
    $current_screen->add_help_tab( array(
            'id'        => 'overview-link',
            'title'     => __('Overview'),
            'content'   => $content
        )
    );
// content for help tab
    $content = '<p>Im a help tab, woo!</p>';
// register our main help tab
    $current_screen->add_help_tab( array(
            'id'        => 'sp_basic_help_tab',
            'title'     => __('Basic Help Tab'),
            'content'   => $content
        )
    );
// register our secondary help tab (with a callback instead of content)
    $current_screen->add_help_tab( array(
            'id'        => 'sp_help_tab_callback',
            'title'     => __('Help Tab With Callback'),
            'callback'  => 'display_help_tab'
        )
    );
// 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://domainname/" title="SCS Help Files " target="_blank">SCS Knowledgebase</a>') . '</p>' .
        '<p>' . __('<a href="http://domainname/support/" target="_blank">Support Forums</a>') . '</p>'
    );
}
add_filter('admin_head', 'add_context_menu_help');
//function used to display the second help tab
function display_help_tab(){
    $content = '<p>This is text from our output function</p>';
    echo $content;
}

I know I'm missing something, and not for looking; How do I call on the relevant 'id and title' to either remove and or overwrite it, or do I have to call on a link such as Dashboard / Home or Updates, etc?

Your help would be greatly appreciated

KR, John

Share Improve this question edited Oct 8, 2019 at 15:33 John asked Oct 7, 2019 at 17:18 JohnJohn 12 bronze badges 4
  • 1 It took me a few times reading over to clarify what you meant, are you asking how to remove a section in the help tab in the top right corner? Also this isn't a support avenue, sending users here for site support is a violation of the terms and conditions, their questions will get closed if they ask non-dev questions, please remove that. WPSE isn't a general user support forum – Tom J Nowell Commented Oct 7, 2019 at 17:29
  • Humm Interesting. Hi Tom... No. It's not a support question! "are you asking how to remove a section in the help tab in the top right corner?" Yes. I thought it was clear enough. Cobbling something together is not a core problem, but a development I'm wishing to under-go!! – John Commented Oct 7, 2019 at 22:26
  • Yes! You can't send users to WP stack exchange for user support, yet you tell your users to do so when you call set_help_sidebar. This site is for WP development, so any non-dev questions they ask will get closed, and any questions about what you've done might get closed too, any response would be a technical one. This isn't a note about what you're asking, but rather something you did in the very last function call – Tom J Nowell Commented Oct 8, 2019 at 10:42
  • With all due respect, I get that part Tom. If you hadn't noticed, while what I've put together is generally working... it's all test data. I have no intention of sending anyone anywhere other than through to my desk via a dashboard interface I've already put together! That said, the inference here, and as pointed out, is to keep the default wp help panel but remove the default links, therefore, there's no major changes to the core nor needlessly bogging down of the theme. Are you able to help, please? – John Commented Oct 8, 2019 at 15:28
Add a comment  | 

1 Answer 1

Reset to default 0

If you want to remove some or all (default) help tabs, then you could do something like this inside your function.

$current_screen = get_current_screen();

$white_list = array(
  'overview-link', // If you want to keep default some tab title and content
);
if ( $current_tabs = $current_screen->get_help_tabs() ) {
  foreach ($current_tabs as $tab_key => $tab_config) {
    if ( ! in_array( $tab_key, $white_list ) ) {
      $current_screen->remove_help_tab($tab_key);
    }
  }
}

And if you want to replace/overwrite either a default help tab title or content, just do what you're doing in your code at the moment,

$current_screen->add_help_tab( 
  array(
    'id'        => 'overview-link', // by using the ID of a default tab you can replace title and/or content
    'title'     => __('Yay?'),
    'content'   => '<p>Yay!</p>'
  )
);

If you remove all default help tabs with the first code example (i.e. just call remove_help_tab() without the white list in_array() stuff), then it doesn't matter which strings you use as ID's for the new tabs you're adding. The ID's can be the default ones or something else.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论