Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

403 "rest_forbidden" error in WordPress REST API (but only for settings)?

i got all API from WordPress except settings (/wp/v2/settings). its returning rest_forbidden error

{
  "code": "rest_forbidden",
  "message": "Sorry, you are not allowed to do that.",
  "data": {
    "status": 403
  }
}
like image 228
Shana Raj Avatar asked Aug 29 '17 05:08

Shana Raj


People also ask

How do I enable REST API in WordPress?

Download the WordPress REST API Basic Auth plugin. Log in to your WordPress Dashboard and go to Plugins -> Add New. Click on the Upload Plugin button and select the plugin's zip file. Go to the Installed Plugins menu and activate the plugin from there.


1 Answers

Your user does not have the correct permissions to access the data at that route. Out of the box the /settings/ route requires the manage_options permission (see the get_item_permissions_check method).

// found in WP Core class-wp-rest-settings-controller.php
/**
 * Checks if a given request has access to read and manage settings.
 *
 * @since 4.7.0
 *
 * @param WP_REST_Request $request Full details about the request.
 * @return bool True if the request has read access for the item, otherwise false.
 */
public function get_item_permissions_check( $request ) {
  return current_user_can( 'manage_options' );
}
like image 100
mikerojas Avatar answered Sep 22 '22 07:09

mikerojas