【问题标题】:wordpress: detect plugins and themes screens activationwordpress:检测插件和主题屏幕激活
【发布时间】:2017-09-07 13:27:08
【问题描述】:

我需要检测用户何时去:

插件 -> 已安装的插件和外观 -> 主题

在 wordpress 管理员中。

类似:

add_action("core_upgrade_preamble", "action_core_upgrade_preamble")

【问题讨论】:

  • 如果他们去那个部分你想做什么?
  • 我想在这些部分添加一些内容

标签: php wordpress action add


【解决方案1】:

你有两个选择:

选项 1
使用回调$hook,首先使用这个获取页面的$hook

function load_custom_wp_admin_style($hook) {
        var_dump($hook);
}
add_action( 'admin_init', 'load_custom_wp_admin_style' );

在浏览器中检查你的页面你应该得到字符串名称,然后你可以使用:

function load_custom_wp_admin_style($hook) {
        // Load only on my specific page
        if($hook != 'page_hook_i_got') {
                return;
        }
        //DO MY LOGIC   

}
add_action( 'admin_init', 'load_custom_wp_admin_style' );

选项 2
使用get_current_screen();

add_action( 'current_screen', 'this_screen' );

function this_screen() {

    $current_screen = get_current_screen();

    if( $current_screen ->id === "widgets" ) {

        // Run some code, only on the admin widgets page

    }

}

您需要通过var_dump 查找页面的id,如选项1 中,您可以找到更多信息here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-21
    • 2014-11-05
    • 2018-04-06
    • 2021-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多