Search code examples
phpwordpressdebuggingwordpress-hook

Stylesheet is getting removed/deregistered automatically - 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?


Solution

  • 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.