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
20 changes: 18 additions & 2 deletions core/REST_API/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,27 @@ public function get_vendor() {
}

/**
* Allow access to an endpoint
* Allow access to an endpoint.
*
* @return bool
* Requires the user to be logged in by default. Use the
* `carbon_fields_rest_api_allow_public_access` filter to allow
* unauthenticated access for intentionally public endpoints.
*
* @return bool|\WP_Error
*/
public function allow_access() {
if ( apply_filters( 'carbon_fields_rest_api_allow_public_access', false ) ) {
return true;
}

if ( ! is_user_logged_in() ) {
return new \WP_Error(
'rest_forbidden',
__( 'You must be logged in to access Carbon Fields data.', 'carbon-fields' ),
array( 'status' => rest_authorization_required_code() )
);
}

return true;
}

Expand Down