Contents
On this page
Preview Role Change - Plugixa Advanced User Role Editor
POST /plugixa-aure/v1/roles/{slug}/preview
Work out what saving a new capability map on one role would change, and whether it would be allowed. Nothing is saved.
Needs the Edit roles permission: plugixa_aure_edit_roles. It is a write permission because the answer tells you what you may grant.
Request
POST https://your-site.example/wp-json/plugixa-aure/v1/roles/editor/preview
Path parameters
| Name | Type | Description |
|---|---|---|
slug |
string |
The role to preview |
Request body
Content type: application/json
| Field | Type | Required | Description |
|---|---|---|---|
capabilities |
object |
Yes | The complete map you would save, as for Update Role. |
{
"capabilities": {
"read": true,
"edit_posts": true,
"publish_posts": true,
"install_plugins": true
}
}
Responses
200 OK. data is the preview.
{
"success": true,
"data": {
"role": "editor",
"change": {
"granted": [
"install_plugins"
],
"revoked": [
"moderate_comments"
],
"denied": [],
"cleared": []
},
"total": 2,
"users": 4,
"usersLabel": "This affects 4 people who hold this role.",
"warnings": [
{
"cap": "install_plugins",
"severity": "critical",
"explain": "Can upload and install any plugin, including one that grants itself administrator access.",
"confirm": true
}
],
"blockers": [],
"allowed": true
}
}
| Field | Type | Meaning |
|---|---|---|
data.change |
object |
granted, revoked, denied and cleared lists, as in Update Role |
data.total |
integer |
Number of capabilities that would change |
data.users |
integer|null |
People holding the role. null when head counts are switched off |
data.usersLabel |
string |
The same as a translated sentence |
data.warnings |
array |
Grants rated critical or high, each with cap, severity, explain and confirm |
data.blockers |
array |
Why saving would be refused, each with cap (empty for a lockout), code and message |
data.allowed |
boolean |
true when there are no blockers |
Errors
| Status | Code | When |
|---|---|---|
404 |
plugixa_aure_unknown_role |
The role does not exist. |
Plus the errors every endpoint can return.
Examples
curl -s -X POST "https://your-site.example/wp-json/plugixa-aure/v1/roles/editor/preview" \
-u "admin:$WP_APP_PASSWORD" \
-H "Content-Type: application/json" \
-d '{"capabilities":{"read":true,"edit_posts":true,"publish_posts":true,"install_plugins":true}}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-aure/v1/roles/editor/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([
'capabilities' => [
'read' => true,
'edit_posts' => true,
'publish_posts' => true,
'install_plugins' => true,
],
]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-site.example/wp-json/plugixa-aure/v1/roles/editor/preview', {
method: 'POST',
headers: {
'Authorization': 'Basic ' + btoa(`admin:${process.env.WP_APP_PASSWORD}`),
'Content-Type': 'application/json',
},
body: JSON.stringify({ capabilities: { read: true, edit_posts: true, publish_posts: true, install_plugins: true } }),
});
const { data } = await response.json();
Quick Links
Share