Documentation
Documentation
Graphic_Data_Custom_Roles
in package
Manages custom user roles and role-based access control for the Graphic Data Plugin.
Replaces the default WordPress roles (subscriber, contributor, author, editor) with two custom roles: Content Editor and Content Manager. Content Editors are restricted to managing only the scene, modal, and figure post types assigned to their instances. Content Managers have editor-level capabilities without sensitive administrative permissions.
Tags
Table of Contents
Methods
- add_instance_selection_fields() : void
- Renders the Instance Assignments checkbox fields on the user edit screen.
- create_custom_roles() : void
- Registers the Content Editor and Content Manager roles and removes default WordPress roles.
- filter_user_roles() : array<string|int, mixed>
- Filters the editable roles list to only include allowed custom roles.
- reorder_roles_js() : void
- Outputs inline JavaScript to reorder the role dropdown on user edit screens.
- restrict_content_editor_admin_menu() : void
- Removes admin menu pages that Content Editors should not access.
- restrict_editing() : void
- Restricts access to individual post edit screens for Content Editors.
- restrict_listing() : void
- Filters admin list queries to show only posts belonging to a Content Editor's assigned instances.
- restrict_new_post_from_admin_bar() : void
- Removes "New" content links from the admin bar for non-admin users.
- save_instance_selections() : bool|void
- Saves the assigned instance selections when a user profile is saved.
Methods
add_instance_selection_fields()
Renders the Instance Assignments checkbox fields on the user edit screen.
public
add_instance_selection_fields(WP_User $user) : void
Displays a list of all published instance posts as checkboxes, allowing administrators to assign specific instances to a user. The section is only visible to administrators and is toggled via inline JavaScript to show only when the selected user role is 'content_editor'.
Parameters
- $user : WP_User
-
The user object being edited.
Tags
create_custom_roles()
Registers the Content Editor and Content Manager roles and removes default WordPress roles.
public
create_custom_roles() : void
Content Editor inherits the built-in editor capabilities, but is restricted to only allowed Instances. Content Manager also inherits editor capabilities but explicitly excludes sensitive administrative capabilities such as plugin/theme management and core updates. After creating the custom roles, the default subscriber, contributor, author, and editor roles are removed.
Tags
filter_user_roles()
Filters the editable roles list to only include allowed custom roles.
public
filter_user_roles(array<string|int, mixed> $roles) : array<string|int, mixed>
Removes any role not in the allowed set (content_editor, content_manager, administrator) from the roles array. Intended for use with the 'editable_roles' filter.
Parameters
- $roles : array<string|int, mixed>
-
Associative array of role slugs to role details.
Tags
Return values
array<string|int, mixed> —Filtered associative array containing only allowed roles.
reorder_roles_js()
Outputs inline JavaScript to reorder the role dropdown on user edit screens.
public
reorder_roles_js() : void
Sorts the role <select> options so they appear in the order: Administrator,
Content Manager, Content Editor. Runs on page load and after AJAX requests
to handle dynamically loaded forms.
Tags
restrict_content_editor_admin_menu()
Removes admin menu pages that Content Editors should not access.
public
restrict_content_editor_admin_menu() : void
Hides Posts, Pages, About, Instance, and Manage Instance Types menu items from users with the 'content_editor' role.
Tags
restrict_editing()
Restricts access to individual post edit screens for Content Editors.
public
restrict_editing() : void
On post.php for scene, modal, and figure post types, verifies that the
Content Editor's assigned instances include the instance associated with the
post being edited. If the user has no assigned instances or the post belongs
to an unassigned instance, the user is redirected to the post type's list screen.
Administrators and non-Content-Editor roles are not affected.
Tags
restrict_listing()
Filters admin list queries to show only posts belonging to a Content Editor's assigned instances.
public
restrict_listing(WP_Query $query) : void
Applies a meta query on the main admin listing query for scene, modal, and figure post types. Content Editors will only see posts whose location meta field matches one of their assigned instances. If no instances are assigned, no posts are shown.
Parameters
- $query : WP_Query
-
The current WordPress query object.
Tags
restrict_new_post_from_admin_bar()
Removes "New" content links from the admin bar for non-admin users.
public
restrict_new_post_from_admin_bar(WP_Admin_Bar $wp_admin_bar) : void
Strips the new-post, new-page, new-about, and new-instance nodes from the admin bar for any user who lacks the 'manage_options' capability.
Parameters
- $wp_admin_bar : WP_Admin_Bar
-
The WordPress admin bar instance.
Tags
save_instance_selections()
Saves the assigned instance selections when a user profile is saved.
public
save_instance_selections(int $user_id) : bool|void
Sanitizes the submitted instance IDs with absint and stores them as the
'assigned_instances' user meta. Only processes the save if the current user
has permission to edit the target user and the target user has the
'content_editor' role.
Parameters
- $user_id : int
-
The ID of the user being saved.
Tags
Return values
bool|void —False if the current user lacks edit permissions, void otherwise.