我尝试找到一个解决方案来禁用 WordPress 管理区域中的特定插件。问题是,为了构建 WooCommerce 商店,我使用 Divi Builder,当您尝试编辑它时,它在产品页面上有时会使用 50mb 的资源...如果我在那里禁用一些插件,那么加载时间会快得多。我在其他主题上找到了以下代码:
add_filter( 'option_active_plugins', 'lg_disable_cart66_plugin' );
function lg_disable_cart66_plugin($plugins){
if(strpos($_SERVER['REQUEST_URI'], '/store/') === FALSE AND strpos($_SERVER['REQUEST_URI'], '/wp-admin/') === FALSE) {
$key = array_search( 'cart66/cart66.php' , $plugins );
if ( false !== $key ) unset( $plugins[$key] );
}
return $plugins;
}
但不知道如何修改它,所以它只是禁用后端所选的插件。换句话说:我不希望在编辑 WooCommerce 产品页面时加载插件。
我们将非常感谢一些帮助。
由于“option_active_plugins”在加载任何插件之前被触发,我们需要将代码放入 mu-plugins 目录中。还请记住,这些插件是在主查询初始化之前运行的 - 这就是为什么我们无法访问许多功能,尤其是始终返回 false 的条件标签。
请粘贴以下代码或将 gist 下载到 wp-content 文件夹中的 mu-plugins 文件夹中。它只会禁用帖子和页面区域中的插件。
<?php
/*
Plugin Name: Disable Plugin for URl
Plugin URI: https://www.glowlogix.com
Description: Disable plugins for for specific backend pages.
Author: Muhammad Usama M.
Version: 1.0.0
*/
add_filter( 'option_active_plugins', 'disable_plugins_per_page' );
function disable_plugins_per_page( $plugin_list ) {
// Quit immediately if not post edit area.
global $pagenow;
if (( $pagenow == 'post.php' || $pagenow == 'edit.php' )) {
$disable_plugins = array (
// Plugin Name
'hello.php',
'developer/developer.php'
);
$plugins_to_disable = array();
foreach ( $plugin_list as $plugin ) {
if ( true == in_array( $plugin, $disable_plugins ) ) {
//error_log( "Found $plugin in list of active plugins." );
$plugins_to_disable[] = $plugin;
}
}
// If there are plugins to disable then remove them from the list,
// otherwise return the original list.
if ( count( $plugins_to_disable ) ) {
$new_list = array_diff( $plugin_list, $plugins_to_disable );
return $new_list;
}
}
return $plugin_list;
}
您可以将 $disable_plugins 替换为要禁用的所需插件列表。