Skip to content

Instantly share code, notes, and snippets.

@philipnewcomer
Created May 8, 2016 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipnewcomer/34639379ccdfe84183f128665685e052 to your computer and use it in GitHub Desktop.
Save philipnewcomer/34639379ccdfe84183f128665685e052 to your computer and use it in GitHub Desktop.
Allow WordPress REST API Requests While Restricted Site Access is Active
<?php
/**
* Plugin Name: Unrestrict REST API
* Plugin URI: https://philipnewcomer.net/2016/05/allow-rest-api-restricted-site-access/
* Description: Allows REST API requests while Restricted Site Access is enabled.
* Version: 0.1.0
* Author: Philip Newcomer
* Author URI: https://philipnewcomer.net
*/
/**
* Filter Restricted Site Access to allow REST API requests.
*
* @param bool $is_restricted Whether access is restricted.
* @param object $wp The WordPress object.
*
* @return bool Whether access should be restricted.
*/
function pn_unrestrict_rest_api( $is_restricted, $wp ) {
if ( ! empty( $wp->query_vars['rest_route'] ) ) {
return false;
}
return $is_restricted;
}
add_filter( 'restricted_site_access_is_restricted', 'pn_unrestrict_rest_api', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment