Shortcode
4 months ago
AccessDeniedRedirect.php
1 year ago
AdminToolbar.php
1 year ago
ApiRoute.php
1 year ago
BackendMenu.php
1 year ago
BaseTrait.php
1 year ago
Capability.php
1 year ago
Content.php
4 months ago
Core.php
8 months ago
Hooks.php
1 year ago
Identity.php
1 month ago
Jwt.php
1 month ago
LoginRedirect.php
1 year ago
LogoutRedirect.php
1 month ago
Metaboxes.php
1 year ago
NotFoundRedirect.php
1 year ago
Policies.php
1 year ago
SecureLogin.php
1 year ago
SecurityAudit.php
1 year ago
Shortcodes.php
4 months ago
Urls.php
1 year ago
Welcome.php
1 year ago
Widgets.php
1 year ago
Capability.php
192 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * ====================================================================== |
| 5 | * LICENSE: This file is subject to the terms and conditions defined in * |
| 6 | * file 'license.txt', which is part of this source code package. * |
| 7 | * ====================================================================== |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * Capability service |
| 12 | * |
| 13 | * @package AAM |
| 14 | * @version 7.0.0 |
| 15 | */ |
| 16 | class AAM_Service_Capability |
| 17 | { |
| 18 | use AAM_Service_BaseTrait; |
| 19 | |
| 20 | /** |
| 21 | * Default configurations |
| 22 | * |
| 23 | * @version 7.0.0 |
| 24 | */ |
| 25 | const DEFAULT_CONFIG = [ |
| 26 | 'service.capability.edit_caps' => true |
| 27 | ]; |
| 28 | |
| 29 | /** |
| 30 | * List of capabilities with their descriptions |
| 31 | * |
| 32 | * @var array |
| 33 | * @access private |
| 34 | * |
| 35 | * @version 7.0.0 |
| 36 | */ |
| 37 | private $_capabilities = []; |
| 38 | |
| 39 | /** |
| 40 | * Constructor |
| 41 | * |
| 42 | * @return void |
| 43 | * @access protected |
| 44 | * |
| 45 | * @version 7.0.4 |
| 46 | */ |
| 47 | protected function __construct() |
| 48 | { |
| 49 | add_filter('aam_get_config_filter', function($result, $key) { |
| 50 | if (empty($result) && array_key_exists($key, self::DEFAULT_CONFIG)) { |
| 51 | $result = self::DEFAULT_CONFIG[$key]; |
| 52 | } |
| 53 | |
| 54 | return $result; |
| 55 | }, 10, 2); |
| 56 | |
| 57 | // Register RESTful API endpoints |
| 58 | AAM_Restful_Capability::bootstrap(); |
| 59 | |
| 60 | add_action('init', function() { |
| 61 | $this->initialize_hooks(); |
| 62 | }, PHP_INT_MAX); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Initialize service hooks |
| 67 | * |
| 68 | * @return void |
| 69 | * @access protected |
| 70 | * |
| 71 | * @version 7.0.4 |
| 72 | */ |
| 73 | protected function initialize_hooks() |
| 74 | { |
| 75 | if (is_admin()) { |
| 76 | // Hook that initialize the AAM UI part of the service |
| 77 | add_action('aam_initialize_ui_action', function () { |
| 78 | AAM_Backend_Feature_Main_Capability::register(); |
| 79 | }); |
| 80 | } |
| 81 | |
| 82 | // Capability descriptions hooks |
| 83 | add_filter( |
| 84 | 'aam_capability_description_filter', |
| 85 | [ $this, 'get_cap_description' ], |
| 86 | 10, |
| 87 | 2 |
| 88 | ); |
| 89 | |
| 90 | // Initialize the list of capabilities with descriptions |
| 91 | $this->_capabilities = [ |
| 92 | 'switch_themes' => __('Allows a user to change the active theme of a website, altering its overall design and layout.', 'advanced-access-manager'), |
| 93 | 'edit_themes' => __('Enables a user to directly modify the code of theme files, allowing for customization and adjustments to the website\'s appearance and functionality.', 'advanced-access-manager'), |
| 94 | 'edit_theme_options' => __('Permits a user to access and modify theme settings through the WordPress Customizer, enabling personalized adjustments to the site\'s appearance and functionality without altering code.', 'advanced-access-manager'), |
| 95 | 'install_themes' => __('Allows a user to add new themes to a website from the WordPress Theme Directory or by uploading theme files directly.', 'advanced-access-manager'), |
| 96 | 'activate_plugins' => __('Enables a user to activate or deactivate plugins, thereby controlling the addition or removal of specific functionalities on the website.', 'advanced-access-manager'), |
| 97 | 'edit_plugins' => __('Allows a user to directly modify the code of installed plugin files, enabling custom changes and enhancements to the site\'s functionality.', 'advanced-access-manager'), |
| 98 | 'install_plugins' => __('Allows a user to add new plugins to a website, expanding its functionality by integrating additional features and tools.', 'advanced-access-manager'), |
| 99 | 'edit_users' => __('Allows a user to modify the profiles and settings of existing users, including their roles, personal information, and permissions.', 'advanced-access-manager'), |
| 100 | 'edit_files' => __('Allows a user to edit files in the theme or plugin editor', 'advanced-access-manager'), |
| 101 | 'manage_options' => __('Allows a user to manage all site options and settings', 'advanced-access-manager'), |
| 102 | 'moderate_comments' => __('Allows a user to moderate comments and manage their status', 'advanced-access-manager'), |
| 103 | 'manage_categories' => __('Allows a user to manage and edit categories for posts', 'advanced-access-manager'), |
| 104 | 'manage_links' => __('Allows a user to manage and edit links in the blogroll', 'advanced-access-manager'), |
| 105 | 'upload_files' => __('Allows a user to upload files to the media library', 'advanced-access-manager'), |
| 106 | 'import' => __('Allows a user to import content from external sources', 'advanced-access-manager'), |
| 107 | 'unfiltered_html' => __('Allows a user to post unfiltered HTML content', 'advanced-access-manager'), |
| 108 | 'edit_posts' => __('Allows a user to edit posts created by the user', 'advanced-access-manager'), |
| 109 | 'edit_others_posts' => __('Allows a user to edit posts created by other users', 'advanced-access-manager'), |
| 110 | 'edit_published_posts' => __('Allows a user to edit posts that are already published', 'advanced-access-manager'), |
| 111 | 'publish_posts' => __('Allows a user to publish new posts', 'advanced-access-manager'), |
| 112 | 'edit_pages' => __('Allows a user to edit pages on the site', 'advanced-access-manager'), |
| 113 | 'read' => __('Allows a user to read and view site content', 'advanced-access-manager'), |
| 114 | 'publish_pages' => __('Publish pages on the site', 'advanced-access-manager'), |
| 115 | 'edit_others_pages' => __('Edit pages created by other users', 'advanced-access-manager'), |
| 116 | 'edit_published_pages' => __('Edit pages that are already published', 'advanced-access-manager'), |
| 117 | 'delete_pages' => __('Delete pages', 'advanced-access-manager'), |
| 118 | 'delete_others_pages' => __('Delete pages created by other users', 'advanced-access-manager'), |
| 119 | 'delete_published_pages' => __('Delete pages that are already published', 'advanced-access-manager'), |
| 120 | 'delete_posts' => __('Delete posts', 'advanced-access-manager'), |
| 121 | 'delete_others_posts' => __('Delete posts created by other users', 'advanced-access-manager'), |
| 122 | 'delete_published_posts' => __('Delete posts that are already published', 'advanced-access-manager'), |
| 123 | 'delete_private_posts' => __('Delete private posts', 'advanced-access-manager'), |
| 124 | 'edit_private_posts' => __('Edit private posts', 'advanced-access-manager'), |
| 125 | 'read_private_posts' => __('Read private posts', 'advanced-access-manager'), |
| 126 | 'delete_private_pages' => __('Delete private pages', 'advanced-access-manager'), |
| 127 | 'edit_private_pages' => __('Edit private pages', 'advanced-access-manager'), |
| 128 | 'read_private_pages' => __('Read private pages', 'advanced-access-manager'), |
| 129 | 'delete_users' => __('Delete users', 'advanced-access-manager'), |
| 130 | 'create_users' => __('Create new users', 'advanced-access-manager'), |
| 131 | 'unfiltered_upload' => __('Upload files without filtering', 'advanced-access-manager'), |
| 132 | 'edit_dashboard' => __('Access and edit the dashboard', 'advanced-access-manager'), |
| 133 | 'customize' => __('Customize site appearance and options', 'advanced-access-manager'), |
| 134 | 'delete_site' => __('Delete the entire site', 'advanced-access-manager'), |
| 135 | 'update_plugins' => __('Update installed plugins', 'advanced-access-manager'), |
| 136 | 'delete_plugins' => __('Delete installed plugins', 'advanced-access-manager'), |
| 137 | 'update_themes' => __('Update installed themes', 'advanced-access-manager'), |
| 138 | 'update_core' => __('Update WordPress core', 'advanced-access-manager'), |
| 139 | 'list_users' => __('View list of all users', 'advanced-access-manager'), |
| 140 | 'remove_users' => __('Remove users from the site', 'advanced-access-manager'), |
| 141 | 'add_users' => __('Add new users to the site', 'advanced-access-manager'), |
| 142 | 'promote_users' => __('Promote users to higher roles', 'advanced-access-manager'), |
| 143 | 'delete_themes' => __('Delete installed themes', 'advanced-access-manager'), |
| 144 | 'export' => __('Export data from the site', 'advanced-access-manager'), |
| 145 | 'edit_comment' => __('Edit comments left on the site', 'advanced-access-manager'), |
| 146 | 'create_sites' => __('Create new sites in a multisite network', 'advanced-access-manager'), |
| 147 | 'delete_sites' => __('Delete sites in a multisite network', 'advanced-access-manager'), |
| 148 | 'manage_network' => __('Manage the entire network of sites', 'advanced-access-manager'), |
| 149 | 'manage_sites' => __('Manage individual sites in a multisite network', 'advanced-access-manager'), |
| 150 | 'manage_network_users' => __('Manage users across the entire network', 'advanced-access-manager'), |
| 151 | 'manage_network_themes' => __('Manage themes across the entire network', 'advanced-access-manager'), |
| 152 | 'manage_network_options' => __('Manage network-wide options and settings', 'advanced-access-manager'), |
| 153 | 'manage_network_plugins' => __('Manage plugins across the entire network', 'advanced-access-manager'), |
| 154 | 'upload_plugins' => __('Upload plugins to the site', 'advanced-access-manager'), |
| 155 | 'upload_themes' => __('Upload themes to the site', 'advanced-access-manager'), |
| 156 | 'upgrade_network' => __('Upgrade the entire network of sites', 'advanced-access-manager'), |
| 157 | 'setup_network' => __('Set up and configure a multisite network', 'advanced-access-manager'), |
| 158 | 'level_0' => __('Read only user level. Typically the Subscriber role.', 'advanced-access-manager'), |
| 159 | 'level_1' => __('Limited access level. Typically the Contributor role.', 'advanced-access-manager'), |
| 160 | 'level_2' => __('Author role access level', 'advanced-access-manager'), |
| 161 | 'level_3' => __('No specific meaning.', 'advanced-access-manager'), |
| 162 | 'level_4' => __('No specific meaning.', 'advanced-access-manager'), |
| 163 | 'level_5' => __('No specific meaning.', 'advanced-access-manager'), |
| 164 | 'level_6' => __('No specific meaning.', 'advanced-access-manager'), |
| 165 | 'level_7' => __('Editor access level.', 'advanced-access-manager'), |
| 166 | 'level_8' => __('No specific meaning.', 'advanced-access-manager'), |
| 167 | 'level_9' => __('No specific meaning.', 'advanced-access-manager'), |
| 168 | 'level_10' => __('The highest level capabilities. Typically the Administrator role.', 'advanced-access-manager') |
| 169 | ]; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Get capability description |
| 174 | * |
| 175 | * @param string $description |
| 176 | * @param string $slug |
| 177 | * |
| 178 | * @return string |
| 179 | * @access public |
| 180 | * |
| 181 | * @version 7.0.0 |
| 182 | */ |
| 183 | public function get_cap_description($description, $slug) |
| 184 | { |
| 185 | if (empty($description) && isset($this->_capabilities[$slug])) { |
| 186 | $description = $this->_capabilities[$slug]; |
| 187 | } |
| 188 | |
| 189 | return $description; |
| 190 | } |
| 191 | |
| 192 | } |