Skip to content

Commit

Permalink
Merge pull request #371 from WPUserManager/#359-Prevent-site-access-t…
Browse files Browse the repository at this point in the history
…o-visitors-setting-should-not-prevent-the-WP-REST-API-from-working

#359 Prevent site access to visitors setting should not prevent the WP REST API from working
  • Loading branch information
wp-user-manager authored Nov 18, 2023
2 parents 38d32d1 + d95d1b6 commit daee2e1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions includes/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ function wpum_prevent_entire_site() {
return;
}

if ( wpum_is_rest_api_request() ) {
return;
}

if ( defined( 'WP_CLI' ) && WP_CLI ) {
return;
}
Expand Down
15 changes: 15 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit daee2e1

Please sign in to comment.