Documentation
Documentation
Graphic_Data_Custom_Capabilities
in package
Manages custom user capabilities for the Graphic Data Plugin.
Tags
Table of Contents
Methods
- add_admin_editor_custom_post_type_caps() : void
- Grants administrator and editor roles full access to the scene, modal, and figure post types.
- add_author_custom_post_type_caps() : void
- Grants author-role users full create, edit, and delete access to selected scene, modal, and figure post types.
- add_instance_selection_fields() : void
- Renders the Instance Assignments checkbox fields on the user edit screen.
- restrict_author_admin_menu() : void
- Removes admin menu pages that authors should not access.
- restrict_editing() : void
- Restricts access to individual post edit screens for authors.
- restrict_listing() : void
- Filters admin list queries to show only posts belonging to an author's assigned instances.
- restrict_new_post_from_admin_bar() : void
- Removes "New" post, page, about, and instance 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_admin_editor_custom_post_type_caps()
Grants administrator and editor roles full access to the scene, modal, and figure post types.
public
add_admin_editor_custom_post_type_caps() : void
Because these post types use a custom capability_type ('scene', 'modal', 'figure') with map_meta_cap enabled, WordPress generates primitive capabilities (e.g. edit_scenes, publish_scenes) that are not present in any default role. This method explicitly adds those primitives to administrator and editor so they can list, create, edit, publish, and delete these posts in the admin.
Tags
add_author_custom_post_type_caps()
Grants author-role users full create, edit, and delete access to selected scene, modal, and figure post types.
public
add_author_custom_post_type_caps() : void
Iterates over the three custom post types and calls add_cap() for every primitive capability WordPress maps to those types, covering own posts, others' posts, published posts, and private posts.
Tags
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 'author'.
Parameters
- $user : WP_User
-
The user object being edited.
Tags
restrict_author_admin_menu()
Removes admin menu pages that authors should not access.
public
restrict_author_admin_menu() : void
Hides Posts, Pages, About, Instance, and Manage Instance Types menu items from users with the 'author' role.
Tags
restrict_editing()
Restricts access to individual post edit screens for authors.
public
restrict_editing() : void
On post.php for scene, modal, and figure post types, verifies that the
Author'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 an author'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. Authors 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" post, page, about, and instance 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
'author' 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.