Contents
On this page

Preview User Roles - Plugixa Advanced User Role Editor

POST /plugixa-aure/v1/users/{id}/preview

Work out which capabilities an account would gain and lose with a new list of roles, and whether saving it would be allowed. Nothing is saved.

Needs the Edit people permission: plugixa_aure_edit_users. Part of the Users feature: when it is switched off in Settings the route is not registered and answers 404.

Note. An empty roles list is not reported as a blocker here, although saving it is refused with plugixa_aure_no_roles. gaining and losing compare roles only: capabilities set on the account itself are left out.

Request

POST https://your-site.example/wp-json/plugixa-aure/v1/users/12/preview

Path parameters

Name Type Description
id integer The account id

Request body

Content type: application/json

Field Type Required Description
roles array Yes The complete new list of role slugs, in order.
{
  "roles": [
    "author",
    "editor"
  ]
}

Responses

200 OK. data is the preview.

{
  "success": true,
  "data": {
    "user": 12,
    "roles": [
      "author",
      "editor"
    ],
    "gaining": [
      "edit_others_posts",
      "manage_categories",
      "moderate_comments"
    ],
    "losing": [],
    "warnings": [],
    "blockers": [],
    "allowed": true
  }
}
Field Type Meaning
data.user integer The account id
data.roles array The list as it would be saved
data.gaining array Capabilities the account would gain, sorted
data.losing array Capabilities it would lose, sorted
data.warnings array Gained capabilities rated critical or high: cap, severity, explain, confirm
data.blockers array Why saving would be refused: cap, code, message
data.allowed boolean true when there are no blockers

Errors

Status Code When
404 plugixa_aure_unknown_user No account with that id.

Plus the errors every endpoint can return.

Examples

curl -s -X POST "https://your-site.example/wp-json/plugixa-aure/v1/users/12/preview" \
  -u "admin:$WP_APP_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{"roles":["author","editor"]}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-aure/v1/users/12/preview');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_USERPWD        => 'admin:' . getenv('WP_APP_PASSWORD'),
    CURLOPT_HTTPHEADER     => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS     => json_encode([
        'roles' => ['author', 'editor'],
    ]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-site.example/wp-json/plugixa-aure/v1/users/12/preview', {
  method: 'POST',
  headers: {
    'Authorization': 'Basic ' + btoa(`admin:${process.env.WP_APP_PASSWORD}`),
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ roles: ['author', 'editor'] }),
});
const { data } = await response.json();

Quick Links

Share