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.

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

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵