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

AxeWP / wp-graphql-rank-math / 5176687204

pending completion
5176687204

push

github

web-flow
chore: Implement WPGraphQL Code Standards (PHPCS) (#51)

* chore: lint for WPGraphQL-Minimum

* chore: lint for WPGraphQL-Strict

* chore: lint for WPGraphQL-Extra

* chore: lint for WPGraphQL (full)

* chore: update PHPCS ruleset

* chore: update changelog

* fix: restore `rank_math/head` hook

* chore: update composer deps (wpcli fix)

* chore: fix missed files

* chore: update composer deps

* test: bump boilerplate

* chore: update deps to final versions

93 of 93 new or added lines in 32 files covered. (100.0%)

1963 of 2274 relevant lines covered (86.32%)

5.42 hits per line

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

94.14
/src/Model/Settings.php
1
<?php
2
/**
3
 * Settings Model class
4
 *
5
 * @package \WPGraphQL\RankMath\Model
6
 */
7

8
namespace WPGraphQL\RankMath\Model;
9

10
use Exception;
11
use RankMath\Helper;
12
use RankMath\Sitemap\Router;
13
use WPGraphQL\Model\Model;
14

15
/**
16
 * Class - Settings
17
 */
18
class Settings extends Model {
19
        /**
20
         * {@inheritDoc}
21
         *
22
         * @var array<string, mixed>
23
         */
24
        protected $data;
25

26
        /**
27
         * Array of active modules
28
         * 
29
         * @var string[]
30
         */
31
        protected array $active_modules;
32

33
        /**
34
         * Constructor.
35
         *
36
         * @throws \Exception .
37
         */
38
        public function __construct() {
39
                /** @property \RankMath\Settings $settings_obj */
40
                $settings_obj = rank_math()->settings;
3✔
41
                $settings     = $settings_obj->all();
3✔
42

43
                if ( empty( $settings ) ) {
3✔
44
                        throw new Exception( __( 'The Rank Math settings cannot be found', 'wp-graphql-rank-math' ) );
×
45
                }
46

47
                $this->data = $settings;
3✔
48

49
                $this->active_modules = Helper::get_active_modules();
3✔
50

51
                parent::__construct();
3✔
52
        }
53

54
        /**
55
         * Initializes the object
56
         *
57
         * @return void
58
         */
59
        protected function init() {
60
                if ( empty( $this->fields ) ) {
3✔
61
                        $this->fields = [
3✔
62
                                'general' => fn () => $this->general_fields(),
3✔
63
                                'meta'    => fn () => [
3✔
64
                                        'authorArchives'               => $this->meta_author_archive_fields(),
3✔
65
                                        'global'                       => $this->meta_global_fields(),
3✔
66
                                        'local'                        => $this->meta_local_fields(),
3✔
67
                                        'social'                       => $this->meta_social_fields(),
3✔
68
                                        'homepage'                     => $this->meta_homepage_fields(),
3✔
69
                                        'dateArchives'                 => $this->meta_date_archive_fields(),
3✔
70
                                        'contentTypes'                 => $this->meta_content_type_fields(),
3✔
71
                                        'taxonomies'                   => $this->meta_taxonomy_fields(),
3✔
72
                                        'notFoundTitle'                => ! empty( $this->data['titles']['404_title'] ) ? $this->data['titles']['404_title'] : null,
3✔
73
                                        'searchTitle'                  => ! empty( $this->data['titles']['search_title'] ) ? $this->data['titles']['search_title'] : null,
3✔
74
                                        'shouldIndexSearch'            => empty( $this->data['titles']['noindex_search'] ),
3✔
75
                                        'shouldIndexPaginatedPages'    => empty( $this->data['titles']['noindex_paginated_pages'] ),
3✔
76
                                        'shouldIndexArchiveSubpages'   => empty( $this->data['titles']['noindex_archive_subpages'] ),
3✔
77
                                        'shouldIndexPasswordProtected' => empty( $this->data['titles']['noindex_password_protected'] ),
3✔
78
                                ],  
3✔
79
                        ];
3✔
80

81
                        if ( in_array( 'sitemap', $this->active_modules, true ) ) {
3✔
82
                                $this->fields['sitemap'] = fn () => [
3✔
83
                                        'author'          => $this->sitemap_author_fields(),
1✔
84
                                        'contentTypes'    => $this->sitemap_content_type_fields(),
1✔
85
                                        'general'         => $this->sitemap_general_fields(),
1✔
86
                                        'sitemapIndexUrl' => rank_math_get_sitemap_url(),
1✔
87
                                        'taxonomies'      => $this->sitemap_taxonomy_fields(),
1✔
88
                                ];
1✔
89
                        }
90
                }
91
        }
92

93
        /**
94
         * Resolve the general settings fields.
95
         *
96
         * @return array<string, mixed>
97
         */
98
        private function general_fields(): array {
99
                return [
1✔
100
                        'breadcrumbs'         => function (): array {
1✔
101
                                $has_home = ! empty( $this->data['general']['breadcrumbs_home'] );
1✔
102

103
                                return [
1✔
104
                                        'archiveFormat'         => ! empty( $this->data['general']['breadcrumbs_archive_format'] ) ? $this->data['general']['breadcrumbs_archive_format'] : null,
1✔
105
                                        'hasPostTitle'          => empty( $this->data['general']['breadcrumbs_remove_post_title'] ),
1✔
106
                                        'hasAncestorCategories' => ! empty( $this->data['general']['breadcrumbs_ancestor_categories'] ),
1✔
107
                                        'hasTaxonomyName'       => empty( $this->data['general']['breadcrumbs_hide_taxonomy_name'] ),
1✔
108
                                        'hasBlogPage'           => ! empty( $this->data['general']['breadcrumbs_blog_page'] ),
1✔
109
                                        'hasHome'               => $has_home,
1✔
110
                                        'homeLabel'             => function () use ( $has_home ): ?string {
1✔
111
                                                if ( ! $has_home ) {
1✔
112
                                                        return null;
×
113
                                                }
114
                                                return ! empty( $this->data['general']['breadcrumbs_home_label'] ) ? $this->data['general']['breadcrumbs_home_label'] : null;
1✔
115
                                        },
1✔
116
                                        'homeUrl'               => function () use ( $has_home ): ?string {
1✔
117
                                                if ( ! $has_home ) {
1✔
118
                                                        return null;
×
119
                                                }
120
                                                $value = ! empty( $this->data['general']['breadcrumbs_home_link'] ) ? $this->data['general']['breadcrumbs_home_link'] : null;
1✔
121
                                                return ! empty( $value ) ? $value : null;
1✔
122
                                        },
1✔
123
                                        'notFoundLabel'         => ! empty( $this->data['general']['breadcrumbs_404_label'] ) ? $this->data['general']['breadcrumbs_404_label'] : null,
1✔
124
                                        'prefix'                => ! empty( $this->data['general']['breadcrumbs_prefix'] ) ? $this->data['general']['breadcrumbs_prefix'] : null,
1✔
125
                                        'separator'             => ! empty( $this->data['general']['breadcrumbs_separator'] ) ? $this->data['general']['breadcrumbs_separator'] : null,
1✔
126
                                        'searchFormat'          => ! empty( $this->data['general']['breadcrumbs_search_format'] ) ? $this->data['general']['breadcrumbs_search_format'] : null,
1✔
127
                                ];
1✔
128
                        },
1✔
129
                        'frontendSeoScore'    => [
1✔
130
                                'enabledPostTypes'    => ! empty( $this->data['general']['frontend_seo_score_post_types'] ) ? $this->data['general']['frontend_seo_score_post_types'] : null,
1✔
131
                                'template'            => ! empty( $this->data['general']['frontend_seo_score_template'] ) ? $this->data['general']['frontend_seo_score_template'] : null,
1✔
132
                                'position'            => ! empty( $this->data['general']['frontend_seo_score_position'] ) ? $this->data['general']['frontend_seo_score_position'] : null,
1✔
133
                                'hasRankMathBacklink' => ! empty( $this->data['general']['support_rank_math'] ),
1✔
134
                        ],
1✔
135
                        'hasBreadcrumbs'      => ! empty( $this->data['general']['breadcrumbs'] ),
1✔
136
                        'hasFrontendSeoScore' => ! empty( $this->data['general']['frontend_seo_score'] ),
1✔
137
                        'links'               => [
1✔
138
                                'defaultAttachmentRedirectUrl' => ! empty( $this->data['general']['attachment_redirect_default'] ) ? $this->data['general']['attachment_redirect_default'] : null,
1✔
139
                                'hasCategoryBase'              => empty( $this->data['general']['strip_category_base'] ),
1✔
140
                                'nofollowDomains'              => ! empty( $this->data['general']['nofollow_domains'] ) ? $this->data['general']['nofollow_domains'] : null,
1✔
141
                                'nofollowExcludedDomains'      => ! empty( $this->data['general']['nofollow_exclude_domains'] ) ? $this->data['general']['nofollow_exclude_domains'] : null,
1✔
142
                                'shouldNofollowImageLinks'     => ! empty( $this->data['general']['nofollow_image_links'] ),
1✔
143
                                'shouldNofollowLinks'          => ! empty( $this->data['general']['nofollow_external_links'] ),
1✔
144
                                'shouldOpenInNewWindow'        => ! empty( $this->data['general']['new_window_external_links'] ),
1✔
145
                                'shouldRedirectAttachments'    => ! empty( $this->data['general']['attachment_redirect_urls'] ),
1✔
146
                        ],
1✔
147
                        'webmaster'           => [
1✔
148
                                'baidu'     => ! empty( $this->data['general']['baidu_verify'] ) ? $this->data['general']['baidu_verify'] : null,
1✔
149
                                'bing'      => ! empty( $this->data['general']['bing_verify'] ) ? $this->data['general']['bing_verify'] : null,
1✔
150
                                'google'    => ! empty( $this->data['general']['google_verify'] ) ? $this->data['general']['google_verify'] : null,
1✔
151
                                'norton'    => ! empty( $this->data['general']['norton_verify'] ) ? $this->data['general']['norton_verify'] : null,
1✔
152
                                'pinterest' => ! empty( $this->data['general']['pinterest_verify'] ) ? $this->data['general']['pinterest_verify'] : null,
1✔
153
                                'yandex'    => ! empty( $this->data['general']['yandex_verify'] ) ? $this->data['general']['yandex_verify'] : null,
1✔
154
                        ],
1✔
155
                        'rssBeforeContent'    => ! empty( $this->data['general']['rss_before_content'] ) ? $this->data['general']['rss_before_content'] : null,
1✔
156
                        'rssAfterContent'     => ! empty( $this->data['general']['rss_after_content'] ) ? $this->data['general']['rss_after_content'] : null,
1✔
157
                ];
1✔
158
        }
159

160
        /**
161
         * Get the advanced robots meta for the provided key.
162
         *
163
         * @param string $key the array key used to store the meta.
164
         *
165
         * @return ?array<string, mixed>
166
         */
167
        private function advanced_robots_meta( string $key ): ?array {
168
                return ! empty( $this->data['titles'][ $key ] )
1✔
169
                        ? [
×
170
                                'hasSnippet'       => ! empty( $this->data['titles'][ $key ]['max-snippet'] ),
×
171
                                'snippetLength'    => ! empty( $this->data['titles'][ $key ]['max-snippet'] ) ? $this->data['titles'][ $key ]['max-snippet'] : null,
×
172
                                'hasVideoPreview'  => ! empty( $this->data['titles'][ $key ]['max-video-preview'] ),
×
173
                                'videoDuration'    => ! empty( $this->data['titles'][ $key ]['max-video-preview'] ) ? $this->data['titles'][ $key ]['max-video-preview'] : null,
×
174
                                'hasImagePreview'  => ! empty( $this->data['titles'][ $key ]['max-image-preview'] ),
×
175
                                'imagePreviewSize' => ! empty( $this->data['titles'][ $key ]['max-image-preview'] ) ? $this->data['titles'][ $key ]['max-image-preview'] : null,
×
176
                        ]
×
177
                        : null;
1✔
178
        }
179

180
        /**
181
         * Resolve titles and meta Global fields.
182
         *
183
         * @return array<string, mixed>
184
         */
185
        private function meta_global_fields(): array {
186
                return [
1✔
187
                        'advancedRobotsMeta'         => $this->advanced_robots_meta( 'advanced_robots_global' ),
1✔
188
                        'robotsMeta'                 => ! empty( $this->data['titles']['robots_global'] ) ? $this->data['titles']['robots_global'] : null,
1✔
189
                        'openGraphImageId'           => ! empty( $this->data['titles']['open_graph_image_id'] ) ? $this->data['titles']['open_graph_image_id'] : null,
1✔
190
                        'separator'                  => ! empty( $this->data['titles']['title_separator'] ) ? $this->data['titles']['title_separator'] : null,
1✔
191
                        'twitterCardType'            => ! empty( $this->data['titles']['twitter_card_type'] ) ? $this->data['titles']['twitter_card_type'] : null,
1✔
192
                        'shouldCapitalizeTitles'     => ! empty( $this->data['titles']['capitalize_titles'] ),
1✔
193
                        'shouldIndexEmptyTaxonomies' => empty( $this->data['titles']['noindex_empty_taxonomies'] ),
1✔
194
                        'shouldRewriteTitle'         => ! empty( $this->data['titles']['rewrite_title'] ),
1✔
195
                ];
1✔
196
        }
197

198
        /**
199
         * Resolve titles and meta social fields.
200
         *
201
         * @return array<string, mixed>
202
         */
203
        private function meta_social_fields(): array {
204
                return [
1✔
205
                        'facebookPageUrl'   => ! empty( $this->data['titles']['social_url_facebook'] ) ? $this->data['titles']['social_url_facebook'] : null,
1✔
206
                        'facebookAuthorUrl' => ! empty( $this->data['titles']['facebook_author_urls'] ) ? $this->data['titles']['facebook_author_urls'] : null,
1✔
207
                        'facebookAdminId'   => ! empty( $this->data['titles']['facebook_admin_id'] ) ? $this->data['titles']['facebook_admin_id'] : null,
1✔
208
                        'facebookAppId'     => ! empty( $this->data['titles']['facebook_app_id'] ) ? $this->data['titles']['facebook_app_id'] : null,
1✔
209
                        'twitterAuthorName' => ! empty( $this->data['titles']['twitter_author_names'] ) ? $this->data['titles']['twitter_author_names'] : null,
1✔
210
                ];
1✔
211
        }
212

213
        /**
214
         * Resolve titles and meta local fields.
215
         *
216
         * @return array<string, mixed>
217
         */
218
        private function meta_local_fields(): array {
219
                return [
1✔
220
                        'type'   => ! empty( $this->data['titles']['knowledgegraph_type'] ) ? $this->data['titles']['knowledgegraph_type'] : null,
1✔
221
                        'name'   => ! empty( $this->data['titles']['knowledgegraph_name'] ) ? $this->data['titles']['knowledgegraph_name'] : null,
1✔
222
                        'url'    => ! empty( $this->data['titles']['url'] ) ? $this->data['titles']['url'] : null,
1✔
223
                        'logoId' => ! empty( $this->data['titles']['knowledgegraph_logo_id'] ) ? $this->data['titles']['knowledgegraph_logo_id'] : null,
1✔
224
                ];
1✔
225
        }
226

227
        /**
228
         * Resolve the titles and meta homepage fields.
229
         *
230
         * @return ?array<string, mixed>
231
         */
232
        private function meta_homepage_fields(): ?array {
233
                return 'page' !== get_option( 'show_on_front' ) ? [
1✔
234
                        'advancedRobotsMeta'  => $this->advanced_robots_meta( 'homepage_advanced_robots' ),
1✔
235
                        'description'         => ! empty( $this->data['titles']['homepage_description'] ) ? $this->data['titles']['author_archive_description'] : null,
1✔
236
                        'hasCustomRobotsMeta' => ! empty( $this->data['titles']['homepage_custom_robots'] ),
1✔
237
                        'robotsMeta'          => ! empty( $this->data['titles']['homepage_robots'] ) ? $this->data['titles']['homepage_robots'] : null,
1✔
238
                        'socialDescription'   => ! empty( $this->data['titles']['homepage_facebook_description'] ) ? $this->data['titles']['homepage_facebook_description'] : null,
1✔
239
                        'socialImageId'       => ! empty( $this->data['titles']['homepage_facebook_image_id'] ) ? $this->data['titles']['homepage_facebook_image_id'] : null,
1✔
240
                        'socialTitle'         => ! empty( $this->data['titles']['homepage_facebook_title'] ) ? $this->data['titles']['homepage_facebook_title'] : null,
1✔
241
                        'title'               => ! empty( $this->data['titles']['homepage_title'] ) ? $this->data['titles']['homepage_title'] : null,
1✔
242
                ] : null;
1✔
243
        }
244

245
        /**
246
         * Resolve the titles and meta date archive fields.
247
         *
248
         * @return array<string, mixed>
249
         */
250
        private function meta_date_archive_fields(): array {
251
                $has_archives = empty( $this->data['titles']['disable_date_archives'] );
1✔
252

253
                return [
1✔
254
                        'hasArchives'        => $has_archives,
1✔
255
                        'advancedRobotsMeta' => $has_archives ? $this->advanced_robots_meta( 'date_advanced_robots' ) : null,
1✔
256
                        'robotsMeta'         => $has_archives && ! empty( $this->data['titles']['date_archive_robots'] ) ? $this->data['titles']['date_archive_robots'] : null,
1✔
257
                        'archiveDescription' => $has_archives && ! empty( $this->data['titles']['date_archive_description'] ) ? $this->data['titles']['date_archive_description'] : null,
1✔
258
                        'archiveTitle'       => $has_archives && ! empty( $this->data['titles']['date_archive_title'] ) ? $this->data['titles']['date_archive_title'] : null,
1✔
259
                ];
1✔
260
        }
261

262
        /**
263
         * Resolve the titles and meta author archive fields.
264
         *
265
         * @return array<string, mixed>
266
         */
267
        private function meta_author_archive_fields(): array {
268
                $has_archives = empty( $this->data['titles']['disable_author_archives'] );
1✔
269
                return [
1✔
270
                        'advancedRobotsMeta'      => $has_archives ? $this->advanced_robots_meta( 'author_advanced_robots' ) : null,
1✔
271
                        'archiveDescription'      => $has_archives && ! empty( $this->data['titles']['author_archive_description'] ) ? $this->data['titles']['author_archive_description'] : null,
1✔
272
                        'archiveTitle'            => $has_archives && ! empty( $this->data['titles']['author_archive_title'] ) ? $this->data['titles']['author_archive_title'] : null,
1✔
273
                        'baseSlug'                => $has_archives && ! empty( $this->data['titles']['url_author_base'] ) ? $this->data['titles']['url_author_base'] : null,
1✔
274
                        'robotsMeta'              => $has_archives && ! empty( $this->data['titles']['author_robots'] ) ? $this->data['titles']['author_robots'] : null,
1✔
275
                        'hasArchives'             => $has_archives,
1✔
276
                        'hasCustomRobotsMeta'     => $has_archives && ! empty( $this->data['titles']['author_custom_robots'] ),
1✔
277
                        'hasSeoControls'          => $has_archives && ! empty( $this->data['titles']['author_add_meta_box'] ),
1✔
278
                        'hasSlackEnhancedSharing' => $has_archives && ! empty( $this->data['titles']['author_slack_enhanced_sharing'] ),
1✔
279
                ];
1✔
280
        }
281

282
        /**
283
         * Resolve the titles and meta for taxonomy fields.
284
         *
285
         * @return ?array<string, array<string,mixed>>
286
         */
287
        private function meta_taxonomy_fields(): ?array {
288
                /** @var string[] $taxonomies */
289
                $taxonomies = \WPGraphQL::get_allowed_taxonomies();
1✔
290

291
                $fields = [];
1✔
292

293
                foreach ( $taxonomies as $taxonomy ) {
1✔
294
                        $prefix = 'tax_' . $taxonomy;
1✔
295

296
                        $fields[ $taxonomy ] = [
1✔
297
                                'archiveTitle'            => ! empty( $this->data['titles'][ $prefix . '_archive_title' ] ) ? $this->data['titles'][ $prefix . '_archive_title' ] : null,
1✔
298
                                'archiveDescription'      => ! empty( $this->data['titles'][ $prefix . '_archive_description' ] ) ? $this->data['titles'][ $prefix . '_archive_description' ] : null,
1✔
299
                                'hasCustomRobotsMeta'     => ! empty( $this->data['titles'][ $prefix . '_custom_robots' ] ) ? $this->data['titles'][ $prefix . '_custom_robots' ] : null,
1✔
300
                                'robotsMeta'              => ! empty( $this->data['titles'][ $prefix . '_robots' ] ) ? $this->data['titles'][ $prefix . '_robots' ] : null,
1✔
301
                                'advancedRobotsMeta'      => $this->advanced_robots_meta( $prefix . '_advanced_robots' ),
1✔
302
                                'hasSlackEnhancedSharing' => ! empty( $this->data['titles'][ $prefix . '_slack_enhanced_sharing' ] ),
1✔
303
                                'hasSeoControls'          => ! empty( $this->data['titles'][ $prefix . '_add_meta_box' ] ),
1✔
304
                                'hasSnippetData'          => empty( $this->data['titles'][ 'remove_' . $taxonomy . '_snippet_data' ] ),
1✔
305
                        ];
1✔
306
                }
307

308
                return $fields ?: null;
1✔
309
        }
310

311
        /**
312
         * Resolve the titles and meta for post type fields.
313
         *
314
         * @return ?array<string, array<string,mixed>>
315
         */
316
        private function meta_content_type_fields(): ?array {
317
                /** @var string[] $post_types */
318
                $post_types = \WPGraphQL::get_allowed_post_types();
1✔
319

320
                $fields = [];
1✔
321

322
                foreach ( $post_types as $post_type ) {
1✔
323
                        $prefix = 'pt_' . $post_type;
1✔
324

325
                        $fields[ $post_type ] = [
1✔
326
                                'title'                   => ! empty( $this->data['titles'][ $prefix . '_title' ] ) ? $this->data['titles'][ $prefix . '_title' ] : null,
1✔
327
                                'description'             => ! empty( $this->data['titles'][ $prefix . '_description' ] ) ? $this->data['titles'][ $prefix . '_description' ] : null,
1✔
328
                                'archiveTitle'            => ! empty( $this->data['titles'][ $prefix . '_archive_title' ] ) ? $this->data['titles'][ $prefix . '_archive_title' ] : null,
1✔
329
                                'archiveDescription'      => ! empty( $this->data['titles'][ $prefix . '_archive_description' ] ) ? $this->data['titles'][ $prefix . '_archive_description' ] : null,
1✔
330
                                'snippetType'             => ! empty( $this->data['titles'][ $prefix . '_default_rich_snippet' ] ) ? $this->data['titles'][ $prefix . '_default_rich_snippet' ] : null,
1✔
331
                                'snippetHeadline'         => ! empty( $this->data['titles'][ $prefix . '_default_snippet_name' ] ) ? $this->data['titles'][ $prefix . '_default_snippet_name' ] : null,
1✔
332
                                'snippetDescription'      => ! empty( $this->data['titles'][ $prefix . '_default_snippet_desc' ] ) ? $this->data['titles'][ $prefix . '_default_snippet_desc' ] : null,
1✔
333
                                'articleType'             => ! empty( $this->data['titles'][ $prefix . '_default_article_type' ] ) ? $this->data['titles'][ $prefix . '_default_article_type' ] : null,
1✔
334
                                'hasCustomRobotsMeta'     => ! empty( $this->data['titles'][ $prefix . '_custom_robots' ] ) ? $this->data['titles'][ $prefix . '_custom_robots' ] : null,
1✔
335
                                'robotsMeta'              => ! empty( $this->data['titles'][ $prefix . '_robots' ] ) ? $this->data['titles'][ $prefix . '_robots' ] : null,
1✔
336
                                'advancedRobotsMeta'      => $this->advanced_robots_meta( $prefix . '_advanced_robots' ),
1✔
337
                                'hasLinkSuggestions'      => ! empty( $this->data['titles'][ $prefix . '_link_suggestions' ] ),
1✔
338
                                'shouldUseFocusKeyword'   => ! empty( $this->data['titles'][ $prefix . '_ls_use_fk' ] ),
1✔
339
                                'socialImage'             => ! empty( $this->data['titles'][ $prefix . '_facebook_image_id' ] ),
1✔
340
                                'hasBulkEditing'          => ! empty( $this->data['titles'][ $prefix . '_bulk_editing' ] ) ? $this->data['titles'][ $prefix . '_bulk_editing' ] : null,
1✔
341
                                'hasSlackEnhancedSharing' => ! empty( $this->data['titles'][ $prefix . '_slack_enhanced_sharing' ] ),
1✔
342
                                'hasSeoControls'          => ! empty( $this->data['titles'][ $prefix . '_add_meta_box' ] ),
1✔
343
                                'analyzedFields'          => ! empty( $this->data['titles'][ $prefix . '_analyze_fields' ] ) ? $this->data['titles'][ $prefix . '_analyze_fields' ] : null,
1✔
344
                                'primaryTaxonomy'         => ! empty( $this->data['titles'][ $prefix . '_primary_taxonomy' ] ) ? $this->data['titles'][ $prefix . '_primary_taxonomy' ] : null,
1✔
345
                        ];
1✔
346
                }
347

348
                return $fields ?: null;
1✔
349
        }
350

351
        /**
352
         * Resolve the sitemap general settings.
353
         *
354
         * @return array<string, mixed>
355
         */
356
        private function sitemap_general_fields(): array {
357
                return [
1✔
358
                        'canPingSearchEngines'    => ! empty( $this->data['sitemap']['ping_search_engines'] ),
1✔
359
                        'excludedPostDatabaseIds' => ! empty( $this->data['sitemap']['exclude_posts'] ) ? array_map( 'absint', explode( ',', $this->data['sitemap']['exclude_posts'] ) ) : null,
1✔
360
                        'excludedTermDatabaseIds' => ! empty( $this->data['sitemap']['exclude_terms'] ) ? array_map( 'absint', explode( ',', $this->data['sitemap']['exclude_terms'] ) ) : null,
1✔
361
                        'hasFeaturedImage'        => ! empty( $this->data['sitemap']['include_featured_image'] ),
1✔
362
                        'hasImages'               => ! empty( $this->data['sitemap']['include_images'] ),
1✔
363
                        'linksPerSitemap'         => ! empty( $this->data['sitemap']['items_per_page'] ) ? absint( $this->data['sitemap']['items_per_page'] ) : null,
1✔
364
                ];
1✔
365
        }
366

367
        /**
368
         * Resolve the sitemap general settings.
369
         *
370
         * @return array<string, mixed>
371
         */
372
        private function sitemap_author_fields(): ?array {
373
                if ( ! Helper::is_author_archive_indexable() ) {
1✔
374
                        return null;
×
375
                }
376

377
                return [
1✔
378
                        'excludedRoles'           => function () {
1✔
379
                                if ( empty( $this->data['sitemap']['exclude_roles'] ) ) {
1✔
380
                                        return null;
×
381
                                }
382

383
                                $roles = array_keys( $this->data['sitemap']['exclude_roles'] );
1✔
384

385
                                if ( ! is_string( $roles[0] ) ) {
1✔
386
                                        $roles = array_values( $this->data['sitemap']['exclude_roles'] );
×
387
                                }
388

389
                                return ! empty( $roles ) ? $roles : null;
1✔
390
                        },
1✔
391
                        'excludedUserDatabaseIds' => ! empty( $this->data['sitemap']['exclude_users'] ) ? array_map( 'absint', explode( ',', $this->data['sitemap']['exclude_users'] ) ) : null,
1✔
392
                        'sitemapUrl'              => Router::get_base_url( 'author-sitemap.xml' ),
1✔
393
                ];
1✔
394
        }
395

396
        /**
397
         * Resolve the sitemap post type settings.
398
         *
399
         * @return ?array<string, mixed>
400
         */
401
        private function sitemap_content_type_fields(): ?array {
402
                /** @var string[] $post_types */
403
                $post_types = \WPGraphQL::get_allowed_post_types();
1✔
404

405
                $fields = [];
1✔
406

407
                foreach ( $post_types as $post_type ) {
1✔
408
                        $prefix = 'pt_' . $post_type;
1✔
409

410
                        $fields[ $post_type ] = [
1✔
411
                                'customImageMetaKeys' => ! empty( $this->data['sitemap'][ $prefix . '_image_customfields' ] ) ? preg_split( '/\r\n|\r|\n/', $this->data['sitemap'][ $prefix . '_image_customfields' ] ) : null,
1✔
412
                                'isInSitemap'         => ! empty( $this->data['sitemap'][ $prefix . '_sitemap' ] ),
1✔
413
                                'sitemapUrl'          => ! empty( $this->data['sitemap'][ $prefix . '_sitemap' ] ) ? Router::get_base_url( $post_type . '-sitemap.xml' ) : null,
1✔
414
                                'type'                => $post_type,
1✔
415
                        ];
1✔
416
                }
417

418
                return $fields ?: null;
1✔
419
        }
420

421
        /**
422
         * Resolve the sitemap taxonomy settings.
423
         *
424
         * @return array<string, array<string,mixed>>
425
         */
426
        private function sitemap_taxonomy_fields(): ?array {
427
                /** @var string[] $taxonomies */
428
                $taxonomies = \WPGraphQL::get_allowed_taxonomies();
1✔
429

430
                $fields = [];
1✔
431

432
                foreach ( $taxonomies as $taxonomy ) {
1✔
433
                        $prefix = 'tax_' . $taxonomy;
1✔
434

435
                        $fields[ $taxonomy ] = [
1✔
436
                                'hasEmptyTerms' => ! empty( $this->data['sitemap'][ $prefix . '_include_empty' ] ),
1✔
437
                                'isInSitemap'   => ! empty( $this->data['sitemap'][ $prefix . '_sitemap' ] ),
1✔
438
                                'sitemapUrl'    => ! empty( $this->data['sitemap'][ $prefix . '_sitemap' ] ) ? Router::get_base_url( $taxonomy . '-sitemap.xml' ) : null,
1✔
439
                                'type'          => $taxonomy,
1✔
440

441
                        ];
1✔
442
                }
443

444
                return $fields ?: null;
1✔
445
        }
446
}
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