• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wp-graphql / wp-graphql / 14716683875

28 Apr 2025 07:58PM UTC coverage: 84.287% (+1.6%) from 82.648%
14716683875

push

github

actions-user
release: merge develop into master for v2.3.0

15905 of 18870 relevant lines covered (84.29%)

257.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.79
/src/Type/Enum/UserRoleEnum.php
1
<?php
2

3
namespace WPGraphQL\Type\Enum;
4

5
use WPGraphQL\Type\WPEnumType;
6

7
class UserRoleEnum {
8

9
        /**
10
         * Register the UserRoleEnum Type to the Schema
11
         *
12
         * @return void
13
         */
14
        public static function register_type() {
594✔
15
                $all_roles = wp_roles()->roles;
594✔
16
                $roles     = [];
594✔
17

18
                foreach ( $all_roles as $key => $role ) {
594✔
19
                        $formatted_role = WPEnumType::get_safe_name( isset( $role['name'] ) ? $role['name'] : $key );
594✔
20

21
                        switch ( $role ) {
22
                                case 'administrator':
594✔
23
                                        $description = static function () {
24
                                                return __( 'Full system access with ability to manage all aspects of the site.', 'wp-graphql' );
×
25
                                        };
26
                                        break;
×
27
                                case 'editor':
594✔
28
                                        $description = static function () {
29
                                                return __( 'Content management access without administrative capabilities.', 'wp-graphql' );
×
30
                                        };
31
                                        break;
×
32
                                case 'author':
594✔
33
                                        $description = static function () {
34
                                                return __( 'Can publish and manage their own content.', 'wp-graphql' );
×
35
                                        };
36
                                        break;
×
37
                                case 'contributor':
594✔
38
                                        $description = static function () {
39
                                                return __( 'Can write and manage their own content but cannot publish.', 'wp-graphql' );
×
40
                                        };
41
                                        break;
×
42
                                case 'subscriber':
594✔
43
                                        $description = static function () {
44
                                                return __( 'Can only manage their profile and read content.', 'wp-graphql' );
×
45
                                        };
46
                                        break;
×
47
                                default:
48
                                        $description = static function () {
594✔
49
                                                return __( 'User role with specific capabilities', 'wp-graphql' );
137✔
50
                                        };
594✔
51
                        }
52

53
                        $roles[ $formatted_role ] = [
594✔
54
                                'description' => $description,
594✔
55
                                'value'       => $key,
594✔
56
                                'role'        => $role,
594✔
57
                        ];
594✔
58
                }
59

60
                // Bail if there are no roles to register.
61
                if ( empty( $roles ) ) {
594✔
62
                        return;
×
63
                }
64

65
                register_graphql_enum_type(
594✔
66
                        'UserRoleEnum',
594✔
67
                        [
594✔
68
                                'description' => static function () {
594✔
69
                                        return __( 'Permission levels for user accounts. Defines the standard access levels that control what actions users can perform within the system.', 'wp-graphql' );
15✔
70
                                },
594✔
71
                                'values'      => $roles,
594✔
72
                        ]
594✔
73
                );
594✔
74
        }
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc