Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions app/Core/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,38 @@ public function setLoginLogo(): string

return '';
}

/**
* @filter rest_authentication_errors
*/
public function disableDefaultEndpoints(\WP_Error|bool|null $access): \WP_Error|bool|null
{
$endpointsToRemove = [
'/wp/v2/users',
];

if (! is_user_logged_in()) {
$currentEndpoint = $GLOBALS['wp']->query_vars['rest_route'] ?: '';

foreach ($endpointsToRemove as $toRemove) {
if (false !== stripos($currentEndpoint, $toRemove)) {
if (is_wp_error($access)) {
$access->add(
'rest_forbidden',
__('Sorry, you are not allowed to do that.', 'firestarter'),
['status' => rest_authorization_required_code()]
);
} else {
return new \WP_Error(
'rest_forbidden',
__('Sorry, you are not allowed to do that.', 'firestarter'),
['status' => rest_authorization_required_code()]
);
}
}
}
}

return $access;
}
}