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

AxeWP / wp-graphql-rank-math / 6257335822

21 Sep 2023 04:53AM UTC coverage: 92.176%. First build
6257335822

Pull #59

github

web-flow
Merge e6916cad3 into a7f39383c
Pull Request #59: chore: Update dev-deps and lint

24 of 24 new or added lines in 11 files covered. (100.0%)

2533 of 2748 relevant lines covered (92.18%)

11.22 hits per line

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

94.31
/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;
4✔
41
                $settings     = $settings_obj->all();
4✔
42

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

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

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

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

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

81
                        if ( in_array( 'sitemap', $this->active_modules, true ) ) {
4✔
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 [
2✔
100
                        'breadcrumbs'         => function (): array {
2✔
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
                        },
2✔
129
                        'frontendSeoScore'    => [
2✔
130
                                'enabledPostTypes'    => ! empty( $this->data['general']['frontend_seo_score_post_types'] ) ? $this->data['general']['frontend_seo_score_post_types'] : null,
2✔
131
                                'template'            => ! empty( $this->data['general']['frontend_seo_score_template'] ) ? $this->data['general']['frontend_seo_score_template'] : null,
2✔
132
                                'position'            => ! empty( $this->data['general']['frontend_seo_score_position'] ) ? $this->data['general']['frontend_seo_score_position'] : null,
2✔
133
                                'hasRankMathBacklink' => ! empty( $this->data['general']['support_rank_math'] ),
2✔
134
                        ],
2✔
135
                        'hasBreadcrumbs'      => ! empty( $this->data['general']['breadcrumbs'] ),
2✔
136
                        'hasFrontendSeoScore' => ! empty( $this->data['general']['frontend_seo_score'] ),
2✔
137
                        'links'               => [
2✔
138
                                'defaultAttachmentRedirectUrl' => ! empty( $this->data['general']['attachment_redirect_default'] ) ? $this->data['general']['attachment_redirect_default'] : null,
2✔
139
                                'hasCategoryBase'              => empty( $this->data['general']['strip_category_base'] ),
2✔
140
                                'nofollowDomains'              => ! empty( $this->data['general']['nofollow_domains'] ) ? $this->data['general']['nofollow_domains'] : null,
2✔
141
                                'nofollowExcludedDomains'      => ! empty( $this->data['general']['nofollow_exclude_domains'] ) ? $this->data['general']['nofollow_exclude_domains'] : null,
2✔
142
                                'shouldNofollowImageLinks'     => ! empty( $this->data['general']['nofollow_image_links'] ),
2✔
143
                                'shouldNofollowLinks'          => ! empty( $this->data['general']['nofollow_external_links'] ),
2✔
144
                                'shouldOpenInNewWindow'        => ! empty( $this->data['general']['new_window_external_links'] ),
2✔
145
                                'shouldRedirectAttachments'    => ! empty( $this->data['general']['attachment_redirect_urls'] ),
2✔
146
                        ],
2✔
147
                        'webmaster'           => [
2✔
148
                                'baidu'     => ! empty( $this->data['general']['baidu_verify'] ) ? $this->data['general']['baidu_verify'] : null,
2✔
149
                                'bing'      => ! empty( $this->data['general']['bing_verify'] ) ? $this->data['general']['bing_verify'] : null,
2✔
150
                                'google'    => ! empty( $this->data['general']['google_verify'] ) ? $this->data['general']['google_verify'] : null,
2✔
151
                                'norton'    => ! empty( $this->data['general']['norton_verify'] ) ? $this->data['general']['norton_verify'] : null,
2✔
152
                                'pinterest' => ! empty( $this->data['general']['pinterest_verify'] ) ? $this->data['general']['pinterest_verify'] : null,
2✔
153
                                'yandex'    => ! empty( $this->data['general']['yandex_verify'] ) ? $this->data['general']['yandex_verify'] : null,
2✔
154
                        ],
2✔
155
                        'rssBeforeContent'    => ! empty( $this->data['general']['rss_before_content'] ) ? $this->data['general']['rss_before_content'] : null,
2✔
156
                        'rssAfterContent'     => ! empty( $this->data['general']['rss_after_content'] ) ? $this->data['general']['rss_after_content'] : null,
2✔
157
                        'redirections'        => [
2✔
158
                                'hasDebug'          => ! empty( $this->data['general']['redirect_debug'] ),
2✔
159
                                'fallbackBehavior'  => ! empty( $this->data['general']['redirections_fallback'] ) ? $this->data['general']['redirections_fallback'] : 'default',
2✔
160
                                'fallbackCustomUrl' => ! empty( $this->data['general']['redirections_custom_url'] ) ? $this->data['general']['redirections_custom_url'] : null,
2✔
161
                                'redirectionType'   => ! empty( $this->data['general']['redirections_header_code'] ) ? $this->data['general']['redirections_header_code'] : '301',
2✔
162
                                'hasAutoPostDirect' => ! empty( $this->data['general']['redirections_post_redirect'] ),
2✔
163
                        ],
2✔
164
                ];
2✔
165
        }
166

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

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

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

220
        /**
221
         * Resolve titles and meta local fields.
222
         *
223
         * @return array<string, mixed>
224
         */
225
        private function meta_local_fields(): array {
226
                return [
1✔
227
                        'type'   => ! empty( $this->data['titles']['knowledgegraph_type'] ) ? $this->data['titles']['knowledgegraph_type'] : null,
1✔
228
                        'name'   => ! empty( $this->data['titles']['knowledgegraph_name'] ) ? $this->data['titles']['knowledgegraph_name'] : null,
1✔
229
                        'url'    => ! empty( $this->data['titles']['url'] ) ? $this->data['titles']['url'] : null,
1✔
230
                        'logoId' => ! empty( $this->data['titles']['knowledgegraph_logo_id'] ) ? $this->data['titles']['knowledgegraph_logo_id'] : null,
1✔
231
                ];
1✔
232
        }
233

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

252
        /**
253
         * Resolve the titles and meta date archive fields.
254
         *
255
         * @return array<string, mixed>
256
         */
257
        private function meta_date_archive_fields(): array {
258
                $has_archives = empty( $this->data['titles']['disable_date_archives'] );
1✔
259

260
                return [
1✔
261
                        'hasArchives'        => $has_archives,
1✔
262
                        'advancedRobotsMeta' => $has_archives ? $this->advanced_robots_meta( 'date_advanced_robots' ) : null,
1✔
263
                        'robotsMeta'         => $has_archives && ! empty( $this->data['titles']['date_archive_robots'] ) ? $this->data['titles']['date_archive_robots'] : null,
1✔
264
                        'archiveDescription' => $has_archives && ! empty( $this->data['titles']['date_archive_description'] ) ? $this->data['titles']['date_archive_description'] : null,
1✔
265
                        'archiveTitle'       => $has_archives && ! empty( $this->data['titles']['date_archive_title'] ) ? $this->data['titles']['date_archive_title'] : null,
1✔
266
                ];
1✔
267
        }
268

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

289
        /**
290
         * Resolve the titles and meta for taxonomy fields.
291
         *
292
         * @return ?array<string, array<string,mixed>>
293
         */
294
        private function meta_taxonomy_fields(): ?array {
295
                /** @var string[] $taxonomies */
296
                $taxonomies = \WPGraphQL::get_allowed_taxonomies();
1✔
297

298
                $fields = [];
1✔
299

300
                foreach ( $taxonomies as $taxonomy ) {
1✔
301
                        $prefix = 'tax_' . $taxonomy;
1✔
302

303
                        $fields[ $taxonomy ] = [
1✔
304
                                'archiveTitle'            => ! empty( $this->data['titles'][ $prefix . '_archive_title' ] ) ? $this->data['titles'][ $prefix . '_archive_title' ] : null,
1✔
305
                                'archiveDescription'      => ! empty( $this->data['titles'][ $prefix . '_archive_description' ] ) ? $this->data['titles'][ $prefix . '_archive_description' ] : null,
1✔
306
                                'hasCustomRobotsMeta'     => ! empty( $this->data['titles'][ $prefix . '_custom_robots' ] ) ? $this->data['titles'][ $prefix . '_custom_robots' ] : null,
1✔
307
                                'robotsMeta'              => ! empty( $this->data['titles'][ $prefix . '_robots' ] ) ? $this->data['titles'][ $prefix . '_robots' ] : null,
1✔
308
                                'advancedRobotsMeta'      => $this->advanced_robots_meta( $prefix . '_advanced_robots' ),
1✔
309
                                'hasSlackEnhancedSharing' => ! empty( $this->data['titles'][ $prefix . '_slack_enhanced_sharing' ] ),
1✔
310
                                'hasSeoControls'          => ! empty( $this->data['titles'][ $prefix . '_add_meta_box' ] ),
1✔
311
                                'hasSnippetData'          => empty( $this->data['titles'][ 'remove_' . $taxonomy . '_snippet_data' ] ),
1✔
312
                        ];
1✔
313
                }
314

315
                return $fields ?: null;
1✔
316
        }
317

318
        /**
319
         * Resolve the titles and meta for post type fields.
320
         *
321
         * @return ?array<string, array<string,mixed>>
322
         */
323
        private function meta_content_type_fields(): ?array {
324
                /** @var string[] $post_types */
325
                $post_types = \WPGraphQL::get_allowed_post_types();
1✔
326

327
                $fields = [];
1✔
328

329
                foreach ( $post_types as $post_type ) {
1✔
330
                        $prefix = 'pt_' . $post_type;
1✔
331

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

355
                return $fields ?: null;
1✔
356
        }
357

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

374
        /**
375
         * Resolve the sitemap general settings.
376
         *
377
         * @return array<string, mixed>
378
         */
379
        private function sitemap_author_fields(): ?array {
380
                if ( ! Helper::is_author_archive_indexable() ) {
1✔
381
                        return null;
×
382
                }
383

384
                return [
1✔
385
                        'excludedRoles'           => function () {
1✔
386
                                if ( empty( $this->data['sitemap']['exclude_roles'] ) ) {
1✔
387
                                        return null;
×
388
                                }
389

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

392
                                if ( ! is_string( $roles[0] ) ) {
1✔
393
                                        $roles = array_values( $this->data['sitemap']['exclude_roles'] );
×
394
                                }
395

396
                                return ! empty( $roles ) ? $roles : null;
1✔
397
                        },
1✔
398
                        'excludedUserDatabaseIds' => ! empty( $this->data['sitemap']['exclude_users'] ) ? array_map( 'absint', explode( ',', $this->data['sitemap']['exclude_users'] ) ) : null,
1✔
399
                        'sitemapUrl'              => Router::get_base_url( 'author-sitemap.xml' ),
1✔
400
                ];
1✔
401
        }
402

403
        /**
404
         * Resolve the sitemap post type settings.
405
         *
406
         * @return ?array<string, mixed>
407
         */
408
        private function sitemap_content_type_fields(): ?array {
409
                /** @var string[] $post_types */
410
                $post_types = \WPGraphQL::get_allowed_post_types();
1✔
411

412
                $fields = [];
1✔
413

414
                foreach ( $post_types as $post_type ) {
1✔
415
                        $prefix = 'pt_' . $post_type;
1✔
416

417
                        $fields[ $post_type ] = [
1✔
418
                                'customImageMetaKeys' => ! empty( $this->data['sitemap'][ $prefix . '_image_customfields' ] ) ? preg_split( '/\r\n|\r|\n/', $this->data['sitemap'][ $prefix . '_image_customfields' ] ) : null,
1✔
419
                                'isInSitemap'         => ! empty( $this->data['sitemap'][ $prefix . '_sitemap' ] ),
1✔
420
                                'sitemapUrl'          => ! empty( $this->data['sitemap'][ $prefix . '_sitemap' ] ) ? Router::get_base_url( $post_type . '-sitemap.xml' ) : null,
1✔
421
                                'type'                => $post_type,
1✔
422
                        ];
1✔
423
                }
424

425
                return $fields ?: null;
1✔
426
        }
427

428
        /**
429
         * Resolve the sitemap taxonomy settings.
430
         *
431
         * @return array<string, array<string,mixed>>
432
         */
433
        private function sitemap_taxonomy_fields(): ?array {
434
                /** @var string[] $taxonomies */
435
                $taxonomies = \WPGraphQL::get_allowed_taxonomies();
1✔
436

437
                $fields = [];
1✔
438

439
                foreach ( $taxonomies as $taxonomy ) {
1✔
440
                        $prefix = 'tax_' . $taxonomy;
1✔
441

442
                        $fields[ $taxonomy ] = [
1✔
443
                                'hasEmptyTerms' => ! empty( $this->data['sitemap'][ $prefix . '_include_empty' ] ),
1✔
444
                                'isInSitemap'   => ! empty( $this->data['sitemap'][ $prefix . '_sitemap' ] ),
1✔
445
                                'sitemapUrl'    => ! empty( $this->data['sitemap'][ $prefix . '_sitemap' ] ) ? Router::get_base_url( $taxonomy . '-sitemap.xml' ) : null,
1✔
446
                                'type'          => $taxonomy,
1✔
447

448
                        ];
1✔
449
                }
450

451
                return $fields ?: null;
1✔
452
        }
453
}
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