我在活动子主题的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
任何地方取消注册,但它可能由于某些插件而被删除。
在调试时,我进一步检查了它是否被取消注册,方法是在WP_Dependencies::remove()
位于此处的 WordPress 核心类方法中添加额外的行,如下所示。
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
通过这种方法看到其中的日志输出。
我不确定为什么样式会从入队列表中删除。有人可以帮我调试这种行为并找到解决方案吗?