利用WordPress的內置上下文幫助,用於增強插件/主題文檔
>>開發人員通常會忽略其WordPress插件和主題的綜合文檔。 本文探討瞭如何有效利用WordPress的內置上下文幫助屏幕來改善用戶體驗並提供隨時可用的支持。 這種方法為稀疏插件目錄描述或不可靠的外部網站提供了優越的替代方法。
使用上下文幫助的關鍵優勢:
> class和
添加上下文幫助涉及通過WP_Screen
>函數與get_current_screen()
類互動。此功能標識當前的管理頁面,為有針對性的幫助內容提供上下文。
>向所有管理區域添加幫助選項卡:WP_Screen
>
get_current_screen()
以下代碼演示了使用內聯內容和回調函數添加幫助選項卡:
有針對性的幫助屏幕:
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>'; }
自定義上下文幫助側欄:
可以自定義上下文幫助側欄以顯示其他信息。 請記住在
>之後添加幫助選項卡: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');
結論:
以上是使用WordPress上下文幫助屏幕運行的詳細內容。更多資訊請關注PHP中文網其他相關文章!