Contents
On this page

Preview Changes - Plugixa Advanced User Role Editor

POST /plugixa-aure/v1/changes/preview

Work out what a set of changes to roles and people would do, whether it would be allowed, and which dangerous grants need confirming. Nothing is saved. This is the first half of the preview-then-apply flow the Roles and People screens use.

Needs plugixa_aure_edit_roles or plugixa_aure_edit_users to get in. The body is then checked part by part: the roles part needs plugixa_aure_edit_roles, and the users part needs plugixa_aure_edit_users and the Users feature switched on.

Request

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

Request body

Content type: application/json

Field Type Required Description
roles object No Role slug to the role’s whole capability map: true grants, false blocks. A capability the role holds now and that is missing from the map is taken away.
users object No Account id to an object with roles (the whole list, in order) and/or capabilities (the account’s whole own map). A key you leave out keeps its current value.
versions object No role:<slug> or user:<id> to the version you read from List Roles or Get User. A mismatch means someone changed it since, and blocks the set.
acknowledged array No The key of each warning you confirm.

Inside the maps, values that are not real JSON booleans are dropped rather than read as a block. Roles and people that the body would not actually change are left out of the result. Administrator can only be changed while editing it is switched on in Settings.

{
  "roles": {
    "editor": {
      "read": true,
      "edit_posts": true,
      "publish_posts": true,
      "install_plugins": true
    }
  },
  "users": {
    "12": {
      "roles": [
        "author",
        "editor"
      ],
      "capabilities": {
        "switch_themes": true
      }
    }
  },
  "versions": {
    "role:editor": "3f9c2a71b0de",
    "user:12": "a41d07c95e22"
  },
  "acknowledged": []
}

Responses

200 OK. data is the plan.

{
  "success": true,
  "data": {
    "roles": [
      {
        "role": "editor",
        "name": "Editor",
        "people": 5,
        "granted": [
          "install_plugins"
        ],
        "revoked": [],
        "denied": [],
        "cleared": []
      }
    ],
    "users": [
      {
        "user": 12,
        "name": "Maria Lopez",
        "rolesAdded": [
          "editor"
        ],
        "rolesRemoved": [],
        "reordered": false,
        "granted": [
          "switch_themes"
        ],
        "revoked": [],
        "denied": [],
        "cleared": []
      }
    ],
    "totals": {
      "changes": 3,
      "people": 5
    },
    "warnings": [
      {
        "key": "role:editor:install_plugins",
        "cap": "install_plugins",
        "severity": "critical",
        "target": "Editor",
        "explain": "Can upload and install any plugin, including one that grants itself administrator access.",
        "confirm": true
      },
      {
        "key": "user:12:switch_themes",
        "cap": "switch_themes",
        "severity": "high",
        "target": "Maria Lopez",
        "explain": "Can change how the whole public site looks.",
        "confirm": false
      }
    ],
    "blockers": [],
    "allowed": true
  }
}
Field Type Meaning
data.roles[] array One row per role that would change: role, name, people and the four change lists
data.roles[].people integer|null How many people hold the role after the change. null when head counts are switched off
data.users[] array One row per account: user, name, rolesAdded, rolesRemoved, reordered and the four change lists for its own capabilities
granted, revoked, denied, cleared array Newly granted, taken away, newly blocked, no longer blocked
data.totals.changes integer Number of individual changes
data.totals.people integer|null How many people the whole set reaches. null when head counts are switched off
data.warnings[] array Risky grants: key, cap, severity, target, explain, confirm
data.blockers[] array Why apply would refuse: code, message, cap (empty when not about one capability)
data.allowed boolean true when there are no blockers

In this example the Editor role had four holders, and Maria, being given it, makes five.

A warning’s key has one of three forms: role:<slug>:<cap> (a role is granted a risky capability), user:<id>:<cap> (one account is), and user:<id>:role:<slug> (an account is given a role that holds a critical capability). Only critical grants need confirming; high ones come with confirm: false. With the confirmation setting switched off in Settings, every warning has confirm: false.

Problems with the body come back as blockers with a 200, not as errors. Their codes are listed on Apply Changes.

Errors

Plus the errors every endpoint can return.

Examples

curl -s -X POST "https://your-site.example/wp-json/plugixa-aure/v1/changes/preview" \
  -u "admin:$WP_APP_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{"roles":{"editor":{"read":true,"edit_posts":true,"publish_posts":true,"install_plugins":true}},"users":{"12":{"roles":["author","editor"],"capabilities":{"switch_themes":true}}},"versions":{"role:editor":"3f9c2a71b0de","user:12":"a41d07c95e22"},"acknowledged":[]}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-aure/v1/changes/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'        => [
            'editor' => [
                'read'            => true,
                'edit_posts'      => true,
                'publish_posts'   => true,
                'install_plugins' => true,
            ],
        ],
        'users'        => [
            '12' => [
                'roles'        => ['author', 'editor'],
                'capabilities' => [
                    'switch_themes' => true,
                ],
            ],
        ],
        'versions'     => [
            'role:editor' => '3f9c2a71b0de',
            'user:12'     => 'a41d07c95e22',
        ],
        'acknowledged' => [],
    ]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-site.example/wp-json/plugixa-aure/v1/changes/preview', {
  method: 'POST',
  headers: {
    'Authorization': 'Basic ' + btoa(`admin:${process.env.WP_APP_PASSWORD}`),
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ roles: { editor: { read: true, edit_posts: true, publish_posts: true, install_plugins: true } }, users: { '12': { roles: ['author', 'editor'], capabilities: { switch_themes: true } } }, versions: { 'role:editor': '3f9c2a71b0de', 'user:12': 'a41d07c95e22' }, acknowledged: [] }),
});
const { data } = await response.json();

Quick Links

Share