• 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

94.19
/src/Type/ObjectType/CommentAuthor.php
1
<?php
2

3
namespace WPGraphQL\Type\ObjectType;
4

5
use WPGraphQL\Model\CommentAuthor as CommentAuthorModel;
6

7
class CommentAuthor {
8

9
        /**
10
         * Register the CommentAuthor Type to the Schema
11
         *
12
         * @return void
13
         */
14
        public static function register_type() {
593✔
15
                register_graphql_object_type(
593✔
16
                        'CommentAuthor',
593✔
17
                        [
593✔
18
                                'description'     => static function () {
593✔
19
                                        return __( 'A Comment Author object', 'wp-graphql' );
69✔
20
                                },
593✔
21
                                'interfaces'      => [ 'Node', 'Commenter' ],
593✔
22
                                'model'           => CommentAuthorModel::class,
593✔
23
                                'eagerlyLoadType' => true,
593✔
24
                                'fields'          => static function () {
593✔
25
                                        return [
72✔
26
                                                'id'           => [
72✔
27
                                                        'description' => static function () {
72✔
28
                                                                return __( 'The globally unique identifier for the comment author object', 'wp-graphql' );
69✔
29
                                                        },
72✔
30
                                                ],
72✔
31
                                                'name'         => [
72✔
32
                                                        'type'        => 'String',
72✔
33
                                                        'description' => static function () {
72✔
34
                                                                return __( 'The name for the comment author.', 'wp-graphql' );
69✔
35
                                                        },
72✔
36
                                                ],
72✔
37
                                                'email'        => [
72✔
38
                                                        'type'        => 'String',
72✔
39
                                                        'description' => static function () {
72✔
40
                                                                return __( 'The email for the comment author', 'wp-graphql' );
69✔
41
                                                        },
72✔
42
                                                ],
72✔
43
                                                'url'          => [
72✔
44
                                                        'type'        => 'String',
72✔
45
                                                        'description' => static function () {
72✔
46
                                                                return __( 'The url the comment author.', 'wp-graphql' );
69✔
47
                                                        },
72✔
48
                                                ],
72✔
49
                                                'isRestricted' => [
72✔
50
                                                        'type'        => 'Boolean',
72✔
51
                                                        'description' => static function () {
72✔
52
                                                                return __( 'Whether the object is restricted from the current viewer', 'wp-graphql' );
69✔
53
                                                        },
72✔
54
                                                ],
72✔
55
                                                'avatar'       => [
72✔
56
                                                        'args'    => [
72✔
57
                                                                'size'         => [
72✔
58
                                                                        'type'         => 'Int',
72✔
59
                                                                        'description'  => static function () {
72✔
60
                                                                                return __( 'The size attribute of the avatar field can be used to fetch avatars of different sizes. The value corresponds to the dimension in pixels to fetch. The default is 96 pixels.', 'wp-graphql' );
69✔
61
                                                                        },
72✔
62
                                                                        'defaultValue' => 96,
72✔
63
                                                                ],
72✔
64
                                                                'forceDefault' => [
72✔
65
                                                                        'type'        => 'Boolean',
72✔
66
                                                                        'description' => static function () {
72✔
67
                                                                                return __( 'Whether to always show the default image, never the Gravatar. Default false', 'wp-graphql' );
69✔
68
                                                                        },
72✔
69
                                                                ],
72✔
70
                                                                'rating'       => [
72✔
71
                                                                        'type'        => 'AvatarRatingEnum',
72✔
72
                                                                        'description' => static function () {
72✔
73
                                                                                return __( 'The rating level of the avatar.', 'wp-graphql' );
69✔
74
                                                                        },
72✔
75
                                                                ],
72✔
76

77
                                                        ],
72✔
78
                                                        'resolve' => static function ( $comment_author, $args ) {
72✔
79
                                                                /**
80
                                                                 * If the $comment_author is a user, the User model only returns the email address if the requesting user is authenticated.
81
                                                                 * But, to resolve the Avatar we need a valid email, even for unauthenticated requests.
82
                                                                 *
83
                                                                 * If the email isn't visible, we use the comment ID to retrieve it, then use it to resolve the avatar.
84
                                                                 *
85
                                                                 * The email address is not publicly exposed, adhering to the rules of the User model.
86
                                                                 */
87
                                                                $comment_author_email = ! empty( $comment_author->email ) ? $comment_author->email : get_comment_author_email( $comment_author->databaseId );
2✔
88

89
                                                                if ( empty( $comment_author_email ) ) {
2✔
90
                                                                        return null;
×
91
                                                                }
92

93
                                                                $avatar_args = [];
2✔
94
                                                                if ( is_numeric( $args['size'] ) ) {
2✔
95
                                                                        $avatar_args['size'] = absint( $args['size'] );
2✔
96
                                                                        if ( ! $avatar_args['size'] ) {
2✔
97
                                                                                $avatar_args['size'] = 96;
×
98
                                                                        }
99
                                                                }
100

101
                                                                if ( ! empty( $args['forceDefault'] ) && true === $args['forceDefault'] ) {
2✔
102
                                                                        $avatar_args['force_default'] = true;
×
103
                                                                }
104

105
                                                                if ( ! empty( $args['rating'] ) ) {
2✔
106
                                                                        $avatar_args['rating'] = esc_sql( (string) $args['rating'] );
×
107
                                                                }
108

109
                                                                $avatar = get_avatar_data( $comment_author_email, $avatar_args );
2✔
110

111
                                                                // if there's no url returned, return null
112
                                                                if ( empty( $avatar['url'] ) ) {
2✔
113
                                                                        return null;
×
114
                                                                }
115

116
                                                                return new \WPGraphQL\Model\Avatar( $avatar );
2✔
117
                                                        },
72✔
118
                                                ],
72✔
119
                                        ];
72✔
120
                                },
593✔
121
                        ]
593✔
122
                );
593✔
123
        }
124
}
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