如何在Wordpress后端/编辑产品页面上禁用特定插件

如何在Wordpress后端/编辑产品页面上禁用特定插件,wordpress,woocommerce,Wordpress,Woocommerce,我试图找到一个解决方案,在Wordpress管理区禁用特定插件。问题是,对于建立WooCommerce商店,我使用Divi Builder,当您试图编辑它时,它在产品页面上有时会使用50mb的资源。。。如果我在那里禁用一些插件,那么加载时间会快得多。我在其他主题中找到了以下代码: add_filter( 'option_active_plugins', 'lg_disable_cart66_plugin' ); function lg_disable_cart66_plugin($plugin

我试图找到一个解决方案,在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\u active\u plugins”,我们需要将代码放到目录中。还请记住,这些插件是在初始化主查询之前运行的——这就是为什么我们无法访问许多功能,尤其是总是返回false的条件标记

请将下面的代码粘贴或下载到wp内容文件夹中的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;
}

好的,我刚用WordPress测试过,效果很好。如果可能的话,请在它崩溃后共享错误日志消息。你知道怎么做吗?当我使用它时,我再也无法访问我的仪表板了。我已经改进了解决方案,并创建了mu插件来满足您的需求。非常感谢!虽然它仍然不能正常工作:-S例如,我试图在编辑页面上取消查询监视器插件。它从顶部菜单栏消失了,但它仍然加载JS和CSS,这会减慢编辑页面的速度:我在这里使用Divi Builder,当所有插件都处于活动状态时,在编辑页面上它可以使用47MB的资源(在Chrome开发网络选项卡:)。这太疯狂了,所以我必须以某种方式限制它:(当我从插件页面手动禁用插件时,他们不会加载CSS和JS。)。。