問題描述

使用新的 WP_Screen 類可以很容易地將幫助文字新增到螢幕。

<?php
add_action( "load-{$somepage}", 'wpse_load_reading' );
function wpse_load_reading()
{
    get_current_screen()->add_help_tab( array(
        'id'        => 'my-help-tab',
        'title'     => __( 'My Title' ),
        'content'   => __( 'Help Content' )
    ) );
}

這對於自定義頁面來說非常棒。但是當在現有螢幕上新增一個幫助選項卡時,我們來說 options-reading.php 有些奇怪。

load-options-reading.php 鉤子在內建 WP 頁面新增自己的幫助選項卡之前觸發。換句話說,在現有的螢幕上新增一個幫助標籤會將所有內建的幫助選項卡顛倒到列表的底部。

這裡有一些程式碼,如果你想嘗試一下:

<?php
add_action( "load-options-reading.php", 'wpse_load_reading2' );
function wpse_load_reading2()
{
    get_current_screen()->add_help_tab( array(
        'id'        => 'my-help-tab',
        'title'     => __( 'My Title' ),
        'content'   => __( 'Why is this tab above the built in tab?' )
    ) );
}

有沒有辦法在螢幕上重新排列幫助標籤?

編輯:

找到了一個辦法。在包括 admin-header.php 檔案之前新增預設幫助選項卡。

所以你可以掛接到 load-{$built_in_page},並從那裡鉤一個功能 admin_head,它負責設定你的幫助選項卡。

<?php
add_action( 'load-options-reading.php', 'wpse45210_load' );
function wpse45210_load()
{
    add_action( 'admin_head', 'wpse45210_add_help' );
}

function wpse45210_add_help()
{
    get_current_screen()->add_help_tab( array(
        'id'        => 'my-help-tab',
        'title'     => __( 'My Title' ),
        'content'   => __( 'This tab is below the built in tab.' )
    ) );
}

似乎像一個駭客。有沒有更好的辦法?

最佳解決方案

使用 admin_head-$hook_suffix 操作,這是相同的方法只是刪除 exta 動作和回撥。

次佳解決方案

如 @Mamaduka 所建議的,您可以掛接到 admin_head-{$page_hook}並在其中新增上下文幫助。 admin_head 在新增預設上下文幫助選項卡後觸發。

<?php
add_action( 'admin_head-options-reading.php', 'wpse45210_add_help' );
function wpse45210_add_help()
{
    get_current_screen()->add_help_tab( array(
        'id'        => 'my-help-tab',
        'title'     => __( 'My Title' ),
        'content'   => __( 'This tab is below the built in tab.' )
    ) );
}

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。