Recall & Review
beginner
What is a permission callback in WordPress REST API?
A permission callback is a function that checks if the current user has the right to access or modify a REST API endpoint. It returns true if allowed, false otherwise.
Click to reveal answer
beginner
Why do we use permission callbacks when registering REST API routes?
Permission callbacks protect REST API routes by ensuring only authorized users can access or change data, helping keep the site secure.
Click to reveal answer
intermediate
How do you define a permission callback when registering a REST route in WordPress?
You add a 'permission_callback' key in the route arguments, assigning it a function that returns true or false based on user capabilities.
Click to reveal answer
beginner
What happens if a permission callback returns false?
The REST API request is denied with a 403 Forbidden error, preventing unauthorized access.
Click to reveal answer
intermediate
Give an example of a simple permission callback function in WordPress.
function my_permission_callback() { return current_user_can('edit_posts'); } This allows only users who can edit posts to access the route.Click to reveal answer
What does a permission callback function return to allow access?
✗ Incorrect
Permission callbacks must return true to allow access to the REST API endpoint.
Where do you specify the permission callback when registering a REST route?
✗ Incorrect
The 'permission_callback' argument is used to define the function that checks user permissions.
What HTTP status code is returned if permission callback denies access?
✗ Incorrect
A 403 Forbidden status code indicates the user is not allowed to access the resource.
Which WordPress function is commonly used inside permission callbacks to check capabilities?
✗ Incorrect
current_user_can() checks if the current user has a specific capability.
If no permission callback is set, what is the default behavior for REST API routes?
✗ Incorrect
By default, REST API routes are public unless a permission callback restricts access.
Explain what a permission callback is and why it is important in WordPress REST API.
Think about who can use your API and how you check that.
You got /3 concepts.
Describe how to add a permission callback when registering a REST API route in WordPress.
Focus on the arguments passed to register_rest_route.
You got /3 concepts.