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

AxeWP / wp-graphql-rank-math / 15507492505

07 Jun 2025 11:44AM UTC coverage: 86.429% (-2.0%) from 88.44%
15507492505

push

github

web-flow
dev: add support for lazy-loading `description`/`deprecationReason` config values (#121)

* chore: update strauss and deps

* dev: use callable descriptions/deprecations

* fix: dont prefix `NodeWithRankMathSeo`

* chore: fix backcompat on connections

* chore: update dep

* chore: update deps

* tests: ensure schema can build

* chore: update and cleanup

* fix: regenerate autoloader

357 of 367 new or added lines in 66 files covered. (97.28%)

60 existing lines in 60 files now uncovered.

2541 of 2940 relevant lines covered (86.43%)

11.49 hits per line

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

80.95
/src/Type/WPObject/Settings/Meta/ContentTypeMeta.php
1
<?php
2
/**
3
 * The ContentTypeMeta GraphQL object.
4
 *
5
 * @package WPGraphQL\RankMath\Type\WPObject\Settings\Meta
6
 */
7

8
declare( strict_types = 1 );
9

10
namespace WPGraphQL\RankMath\Type\WPObject\Settings\Meta;
11

12
use GraphQL\Error\UserError;
13
use RankMath\Helper;
14
use WPGraphQL\AppContext;
15
use WPGraphQL\RankMath\Type\Enum\ArticleTypeEnum;
16
use WPGraphQL\RankMath\Type\Enum\BulkEditingTypeEnum;
17
use WPGraphQL\RankMath\Type\Enum\SnippetTypeEnum;
18
use WPGraphQL\RankMath\Type\WPInterface\MetaSettingWithArchive;
19
use WPGraphQL\RankMath\Type\WPInterface\MetaSettingWithRobots;
20
use WPGraphQL\RankMath\Vendor\AxeWP\GraphQL\Abstracts\ObjectType;
21
use WPGraphQL\RankMath\Vendor\AxeWP\GraphQL\Helper\Compat;
22

23
/**
24
 * Class - ContentTypeMeta
25
 */
26
class ContentTypeMeta extends ObjectType {
27
        /**
28
         * {@inheritDoc}
29
         */
30
        protected static function type_name(): string {
31
                return 'ContentTypeMetaSettings';
20✔
32
        }
33

34
        /**
35
         * {@inheritDoc}
36
         */
37
        public static function get_description(): string {
UNCOV
38
                return __( 'The RankMath SEO Post Type settings.', 'wp-graphql-rank-math' );
×
39
        }
40

41
        /**
42
         * {@inheritDoc}
43
         */
44
        public static function register(): void {
45
                /** @var \WP_Post_Type[] */
46
                $allowed_post_types = \WPGraphQL::get_allowed_post_types( 'objects', [ 'public' => true ] );
20✔
47

48
                foreach ( $allowed_post_types as $post_type_object ) {
20✔
49
                        // Skip attachment meta if redirection is enabled.
50
                        if ( 'attachment' === $post_type_object->name && Helper::get_settings( 'general.attachment_redirect_urls', true ) ) {
20✔
51
                                continue;
20✔
52
                        }
53

54
                        $interfaces = [
20✔
55
                                MetaSettingWithRobots::get_type_name(),
20✔
56
                        ];
20✔
57
                        if ( $post_type_object->has_archive ) {
20✔
58
                                $interfaces[] = MetaSettingWithArchive::get_type_name();
×
59
                        }
60

61
                        register_graphql_object_type(
20✔
62
                                ucfirst( $post_type_object->graphql_single_name ) . 'MetaSettings',
20✔
63
                                Compat::resolve_graphql_config( // @todo Remove when WPGraphQL < 2.3.0 is dropped.
20✔
64
                                        [
20✔
65
                                                'description' => static fn () => sprintf(
20✔
66
                                                // translators: post type name.
67
                                                        __( 'The RankMath SEO meta settings for %s.', 'wp-graphql-rank-math' ),
20✔
68
                                                        $post_type_object->label,
20✔
69
                                                ),
20✔
70
                                                'interfaces'  => $interfaces,
20✔
71
                                                'fields'      => self::get_child_type_fields( $post_type_object ),
20✔
72
                                        ]
20✔
73
                                )
20✔
74
                        );
20✔
75
                }
76

77
                parent::register();
20✔
78
        }
79

80
        /**
81
         * {@inheritDoc}
82
         */
83
        public static function get_fields(): array {
84
                /** @var \WP_Post_Type[] */
85
                $allowed_post_types = \WPGraphQL::get_allowed_post_types( 'objects', [ 'public' => true ] );
20✔
86

87
                $fields = [];
20✔
88

89
                foreach ( $allowed_post_types as $post_type_object ) {
20✔
90

91
                        // Skip attachment meta if redirection is enabled.
92
                        if ( 'attachment' === $post_type_object->name && Helper::get_settings( 'general.attachment_redirect_urls', true ) ) {
20✔
93
                                continue;
20✔
94
                        }
95

96
                        $fields[ lcfirst( $post_type_object->graphql_single_name ) ] = [
20✔
97
                                'type'        => $post_type_object->graphql_single_name . 'MetaSettings',
20✔
98
                                'description' => static fn () => sprintf(
20✔
99
                                        // translators: post type name.
100
                                        __( 'The RankMath SEO meta settings for %s.', 'wp-graphql-rank-math' ),
20✔
101
                                        $post_type_object->label,
20✔
102
                                ),
20✔
103
                        ];
20✔
104
                }
105

106
                return $fields;
20✔
107
        }
108

109
        /**
110
         * Get the fields for the provided content type.
111
         *
112
         * @param \WP_Post_Type $post_type_object .
113
         *
114
         * @return array<string, array<string, mixed>>
115
         */
116
        public static function get_child_type_fields( \WP_Post_Type $post_type_object ): array {
117
                $fields = [
20✔
118
                        'title'                   => [
20✔
119
                                'type'        => 'String',
20✔
120
                                'description' => static fn () => sprintf(
20✔
121
                                        // translators: post type label.
122
                                        __( 'Default title tag for single %s pages.', 'wp-graphql-rank-math' ),
20✔
123
                                        $post_type_object->label,
20✔
124
                                ),
20✔
125
                        ],
20✔
126
                        'description'             => [
20✔
127
                                'type'        => 'String',
20✔
128
                                'description' => static fn () => sprintf(
20✔
129
                                        // translators: post type label.
130
                                        __( 'Default description for single %s pages.', 'wp-graphql-rank-math' ),
20✔
131
                                        $post_type_object->label,
20✔
132
                                ),
20✔
133
                        ],
20✔
134
                        'snippetType'             => [
20✔
135
                                'type'        => SnippetTypeEnum::get_type_name(),
20✔
136
                                'description' => static fn () => sprintf(
20✔
137
                                        // translators: post type label.
138
                                        __( 'Default rich snippet select when creating a new %s.', 'wp-graphql-rank-math' ),
20✔
139
                                        $post_type_object->label,
20✔
140
                                ),
20✔
141
                        ],
20✔
142
                        'articleType'             => [
20✔
143
                                'type'        => ArticleTypeEnum::get_type_name(),
20✔
144
                                'description' => static fn () => sprintf(
20✔
145
                                        // translators: post type label.
146
                                        __( 'Default article type when creating a new %s.', 'wp-graphql-rank-math' ),
20✔
147
                                        $post_type_object->label,
20✔
148
                                ),
20✔
149
                        ],
20✔
150
                        'snippetHeadline'         => [
20✔
151
                                'type'        => 'String',
20✔
152
                                'description' => static fn () => __( 'Default rich snippet headline.', 'wp-graphql-rank-math' ),
20✔
153
                        ],
20✔
154
                        'snippetDescription'      => [
20✔
155
                                'type'        => 'String',
20✔
156
                                'description' => static fn () => __( 'Default rich snippet headline.', 'wp-graphql-rank-math' ),
20✔
157
                        ],
20✔
158
                        'hasCustomRobotsMeta'     => [
20✔
159
                                'type'        => 'Boolean',
20✔
160
                                'description' => static fn () => __( 'Whether custom robots meta for author page are set. Otherwise the default meta will be used, as set in the Global Meta tab.', 'wp-graphql-rank-math' ),
20✔
161
                        ],
20✔
162
                        'hasLinkSuggestions'      => [
20✔
163
                                'type'        => 'Boolean',
20✔
164
                                'description' => static fn () => __( 'Whether Link Suggestions meta box and the Pillar Content featured are enabled for this post type.', 'wp-graphql-rank-math' ),
20✔
165
                        ],
20✔
166
                        'shouldUseFocusKeyword'   => [
20✔
167
                                'type'        => 'Boolean',
20✔
168
                                'description' => static fn () => __( 'Whether to use the Focus Keyword as the default text for the links instead of the post titles.', 'wp-graphql-rank-math' ),
20✔
169
                        ],
20✔
170
                        'hasBulkEditing'          => [
20✔
171
                                'type'        => BulkEditingTypeEnum::get_type_name(),
20✔
172
                                'description' => static fn () => __( 'Whether to list bulk editing columns to the post listing screen.', 'wp-graphql-rank-math' ),
20✔
173
                        ],
20✔
174
                        'socialImage'             => [
20✔
175
                                'type'        => 'MediaItem',
20✔
176
                                'description' => static fn () => __( 'The default image to display when sharing this post type on social media', 'wp-graphql-rank-math' ),
20✔
177
                                'resolve'     => static function ( $source, array $args, AppContext $context ) {
20✔
178
                                        return ! empty( $source['socialImage'] ) ? $context->get_loader( 'post' )->load_deferred( $source['socialImage'] ) : null;
1✔
179
                                },
20✔
180
                        ],
20✔
181
                        'hasSlackEnhancedSharing' => [
20✔
182
                                'type'        => 'Boolean',
20✔
183
                                'description' => static fn () => __( 'Whether to show additional information (name & total number of posts) when an author archive is shared on Slack.', 'wp-graphql-rank-math' ),
20✔
184
                        ],
20✔
185
                        'hasSeoControls'          => [
20✔
186
                                'type'        => 'Boolean',
20✔
187
                                'description' => static fn () => __( 'Whether the SEO Controls meta box for user profile pages is enabled.', 'wp-graphql-rank-math' ),
20✔
188
                        ],
20✔
189
                        'analyzedFields'          => [
20✔
190
                                'type'        => [ 'list_of' => 'String' ],
20✔
191
                                'description' => static fn () => __( 'List of custom fields name to include in the Page analysis', 'wp-graphql-rank-math' ),
20✔
192
                        ],
20✔
193
                ];
20✔
194

195
                $all_taxonomies = Helper::get_object_taxonomies( $post_type_object->name );
20✔
196
                $all_taxonomies = is_array( $all_taxonomies ) && ! empty( $all_taxonomies ) ? $all_taxonomies : [];
20✔
197

198
                $allowed_taxonomies = \WPGraphQL::get_allowed_taxonomies( 'names', [ 'public' => true ] );
20✔
199

200
                $taxonomies = array_intersect( $all_taxonomies, $allowed_taxonomies );
20✔
201

202
                if ( ! empty( $taxonomies ) ) {
20✔
203
                        $fields['primaryTaxonomy'] = [
×
204
                                'type'        => 'TaxonomyEnum',
×
NEW
205
                                'description' => static fn () => __( 'The taxonomy used with the Primary Term Feature and displayed in the Breadcrumbs.', 'wp-graphql-rank-math' ),
×
206
                                'resolve'     => static function ( $source ) use ( $allowed_taxonomies ) {
×
207
                                        if ( ! in_array( $source, $allowed_taxonomies, true ) ) {
×
208
                                                throw new UserError(
×
209
                                                        sprintf(
×
210
                                                                // translators: taxonomy name.
211
                                                                esc_html__( 'The %s post type is not available in WPGraphQL', 'wp-graphql-rank-math' ),
×
212
                                                                esc_html( $source )
×
213
                                                        )
×
214
                                                );
×
215
                                        }
216
                                },
×
217
                        ];
×
218
                }
219

220
                if ( $post_type_object->has_archive ) {
20✔
221
                        unset( $fields['socialImage'] );
×
222
                }
223

224
                if ( in_array( $post_type_object->name, [ 'product', 'download', 'rank_math_locations' ], true ) ) {
20✔
225
                        unset( $fields['snippetDescription'] );
×
226
                        unset( $fields['snippetHeadline'] );
×
227
                }
228

229
                if ( 'attachment' === $post_type_object->name ) {
20✔
230
                        unset( $fields['hasLinkSuggestions'] );
×
231
                        unset( $fields['shouldUseFocusKeyword'] );
×
232
                        unset( $fields['hasSlackEnhancedSharing'] );
×
233
                }
234

235
                if ( defined( 'WEBSTORIES_VERSION' ) && 'web-story' === $post_type_object->name ) {
20✔
236
                        unset( $fields['snippetDescription'] );
×
237
                        unset( $fields['description'] );
×
238
                        unset( $fields['hasLinkSuggestions'] );
×
239
                        unset( $fields['shouldUseFocusKeyword'] );
×
240
                        unset( $fields['analyzedFields'] );
×
241
                        unset( $fields['hasBulkEditing'] );
×
242
                        unset( $fields['hasSeoControls'] );
×
243
                }
244

245
                return $fields;
20✔
246
        }
247
}
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