样式表自动获取 removed/deregistered - WordPress
Stylesheet is getting removed/deregistered automatically - WordPress
我在活跃的子主题 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
,但它被删除可能是由于某些插件。
在调试时,我进一步检查了它是否通过在位于 here 的 WordPress 核心 class 方法 WP_Dependencies::remove()
中添加额外的行来取消注册,如下所示。
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
的日志输出。
我不确定为什么样式会从排队列表中删除。任何人都可以帮我调试此行为并找到解决方案吗?
脚本和样式未在管理页面上加载,因为 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.
关闭无冲突模式后问题得到解决。
我在活跃的子主题 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
,但它被删除可能是由于某些插件。
在调试时,我进一步检查了它是否通过在位于 here 的 WordPress 核心 class 方法 WP_Dependencies::remove()
中添加额外的行来取消注册,如下所示。
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
的日志输出。
我不确定为什么样式会从排队列表中删除。任何人都可以帮我调试此行为并找到解决方案吗?
脚本和样式未在管理页面上加载,因为 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.
关闭无冲突模式后问题得到解决。