Wordpress-忽略或暂时禁用菜单保存上的插件

凯文

我有一个菜单很大的网站。请理解,菜单大小必须满足客户的要求,因此不能,不能以其他任何方式完成。

该站点通过Cloudflare运行,因此我们安装了Cloudflare插件,以便在更新发生时清除缓存。

我发现,将菜单保存在admin中会导致502错误,因为保存脚本超时。我们发现,罪魁祸首是执行清除请求的Curl请求的Cloudflare插件,由于菜单的大小,很多次。

我想做的是在保存菜单时禁用该插件,因此我已经创建了一个“ Must Use”插件,并使用以下代码来完成此操作……但是,它似乎无法正常工作,并且插件的清除Curl进程仍在起作用开火。

注意: php输入最大值,脚本超时,内存限制都得到了极大提高:分别为5000、5Minutes,1024M。Cloudflare有一个严格的超时期限,因此实际上在脚本执行之前就超时了……我知道会发生什么的唯一原因是因为它已经过测试并记录在登台区域中。

<?php
/*
Plugin Name: Disable Plugins in Admin pages
Plugin URI: http://www.example.com
Description: Disable plugins in wordpress admin pages
Author: Kevin Pirnie
Version: 0.0.1
*/

// wait until the plugins are active
add_filter( 'option_active_plugins', function( $_opt, $_opt_name ) {

    // plugins to remove
    $_to_remove = array(
        'cloudflare/cloudflare.php',
    );

    // hold our new options
    $_new_opts = $_opt;

    // remove the plugin from the array
    foreach ( $_opt as $_k => $_v ) {
        if ( in_array( $_v, $_to_remove ) ) {
            unset( $_new_opts[$_k] );
        }
    }

    // we only need to do this on these pages
    if( $_SERVER['PHP_SELF'] == '/wp-admin/nav-menus.php' ) {
        $_opt = $_new_opts;
    }

    // return the array
    return $_opt;

}, 999, 2 );

如何解决此问题,以便菜单保存后插件不运行?

卢卡斯·安德烈斯·托雷斯(Lucas Andres Torres)

我现在无法真正测试,因为我现在没有Cloudflare背后的网站,但是可以尝试一下:

<?php

// Use the filter provided by Clodflare's plugin and return an empty array for the urls
// check wp-content/plugins/cloudflare/src/WordPress/Hooks.php line 155 to see what happens behind this
add_filter('cloudflare_purge_by_url', function($urls, $postId) {
    global $pagenow;

    //Act only if the current screen is the Admin Menu
    if ("nav-menus.php" === $pagenow) {
        $urls = [];
    }

    return $urls;
});

Cloudflare的插件提供了该过滤器,用于在清除缓存之前修改url的数组。

祝好运!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章