AuditCheckTrait.php
1 year ago
CoreUserRoleOptionIntegrityCheck.php
1 year ago
EditableFileSystemCheck.php
7 months ago
ElevatedCoreRoleCheck.php
7 months ago
EmptyUnusedRoleCheck.php
7 months ago
HighPrivilegeContentModeratorCheck.php
7 months ago
HighPrivilegeOrElevatedUserCheck.php
7 months ago
HighPrivilegeRoleCheck.php
7 months ago
HighPrivilegeUserCountCheck.php
7 months ago
RestfulAutoDiscoverEndpointCheck.php
7 months ago
RoleCapabilityNamingConventionCheck.php
7 months ago
RoleIntegrityCheck.php
7 months ago
RoleTransparencyCheck.php
7 months ago
XmlRpcEndpointCheck.php
7 months ago
RoleTransparencyCheck.php
128 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 | * Check if all registered roles are transparent to the admin user |
| 12 | * |
| 13 | * @package AAM |
| 14 | * @version 7.0.0 |
| 15 | */ |
| 16 | class AAM_Audit_RoleTransparencyCheck |
| 17 | { |
| 18 | |
| 19 | use AAM_Audit_AuditCheckTrait; |
| 20 | |
| 21 | /** |
| 22 | * Step ID |
| 23 | * |
| 24 | * @version 7.0.0 |
| 25 | */ |
| 26 | const ID = 'roles_visibility'; |
| 27 | |
| 28 | /** |
| 29 | * Run the check |
| 30 | * |
| 31 | * @return array |
| 32 | * |
| 33 | * @access public |
| 34 | * @static |
| 35 | * |
| 36 | * @version 7.0.0 |
| 37 | */ |
| 38 | public static function run() |
| 39 | { |
| 40 | $issues = []; |
| 41 | $response = [ 'is_completed' => true ]; |
| 42 | |
| 43 | try { |
| 44 | array_push( |
| 45 | $issues, |
| 46 | ...self::_validate_roles_transparency(self::_read_role_key_option()) |
| 47 | ); |
| 48 | } catch (Exception $e) { |
| 49 | array_push($issues, self::_format_issue( |
| 50 | 'APPLICATION_ERROR', |
| 51 | [ |
| 52 | 'message' => $e->getMessage() |
| 53 | ], |
| 54 | 'error' |
| 55 | )); |
| 56 | } |
| 57 | |
| 58 | if (count($issues) > 0) { |
| 59 | $response['issues'] = $issues; |
| 60 | } |
| 61 | |
| 62 | // Determine final status for the check |
| 63 | self::_determine_check_status($response); |
| 64 | |
| 65 | return $response; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Get a collection of error messages for current step |
| 70 | * |
| 71 | * @return array |
| 72 | * @access private |
| 73 | * @static |
| 74 | * |
| 75 | * @version 7.0.0 |
| 76 | */ |
| 77 | private static function _get_message_templates() |
| 78 | { |
| 79 | return [ |
| 80 | 'HIDDEN_ROLES' => __( |
| 81 | 'Detected hidden role(s): %s', |
| 82 | 'advanced-access-manager' |
| 83 | ) |
| 84 | ]; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Validate all registered roles are visible to the admin user |
| 89 | * |
| 90 | * @param array $db_roles |
| 91 | * |
| 92 | * @return array |
| 93 | * |
| 94 | * @access private |
| 95 | * @static |
| 96 | * |
| 97 | * @version 7.0.0 |
| 98 | */ |
| 99 | private static function _validate_roles_transparency($db_roles) |
| 100 | { |
| 101 | $response = []; |
| 102 | |
| 103 | $registered_roles = array_keys($db_roles); |
| 104 | |
| 105 | if (function_exists('get_editable_roles')) { |
| 106 | $visible_roles = array_keys(get_editable_roles()); |
| 107 | } else { |
| 108 | $visible_roles = array_keys( |
| 109 | apply_filters('editable_roles', wp_roles()->roles) |
| 110 | ); |
| 111 | } |
| 112 | |
| 113 | // Compute the difference |
| 114 | $diff_roles = array_diff($registered_roles, $visible_roles); |
| 115 | |
| 116 | if (!empty($diff_roles)) { |
| 117 | array_push($response, self::_format_issue( |
| 118 | 'HIDDEN_ROLES', |
| 119 | [ |
| 120 | 'roles' => $diff_roles |
| 121 | ] |
| 122 | )); |
| 123 | } |
| 124 | |
| 125 | return $response; |
| 126 | } |
| 127 | |
| 128 | } |