REST API fails to load when site is on a subfolder
-
I ran into what’s probably an uncommon situation that caused Media Cleaner to fail to function. Essentially it wouldn’t register the REST API endpoints because it couldn’t detect that my website was running a REST request. There are two unique aspects of my site that may be at fault:
* It’s WP site_url is a subfolder
* The website itself is actually a subdomain but using a reverse proxy to appear as a subfolder (this may not be relevant)
Throwing a bunch of Query Monitor logs at the problem, I finally determined the issue is because of these lines 116-117 incommon/helpers.php
– with my setup, the values of the variables are$rest_url
=/subfolder/wp-json
$current_url
=/wp-json
Which then causes theif
condition on line 123-124 to fail.
Since I only needed to use Media Cleaner once, I was able to work around the problem by throwing this in an mu-plugins file:if ( ! defined( 'REST_REQUEST' ) && strpos( $_SERVER['REQUEST_URI'], 'wp-json' ) !== false ) { define( 'REST_REQUEST', true ); }
And that got the job done. I can’t suggest a practical solution to fix the plugin permanently, and maybe my installation is too much of an edge case to worry about, but I thought you might want to be aware one more potential reason for the REST API failure.
Many thanks for a great plugin
ありがとうございます
- The topic ‘REST API fails to load when site is on a subfolder’ is closed to new replies.