使用get_current_screen进行管理逻辑

时间:2018-10-04 08:10:21

标签: php wordpress

我想更改URL wp-admin / admin.php?page = erp-accounting-expense下的文本,并且创建了以下功能,但似乎无法正确获取管理页面。好心提醒。谢谢!

add_action('current_screen', 'current_screen_callback');
function current_screen_callback($screen) {
    if( is_object($screen) && $screen->id == 'erp-accounting-expense' ) {
        add_filter( 'gettext', 'erp_filter_gettext', 99, 3 );
    }
}

function erp_filter_gettext( $translated, $original, $domain ) {

    // Use the text string exactly as it is in the translation file
    if ( $translated == "Receive Payment" )  {
        $translated = "Make Payment";
    }

    return $translated;
}

1 个答案:

答案 0 :(得分:0)

add_action('current_screen', 'current_screen_callback');
function current_screen_callback($screen) {
    if( is_object($screen) && $screen->id == 'accounting_page_erp-accounting-expense' ) {
        add_filter( 'gettext', 'erp_filter_gettext', 99, 3 );
    }
}

function erp_filter_gettext( $translated, $original, $domain ) {

    // Use the text string exactly as it is in the translation file
    if ( $translated == "Receive Payment" )  {
        $translated = "Make Payment";
    }

    return $translated;
}

已解决