The WordPress REST API allows developers to build applications that interact with WordPress, accessing data and functionalities programmatically.
However, there are cases where site administrators may want to disable the REST API for security, performance, or privacy reasons.
Here’s the code snippet we’ll use to disable the REST API:
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(),
)
);
}
);