Skip to content

Commit

Permalink
Allow access to gds/facetwp rest api endpoints out of the box
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyc committed Jul 17, 2023
1 parent d369864 commit 5fb1001
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions web/app/mu-plugins/disable-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
remove_action('xmlrpc_rsd_apis', 'rest_output_rsd');

add_filter('rest_authentication_errors', function ($access) {
// @see https://github.com/WordPress/wordpress-develop/blob/b316c8b25fc71920d89ee37ee26609a77b2a305a/src/wp-includes/rest-api.php#L390
$route = untrailingslashit($GLOBALS['wp']->query_vars['rest_route']) ?: '/';

// Allow logged out users access to the following endpoints, prevent access
// to others.
if (preg_match('@^/(facetwp|gds)/@', $route)) {
return $access;
}

if (!is_user_logged_in()) {
$message = apply_filters('disable_wp_rest_api_error', __('REST API restricted to authenticated users.', 'disable-wp-rest-api'));
return new WP_Error('rest_login_required', $message, array('status' => rest_authorization_required_code()));
Expand Down

0 comments on commit 5fb1001

Please sign in to comment.