取消排队、取消注册、删除操作-插件不起作用

时间:2016-03-29 作者:Jarod Thornton

几年前,我还没有掌握运行多站点网络的最佳实践,我经常使用网络激活插件。后来我意识到这是一个错误,因为并不是所有的网站都使用了一些插件。所以我在几个网站上有不必要的脚本和样式表。

我开始为那些不需要的插件资源做的是wp_dequeue_style( \'style-sheet\' );wp_deregister_style( \'style-sheet\' ); 在子主题函数中。php

我的问题是,它并不适用于所有插件。例如https://wordpress.org/plugins/advanced-recent-posts/ 没有遵循我的功能。我想也许我会尝试remove_action(); 但我不知道这到底是怎么回事。

以下是我在函数中使用的内容。php,它适用于其他样式表。

function remove_unwanted_stylesheets() {

wp_dequeue_style( \'wp-advanced-rp-css\' );
wp_deregister_style( \'wp-advanced-rp-css\' );

}
add_action( \'wp_enqueue_scripts\', \'remove_unwanted_stylesheets\', 999 );
插件排队和添加操作如下所示。

function add_advanced_recent_posts_widget_stylesheet() {

    $plugin_dir = \'advanced-recent-posts-widget\';

    if ( @file_exists( STYLESHEETPATH . \'/advanced-recent-posts-widget.css\' ) )

        $mycss_file = get_stylesheet_directory_uri() . \'/advanced-recent-posts-widget.css\';

    elseif ( @file_exists( TEMPLATEPATH . \'/advanced-recent-posts-widget.css\' ) )

        $mycss_file = get_template_directory_uri() . \'/advanced-recent-posts-widget.css\';

    else

        $mycss_file = plugins_url( \'css/advanced-recent-posts-widget.css\',dirname(__FILE__) );





        wp_register_style( \'wp-advanced-rp-css\', $mycss_file );

        wp_enqueue_style( \'wp-advanced-rp-css\' );



}

add_action(\'wp_print_styles\', \'add_advanced_recent_posts_widget_stylesheet\');
非常感谢您能深入了解我如何有效地退出和注销此插件的样式表。

2 个回复
最合适的回答,由SO网友:Jarod Thornton 整理而成

我只是简单地复制了插件源代码,然后更改了add_action();remove_action(); 在我的孩子主题函数中。php

add_action(\'wp_print_styles\', \'add_advanced_recent_posts_widget_stylesheet\');
更换add 具有remove.

remove_action(\'wp_print_styles\',\'add_advanced_recent_posts_widget_stylesheet\');
这么简单。现在我知道了。

SO网友:Rarst

你的问题是时机。如果你退房this answer for detailed order 你会看到的wp_print_styleswp_enqueue_scripts. 因此,在这种情况下,最早的出列时间是wp_print_styles 在11个优先级。

实际上,插件的作者在那一点上注册是非传统的。wp_enqueue_scripts 正是为了让其他人不会有这样的麻烦。

相关推荐

重置插件版本缓存|PRE_SET_SITE_TRANSPENT_UPDATE_PLUGINS

在我的插件中,我使用这些过滤器进行自动更新并检查许可证。add_filter( \'pre_set_site_transient_update_plugins\', array( &$this, \'check_for_update\' ) ); add_filter( \'plugins_api\', array( &$this, \'plugin_api_call\' ), 10, 3 ); 但正如我所看到的,WordPress在我的插件中更改了版本标签后,会调用该过