On one of our clients websites, when you try to view the "plugins" page in the back-end, the page loads for several minutes, then returns a 404 (using the WordPress 404 template). This is a project that we inherited, and it's quite a mess; there are around 50 plugins installed, so I'm sure that's eating up a lot of resources.
The file /wp-admin/plugins.php
definitely exists, so we're very confused how this is returning a 404. It almost seems like it's running out of memory, but if that were the case, wouldn't it error with a 500 instead of 404?
What could be causing this, or what is the recommended method for trying to track this down?
EDIT:
I've installed Query Monitor and Rewrite Rules Inspector, here are my findings:
Query Monitor
The plugins page is using up a lot of memory at 40 MB (compared to ~7.3 on one of our more standard sites), but it's nowhere near its limit of 256 MB. Nothing in the data looks egregiously slow, but this issue is intermittent, so I have to wait for it to happen again to be able to test the actual issue.
Rewrite Rules Inspector
I see that there are two rules that match for /wp-admin/plugins.php
; one for "page" and one for "post." The more standard site that I tested on only includes the "page" rule. I've included the table below.
Rule | Rewrite | Source |
---|---|---|
(.?.+?)(?:/([0-9]+))?/?$ |
index.php?pagename=$matches[1]&page=$matches[2] |
page |
[^/]+/([^/]+)/?$ |
index.php?attachment=$matches[1] |
post |
I guess to test this, I could just disable the .htaccess
rules, so next time this issue crops up (likely tomorrow), I'll give that a try and report back.
Other Thoughts
This site uses a caching plugin that I'm not familiar with; W3 Total Cache. As this is another plugin that "rewrites" page contents, could it be that the caching plugin is trying to serve a cached version of /wp-admin/plugins.php
?
EDIT 2:
I believe I've tracked down the root of the problem: a plugin called GeoDirectory. It's including the rewrite rules which I previously mentioned. I tried to write a rewrite rule with a higher priority as a workaround, but that didn't seem to work.
/**
* Fix PHP files sometimes loading like WordPress pages
*/
function wpd_rewrite_rules(): void {
add_rewrite_rule("(.*\.php$)", '$matches[1]', "top");
}
add_action("init", "wpd_rewrite_rules", PHP_INT_MAX);
This redirect to something like pagename=wp-admin%2Fplugins.php
, which obviously isn't correct. Is there a way to write a workaround, or should I just try to get in contact with the developer of GeoDirectory to fix this?
wp-admin
folder or even serves WP. Note that it's not the number of plugins that makes a site slow, but rather it's doing a lot of things that makes a site slow. Naturally more plugins do more things but a single plugin or even no plugins and a heavy theme can add all that weight, just as well as a site can be fast with 100 plugins if those plugins are all tiny and lightweight