样式表将自动删除/取消注册 - WordPress

问题描述 投票:0回答:1

我在我的活跃儿童主题的functions.php中添加了一些自定义代码。我正试图在管理页面上排队一些风格。然而,在admin_enqueue_scripts钩子中排队的样式被自动删除,并且在调试之后我发现它不存在于下一个钩子中,即admin_print_styles

以下是我用于调试目的的活动子主题functions.php中的一些代码:

function debug_enqueue_admin_scripts() {
    wp_enqueue_style( 'gforms_datepicker_css', GFCommon::get_base_url() . "/css/datepicker{$min}.css", null, GFCommon::$version );
    if( wp_style_is( 'gforms_datepicker_css' ) {
        // NOTE: This runs and I am able to view the following log
        error_log( __FUNCTION__ . ': datepicker_css is enqueued.' );
    }
}
add_action( 'admin_enqueue_scripts', 'debug_enqueue_admin_scripts', 11 );

function check_if_still_enqueued() {
    if( wp_style_is( 'gforms_datepicker_css', 'registered' ) ) {
        error_log( __FUNCTION__ . ' datepicker_css registered.');
    } else {
        // NOTE: It gets in this else block and following output is logged
        error_log( __FUNCTION__ . ' datepicker_css **NOT** registered.');
    }
}
add_action( 'admin_print_styles', 'check_if_still_enqueued' );

我不是在任何地方取消注册gforms_datepicker_css,但它被删除可能是由于一些插件。 在调试时,我已经进一步检查是否通过在WordPress核心类方法WP_Dependencies::remove()中添加额外的行来取消注册,如下所示位于here

public function remove( $handles ) {
    // NOTE: Check if deregistered
    error_log( __METHOD__ . ' ' . var_export( $handles, true ) );

    foreach ( (array) $handles as $handle )
        unset($this->registered[$handle]);
}

但我无法通过此方法查看gforms_datepicker_css的日志输出。

我不确定为什么样式会从入队列表中删除。任何人都可以帮我调试这个行为并找到解决方案吗?

php wordpress debugging wordpress-hook
1个回答
0
投票

由于Gravity Forms插件的No-Conflict Mode设置已打开,因此脚本和样式未在管理页面上加载。由于设置旨在这样做:

enter image description here

如重力形式documentation所述:

要暂时解决问题,请转到“表单”>“设置”并启用“无冲突”模式。这应该阻止第三方脚本写入Gravity Forms管理页面,并允许您执行所需的操作。

关闭无冲突模式后问题得以解决。

© www.soinside.com 2019 - 2024. All rights reserved.