Created
May 8, 2016 12:04
-
-
Save philipnewcomer/34639379ccdfe84183f128665685e052 to your computer and use it in GitHub Desktop.
Allow WordPress REST API Requests While Restricted Site Access is Active
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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