diff --git a/includes/actions.php b/includes/actions.php index eec9388d..04526427 100644 --- a/includes/actions.php +++ b/includes/actions.php @@ -409,6 +409,10 @@ function wpum_prevent_entire_site() { return; } + if ( wpum_is_rest_api_request() ) { + return; + } + if ( defined( 'WP_CLI' ) && WP_CLI ) { return; } diff --git a/includes/functions.php b/includes/functions.php index 528021f4..28e8b427 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -1383,3 +1383,18 @@ function wpum_strip_slashes( $content ) { return $content; } + +/** + * Returns true if the request is a REST API request. + * + * @return bool + */ +function wpum_is_rest_api_request() { + if ( empty( $_SERVER['REQUEST_URI'] ) ) { + return false; + } + + $rest_prefix = trailingslashit( rest_get_url_prefix() ); + + return ( false !== strpos( $_SERVER['REQUEST_URI'], $rest_prefix ) ); // phpcs:ignore +}