Skip to content

Instantly share code, notes, and snippets.

@bobbydank
Last active October 13, 2023 16:24
Show Gist options
  • Save bobbydank/f896ddc4caef76d87181940a7db8ab38 to your computer and use it in GitHub Desktop.
Save bobbydank/f896ddc4caef76d87181940a7db8ab38 to your computer and use it in GitHub Desktop.
disables wordpress rest api
<?php
add_filter(
'rest_authentication_errors',
function ($access) {
return new WP_Error(
'rest_disabled',
__("The Wordpress REST API has been disabled."),
array(
'status' => rest_authorization_required_code(),
)
);
}
);
// if you need rest api for Elmentor or other logged in processes:
if (!is_user_logged_in()) {
add_filter(
'rest_authentication_errors',
function ($access) {
return new WP_Error(
'rest_disabled',
__("The Wordpress REST API has been disabled."),
array(
'status' => rest_authorization_required_code(),
)
);
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment