函数文档

add_contextual_help()

💡 云策文档标注

概述

add_contextual_help() 是一个已弃用的 WordPress 函数,用于为页面添加上下文帮助文本。自 WordPress 3.3.0 起,推荐使用 WP_Screen::add_help_tab() 替代。

关键要点

  • 函数 add_contextual_help() 已弃用,建议使用 WP_Screen::add_help_tab() 来添加帮助标签。
  • 参数包括 $screen(屏幕句柄,通常来自 add_*_page() 函数)和 $help(帮助内容字符串)。
  • 内部调用 _deprecated_function() 标记弃用,并依赖 WP_Screen::add_old_compat_help() 进行向后兼容处理。

代码示例

// 弃用用法示例(不推荐)
add_contextual_help( 'my-plugin-page', 'This is the help text.' );

// 推荐替代用法
get_current_screen()->add_help_tab( array(
   'id' => 'my-tab-id',
   'title' => 'My Help Tab',
   'content' => 'This is the help text.',
   'callback' => null // 可选回调函数
) );

注意事项

  • 此函数自 WordPress 3.3.0 起弃用,新代码应避免使用,以保持兼容性和最佳实践。
  • 使用 WP_Screen::add_help_tab() 时,需先通过 get_current_screen() 获取当前屏幕对象。

📄 原文内容

Add contextual help text for a page.

Description

Creates an ‘Overview’ help tab.

See also

Parameters

$screenstringrequired
The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions.
$helpstringrequired
The content of an 'Overview' help tab.

Source

function add_contextual_help( $screen, $help ) {
	_deprecated_function( __FUNCTION__, '3.3.0', 'get_current_screen()->add_help_tab()' );

	if ( is_string( $screen ) )
		$screen = convert_to_screen( $screen );

	WP_Screen::add_old_compat_help( $screen, $help );
}

Changelog

Version Description
3.3.0 Deprecated. Use WP_Screen::add_help_tab()
2.7.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    As recommended that

    add_contextual_help( string $screen, string $help )

    is deprecated and suggested to use this

    add_help_tab()

    Here is the usage

    add_help_tab( array( 
       'id' => $id,            //unique id for the tab
       'title' => $title,      //unique visible title for the tab
       'content' => $content,  //actual help text
       'callback' => $callback //optional function to callback
    ) );
    ?> 

    Visit Here for detail description