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

wp-graphql / wp-graphql / 15710056976

17 Jun 2025 02:27PM UTC coverage: 84.17% (-0.1%) from 84.287%
15710056976

push

github

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

15925 of 18920 relevant lines covered (84.17%)

258.66 hits per line

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

92.86
/src/Model/UserRole.php
1
<?php
2

3
namespace WPGraphQL\Model;
4

5
use GraphQLRelay\Relay;
6

7
/**
8
 * Class UserRole - Models data for user roles
9
 *
10
 * @property ?string[] $capabilities
11
 * @property ?string   $displayName
12
 * @property string    $id
13
 * @property ?string   $name
14
 *
15
 * @package WPGraphQL\Model
16
 *
17
 * @extends \WPGraphQL\Model\Model<array<string,mixed>>
18
 */
19
class UserRole extends Model {
20
        /**
21
         * UserRole constructor.
22
         *
23
         * @param array<string,mixed> $user_role The incoming user role to be modeled
24
         *
25
         * @return void
26
         * @throws \Exception
27
         */
28
        public function __construct( $user_role ) {
18✔
29
                $this->data = $user_role;
18✔
30
                parent::__construct();
18✔
31
        }
32

33
        /**
34
         * {@inheritDoc}
35
         */
36
        protected function is_private() {
18✔
37
                if ( current_user_can( 'list_users' ) ) {
18✔
38
                        return false;
11✔
39
                }
40

41
                $current_user_roles = wp_get_current_user()->roles;
7✔
42

43
                if ( in_array( $this->data['slug'], $current_user_roles, true ) ) {
7✔
44
                        return false;
7✔
45
                }
46

47
                return true;
×
48
        }
49

50
        /**
51
         * {@inheritDoc}
52
         */
53
        protected function init() {
18✔
54
                if ( empty( $this->fields ) ) {
18✔
55
                        $this->fields = [
18✔
56
                                'capabilities' => function () {
18✔
57
                                        if ( empty( $this->data['capabilities'] ) || ! is_array( $this->data['capabilities'] ) ) {
2✔
58
                                                return null;
×
59
                                        }
60

61
                                        return array_keys( $this->data['capabilities'] );
2✔
62
                                },
18✔
63
                                'displayName'  => function () {
18✔
64
                                        return ! empty( $this->data['displayName'] ) ? esc_html( $this->data['displayName'] ) : null;
2✔
65
                                },
18✔
66
                                'id'           => function () {
18✔
67
                                        return Relay::toGlobalId( 'user_role', $this->data['id'] );
18✔
68
                                },
18✔
69
                                'name'         => function () {
18✔
70
                                        return ! empty( $this->data['name'] ) ? esc_html( $this->data['name'] ) : null;
17✔
71
                                },
18✔
72
                        ];
18✔
73
                }
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

© 2025 Coveralls, Inc