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 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大