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

AxeWP / wp-graphql-rank-math / 14947513062

10 May 2025 05:19PM UTC coverage: 86.429% (-2.0%) from 88.44%
14947513062

Pull #121

github

web-flow
Merge f69ff5d7f into 3bd3ede8c
Pull Request #121: dev: add support for lazy-loading `description`/`deprecationReason` config values

356 of 366 new or added lines in 65 files covered. (97.27%)

60 existing lines in 60 files now uncovered.

2541 of 2940 relevant lines covered (86.43%)

11.01 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';
19✔
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 ] );
19✔
47

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

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

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

77
                parent::register();
19✔
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 ] );
19✔
86

87
                $fields = [];
19✔
88

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

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

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

106
                return $fields;
19✔
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 = [
19✔
118
                        'title'                   => [
19✔
119
                                'type'        => 'String',
19✔
120
                                'description' => static fn () => sprintf(
19✔
121
                                        // translators: post type label.
122
                                        __( 'Default title tag for single %s pages.', 'wp-graphql-rank-math' ),
19✔
123
                                        $post_type_object->label,
19✔
124
                                ),
19✔
125
                        ],
19✔
126
                        'description'             => [
19✔
127
                                'type'        => 'String',
19✔
128
                                'description' => static fn () => sprintf(
19✔
129
                                        // translators: post type label.
130
                                        __( 'Default description for single %s pages.', 'wp-graphql-rank-math' ),
19✔
131
                                        $post_type_object->label,
19✔
132
                                ),
19✔
133
                        ],
19✔
134
                        'snippetType'             => [
19✔
135
                                'type'        => SnippetTypeEnum::get_type_name(),
19✔
136
                                'description' => static fn () => sprintf(
19✔
137
                                        // translators: post type label.
138
                                        __( 'Default rich snippet select when creating a new %s.', 'wp-graphql-rank-math' ),
19✔
139
                                        $post_type_object->label,
19✔
140
                                ),
19✔
141
                        ],
19✔
142
                        'articleType'             => [
19✔
143
                                'type'        => ArticleTypeEnum::get_type_name(),
19✔
144
                                'description' => static fn () => sprintf(
19✔
145
                                        // translators: post type label.
146
                                        __( 'Default article type when creating a new %s.', 'wp-graphql-rank-math' ),
19✔
147
                                        $post_type_object->label,
19✔
148
                                ),
19✔
149
                        ],
19✔
150
                        'snippetHeadline'         => [
19✔
151
                                'type'        => 'String',
19✔
152
                                'description' => static fn () => __( 'Default rich snippet headline.', 'wp-graphql-rank-math' ),
19✔
153
                        ],
19✔
154
                        'snippetDescription'      => [
19✔
155
                                'type'        => 'String',
19✔
156
                                'description' => static fn () => __( 'Default rich snippet headline.', 'wp-graphql-rank-math' ),
19✔
157
                        ],
19✔
158
                        'hasCustomRobotsMeta'     => [
19✔
159
                                'type'        => 'Boolean',
19✔
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' ),
19✔
161
                        ],
19✔
162
                        'hasLinkSuggestions'      => [
19✔
163
                                'type'        => 'Boolean',
19✔
164
                                'description' => static fn () => __( 'Whether Link Suggestions meta box and the Pillar Content featured are enabled for this post type.', 'wp-graphql-rank-math' ),
19✔
165
                        ],
19✔
166
                        'shouldUseFocusKeyword'   => [
19✔
167
                                'type'        => 'Boolean',
19✔
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' ),
19✔
169
                        ],
19✔
170
                        'hasBulkEditing'          => [
19✔
171
                                'type'        => BulkEditingTypeEnum::get_type_name(),
19✔
172
                                'description' => static fn () => __( 'Whether to list bulk editing columns to the post listing screen.', 'wp-graphql-rank-math' ),
19✔
173
                        ],
19✔
174
                        'socialImage'             => [
19✔
175
                                'type'        => 'MediaItem',
19✔
176
                                'description' => static fn () => __( 'The default image to display when sharing this post type on social media', 'wp-graphql-rank-math' ),
19✔
177
                                'resolve'     => static function ( $source, array $args, AppContext $context ) {
19✔
178
                                        return ! empty( $source['socialImage'] ) ? $context->get_loader( 'post' )->load_deferred( $source['socialImage'] ) : null;
1✔
179
                                },
19✔
180
                        ],
19✔
181
                        'hasSlackEnhancedSharing' => [
19✔
182
                                'type'        => 'Boolean',
19✔
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' ),
19✔
184
                        ],
19✔
185
                        'hasSeoControls'          => [
19✔
186
                                'type'        => 'Boolean',
19✔
187
                                'description' => static fn () => __( 'Whether the SEO Controls meta box for user profile pages is enabled.', 'wp-graphql-rank-math' ),
19✔
188
                        ],
19✔
189
                        'analyzedFields'          => [
19✔
190
                                'type'        => [ 'list_of' => 'String' ],
19✔
191
                                'description' => static fn () => __( 'List of custom fields name to include in the Page analysis', 'wp-graphql-rank-math' ),
19✔
192
                        ],
19✔
193
                ];
19✔
194

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

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

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

202
                if ( ! empty( $taxonomies ) ) {
19✔
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 ) {
19✔
221
                        unset( $fields['socialImage'] );
×
222
                }
223

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

229
                if ( 'attachment' === $post_type_object->name ) {
19✔
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 ) {
19✔
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;
19✔
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

© 2026 Coveralls, Inc