dsmlf1207915 2018-06-14 13:09
浏览 63
已采纳

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

I've put some custom code in my active child theme's functions.php. I'm trying to enqueue some style on a admin page. However, a style enqueued in admin_enqueue_scripts hook gets automatically removed and after debugging I found that its not present in the very next hook i.e. admin_print_styles.

Here's some code in active child theme's functions.php which I used for debugging purposes:

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' );

I'm not deregistering the gforms_datepicker_css anywhere, but its getting removed maybe due to some plugin.
While debugging, I've gone further and inspected if it was deregistered by putting extra line in WordPress core class method WP_Dependencies::remove() located here as following.

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

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

But I'm unable to see log output with gforms_datepicker_css in it from this method.

I'm unsure why the style is getting removed from enqueue list. Can anybody please help me debugging this behaviour and find the solution?

  • 写回答

1条回答 默认 最新

  • duanlu7680 2018-06-15 04:06
    关注

    The scripts and styles were not loading on admin pages because the No-Conflict Mode setting of Gravity Forms plugin was turned ON. As the setting is designed to do so:

    enter image description here

    As described in Gravity Forms documentation:

    To temporarily resolve the issue, go to Forms > Settings and enable No Conflict mode. This should stop third party scripts from writing to Gravity Forms administration pages and allow you to do the things you need.

    The issue resolved after turning OFF the No-Conflict Mode.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名