利用WordPress的内置上下文帮助,用于增强插件/主题文档
>>开发人员通常会忽略其WordPress插件和主题的综合文档。 本文探讨了如何有效利用WordPress的内置上下文帮助屏幕来改善用户体验并提供随时可用的支持。 这种方法为稀疏插件目录描述或不可靠的外部网站提供了优越的替代方法。
使用上下文帮助的关键优势:
> class和
添加上下文帮助涉及通过WP_Screen
>函数与get_current_screen()
类互动。此功能标识当前的管理页面,为有针对性的帮助内容提供上下文。
>向所有管理区域添加帮助选项卡:WP_Screen
>
get_current_screen()
以下代码演示了使用内联内容和回调函数添加帮助选项卡:
有针对性的帮助屏幕:
<code class="language-php">function add_context_menu_help(){ $current_screen = get_current_screen(); $content = '<p>This is a sample help tab.</p>'; $current_screen->add_help_tab( array( 'id' => 'my_plugin_basic_help', 'title' => __('Basic Help'), 'content' => $content )); $current_screen->add_help_tab( array( 'id' => 'my_plugin_advanced_help', 'title' => __('Advanced Help'), 'callback' => 'my_plugin_advanced_help_callback' )); } add_action('admin_head', 'add_context_menu_help'); function my_plugin_advanced_help_callback(){ echo '<p>More detailed help content here.</p>'; }</code>
自定义上下文帮助侧栏:
可以自定义上下文帮助侧栏以显示其他信息。 请记住在
>之后添加帮助选项卡:<code class="language-php">function add_help_screen_to_books(){ $current_screen = get_current_screen(); if($current_screen->post_type == 'book' && $current_screen->base == 'edit'){ $content = '<p>Help specific to book post type.</p>'; $current_screen->add_help_tab( array( 'id' => 'my_plugin_book_help', 'title' => __('Book Help'), 'content' => $content )); } } add_action('admin_head', 'add_help_screen_to_books');</code>
结论:
以上是使用WordPress上下文帮助屏幕运行的详细内容。更多信息请关注PHP中文网其他相关文章!