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

AxeWP / wp-graphql-rank-math / 5034017066

pending completion
5034017066

push

github

GitHub
release: v0.0.12 (#49)

2001 of 2307 relevant lines covered (86.74%)

5.47 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 WPGraphQL\Model\Model;
12
use RankMath\Helper;
13
use RankMath\Sitemap\Router;
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
        /**
35
         * Constructor.
36
         *
37
         * @throws \Exception .
38
         */
39
        public function __construct() {
40
                /** @property \RankMath\Settings $settings_obj */
41
                $settings_obj = rank_math()->settings;
3✔
42
                $settings     = $settings_obj->all();
3✔
43

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

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

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

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

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

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

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

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

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

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

193
        /**
194
         * Resolve titles and meta social fields.
195
         */
196
        private function meta_social_fields() : array {
197
                return [
1✔
198
                        'facebookPageUrl'   => ! empty( $this->data['titles']['social_url_facebook'] ) ? $this->data['titles']['social_url_facebook'] : null,
1✔
199
                        'facebookAuthorUrl' => ! empty( $this->data['titles']['facebook_author_urls'] ) ? $this->data['titles']['facebook_author_urls'] : null,
1✔
200
                        'facebookAdminId'   => ! empty( $this->data['titles']['facebook_admin_id'] ) ? $this->data['titles']['facebook_admin_id'] : null,
1✔
201
                        'facebookAppId'     => ! empty( $this->data['titles']['facebook_app_id'] ) ? $this->data['titles']['facebook_app_id'] : null,
1✔
202
                        'twitterAuthorName' => ! empty( $this->data['titles']['twitter_author_names'] ) ? $this->data['titles']['twitter_author_names'] : null,
1✔
203
                ];
1✔
204
        }
205

206
        /**
207
         * Resolve titles and meta local fields.
208
         */
209
        private function meta_local_fields() : array {
210
                return [
1✔
211
                        'type'   => ! empty( $this->data['titles']['knowledgegraph_type'] ) ? $this->data['titles']['knowledgegraph_type'] : null,
1✔
212
                        'name'   => ! empty( $this->data['titles']['knowledgegraph_name'] ) ? $this->data['titles']['knowledgegraph_name'] : null,
1✔
213
                        'url'    => ! empty( $this->data['titles']['url'] ) ? $this->data['titles']['url'] : null,
1✔
214
                        'logoId' => ! empty( $this->data['titles']['knowledgegraph_logo_id'] ) ? $this->data['titles']['knowledgegraph_logo_id'] : null,
1✔
215
                ];
1✔
216
        }
217

218
        /**
219
         * Resolve the titles and meta homepage fields.
220
         */
221
        private function meta_homepage_fields() : ?array {
222
                return 'page' !== get_option( 'show_on_front' ) ? [
1✔
223
                        'advancedRobotsMeta'  => $this->advanced_robots_meta( 'homepage_advanced_robots' ),
1✔
224
                        'description'         => ! empty( $this->data['titles']['homepage_description'] ) ? $this->data['titles']['author_archive_description'] : null,
1✔
225
                        'hasCustomRobotsMeta' => ! empty( $this->data['titles']['homepage_custom_robots'] ),
1✔
226
                        'robotsMeta'          => ! empty( $this->data['titles']['homepage_robots'] ) ? $this->data['titles']['homepage_robots'] : null,
1✔
227
                        'socialDescription'   => ! empty( $this->data['titles']['homepage_facebook_description'] ) ? $this->data['titles']['homepage_facebook_description'] : null,
1✔
228
                        'socialImageId'       => ! empty( $this->data['titles']['homepage_facebook_image_id'] ) ? $this->data['titles']['homepage_facebook_image_id'] : null,
1✔
229
                        'socialTitle'         => ! empty( $this->data['titles']['homepage_facebook_title'] ) ? $this->data['titles']['homepage_facebook_title'] : null,
1✔
230
                        'title'               => ! empty( $this->data['titles']['homepage_title'] ) ? $this->data['titles']['homepage_title'] : null,
1✔
231
                ] : null;
1✔
232
        }
233

234
        /**
235
         * Resolve the titles and meta date archive fields.
236
         */
237
        private function meta_date_archive_fields() : array {
238
                $has_archives = empty( $this->data['titles']['disable_date_archives'] );
1✔
239

240
                return [
1✔
241
                        'hasArchives'        => $has_archives,
1✔
242
                        'advancedRobotsMeta' => $has_archives ? $this->advanced_robots_meta( 'date_advanced_robots' ) : null,
1✔
243
                        'robotsMeta'         => $has_archives && ! empty( $this->data['titles']['date_archive_robots'] ) ? $this->data['titles']['date_archive_robots'] : null,
1✔
244
                        'archiveDescription' => $has_archives && ! empty( $this->data['titles']['date_archive_description'] ) ? $this->data['titles']['date_archive_description'] : null,
1✔
245
                        'archiveTitle'       => $has_archives && ! empty( $this->data['titles']['date_archive_title'] ) ? $this->data['titles']['date_archive_title'] : null,
1✔
246
                ];
1✔
247
        }
248

249
        /**
250
         * Resolve the titles and meta author archive fields.
251
         */
252
        private function meta_author_archive_fields() : array {
253
                $has_archives = empty( $this->data['titles']['disable_author_archives'] );
1✔
254
                return [
1✔
255
                        'advancedRobotsMeta'      => $has_archives ? $this->advanced_robots_meta( 'author_advanced_robots' ) : null,
1✔
256
                        'archiveDescription'      => $has_archives && ! empty( $this->data['titles']['author_archive_description'] ) ? $this->data['titles']['author_archive_description'] : null,
1✔
257
                        'archiveTitle'            => $has_archives && ! empty( $this->data['titles']['author_archive_title'] ) ? $this->data['titles']['author_archive_title'] : null,
1✔
258
                        'baseSlug'                => $has_archives && ! empty( $this->data['titles']['url_author_base'] ) ? $this->data['titles']['url_author_base'] : null,
1✔
259
                        'robotsMeta'              => $has_archives && ! empty( $this->data['titles']['author_robots'] ) ? $this->data['titles']['author_robots'] : null,
1✔
260
                        'hasArchives'             => $has_archives,
1✔
261
                        'hasCustomRobotsMeta'     => $has_archives && ! empty( $this->data['titles']['author_custom_robots'] ),
1✔
262
                        'hasSeoControls'          => $has_archives && ! empty( $this->data['titles']['author_add_meta_box'] ),
1✔
263
                        'hasSlackEnhancedSharing' => $has_archives && ! empty( $this->data['titles']['author_slack_enhanced_sharing'] ),
1✔
264
                ];
1✔
265
        }
266

267
        /**
268
         * Resolve the titles and meta for taxonomy fields.
269
         */
270
        private function meta_taxonomy_fields() : array {
271
                $taxonomies = \WPGraphQL::get_allowed_taxonomies();
1✔
272

273
                $fields = [];
1✔
274

275
                foreach ( $taxonomies as $taxonomy ) {
1✔
276
                        $prefix = 'tax_' . $taxonomy;
1✔
277

278
                        $fields[ $taxonomy ] = [
1✔
279
                                'archiveTitle'            => ! empty( $this->data['titles'][ $prefix . '_archive_title' ] ) ? $this->data['titles'][ $prefix . '_archive_title' ] : null,
1✔
280
                                'archiveDescription'      => ! empty( $this->data['titles'][ $prefix . '_archive_description' ] ) ? $this->data['titles'][ $prefix . '_archive_description' ] : null,
1✔
281
                                'hasCustomRobotsMeta'     => ! empty( $this->data['titles'][ $prefix . '_custom_robots' ] ) ? $this->data['titles'][ $prefix . '_custom_robots' ] : null,
1✔
282
                                'robotsMeta'              => ! empty( $this->data['titles'][ $prefix . '_robots' ] ) ? $this->data['titles'][ $prefix . '_robots' ] : null,
1✔
283
                                'advancedRobotsMeta'      => $this->advanced_robots_meta( $prefix . '_advanced_robots' ),
1✔
284
                                'hasSlackEnhancedSharing' => ! empty( $this->data['titles'][ $prefix . '_slack_enhanced_sharing' ] ),
1✔
285
                                'hasSeoControls'          => ! empty( $this->data['titles'][ $prefix . '_add_meta_box' ] ),
1✔
286
                                'hasSnippetData'          => empty( $this->data['titles'][ 'remove_' . $taxonomy . '_snippet_data' ] ),
1✔
287
                        ];
1✔
288
                }
289

290
                return $fields;
1✔
291
        }
292

293
        /**
294
         * Resolve the titles and meta for post type fields.
295
         */
296
        private function meta_content_type_fields() : array {
297
                $post_types = \WPGraphQL::get_allowed_post_types();
1✔
298

299
                $fields = [];
1✔
300

301
                foreach ( $post_types as $post_type ) {
1✔
302
                        $prefix = 'pt_' . $post_type;
1✔
303

304
                        $fields[ $post_type ] = [
1✔
305
                                'title'                   => ! empty( $this->data['titles'][ $prefix . '_title' ] ) ? $this->data['titles'][ $prefix . '_title' ] : null,
1✔
306
                                'description'             => ! empty( $this->data['titles'][ $prefix . '_description' ] ) ? $this->data['titles'][ $prefix . '_description' ] : null,
1✔
307
                                'archiveTitle'            => ! empty( $this->data['titles'][ $prefix . '_archive_title' ] ) ? $this->data['titles'][ $prefix . '_archive_title' ] : null,
1✔
308
                                'archiveDescription'      => ! empty( $this->data['titles'][ $prefix . '_archive_description' ] ) ? $this->data['titles'][ $prefix . '_archive_description' ] : null,
1✔
309
                                'snippetType'             => ! empty( $this->data['titles'][ $prefix . '_default_rich_snippet' ] ) ? $this->data['titles'][ $prefix . '_default_rich_snippet' ] : null,
1✔
310
                                'snippetHeadline'         => ! empty( $this->data['titles'][ $prefix . '_default_snippet_name' ] ) ? $this->data['titles'][ $prefix . '_default_snippet_name' ] : null,
1✔
311
                                'snippetDescription'      => ! empty( $this->data['titles'][ $prefix . '_default_snippet_desc' ] ) ? $this->data['titles'][ $prefix . '_default_snippet_desc' ] : null,
1✔
312
                                'articleType'             => ! empty( $this->data['titles'][ $prefix . '_default_article_type' ] ) ? $this->data['titles'][ $prefix . '_default_article_type' ] : null,
1✔
313
                                'hasCustomRobotsMeta'     => ! empty( $this->data['titles'][ $prefix . '_custom_robots' ] ) ? $this->data['titles'][ $prefix . '_custom_robots' ] : null,
1✔
314
                                'robotsMeta'              => ! empty( $this->data['titles'][ $prefix . '_robots' ] ) ? $this->data['titles'][ $prefix . '_robots' ] : null,
1✔
315
                                'advancedRobotsMeta'      => $this->advanced_robots_meta( $prefix . '_advanced_robots' ),
1✔
316
                                'hasLinkSuggestions'      => ! empty( $this->data['titles'][ $prefix . '_link_suggestions' ] ),
1✔
317
                                'shouldUseFocusKeyword'   => ! empty( $this->data['titles'][ $prefix . '_ls_use_fk' ] ),
1✔
318
                                'socialImage'             => ! empty( $this->data['titles'][ $prefix . '_facebook_image_id' ] ),
1✔
319
                                'hasBulkEditing'          => ! empty( $this->data['titles'][ $prefix . '_bulk_editing' ] ) ? $this->data['titles'][ $prefix . '_bulk_editing' ] : null,
1✔
320
                                'hasSlackEnhancedSharing' => ! empty( $this->data['titles'][ $prefix . '_slack_enhanced_sharing' ] ),
1✔
321
                                'hasSeoControls'          => ! empty( $this->data['titles'][ $prefix . '_add_meta_box' ] ),
1✔
322
                                'analyzedFields'          => ! empty( $this->data['titles'][ $prefix . '_analyze_fields' ] ) ? $this->data['titles'][ $prefix . '_analyze_fields' ] : null,
1✔
323
                                'primaryTaxonomy'         => ! empty( $this->data['titles'][ $prefix . '_primary_taxonomy' ] ) ? $this->data['titles'][ $prefix . '_primary_taxonomy' ] : null,
1✔
324
                        ];
1✔
325
                }
326

327
                return $fields;
1✔
328
        }
329

330
        /**
331
         * Resolve the sitemap general settings.
332
         */
333
        private function sitemap_general_fields() : array {
334
                return [
1✔
335
                        'canPingSearchEngines'    => ! empty( $this->data['sitemap']['ping_search_engines'] ),
1✔
336
                        'excludedPostDatabaseIds' => ! empty( $this->data['sitemap']['exclude_posts'] ) ? array_map( 'absint', explode( ',', $this->data['sitemap']['exclude_posts'] ) ) : null,
1✔
337
                        'excludedTermDatabaseIds' => ! empty( $this->data['sitemap']['exclude_terms'] ) ? array_map( 'absint', explode( ',', $this->data['sitemap']['exclude_terms'] ) ) : null,
1✔
338
                        'hasFeaturedImage'        => ! empty( $this->data['sitemap']['include_featured_image'] ),
1✔
339
                        'hasImages'               => ! empty( $this->data['sitemap']['include_images'] ),
1✔
340
                        'linksPerSitemap'         => ! empty( $this->data['sitemap']['items_per_page'] ) ? absint( $this->data['sitemap']['items_per_page'] ) : null,
1✔
341
                ];
1✔
342
        }
343

344
        /**
345
         * Resolve the sitemap general settings.
346
         */
347
        private function sitemap_author_fields() : ?array {
348
                if ( ! Helper::is_author_archive_indexable() ) {
1✔
349
                        return null;
×
350
                }
351

352
                return [
1✔
353
                        'excludedRoles'           => function() {
1✔
354
                                if ( empty( $this->data['sitemap']['exclude_roles'] ) ) {
1✔
355
                                        return null;
×
356
                                }
357

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

360
                                if ( ! is_string( $roles[0] ) ) {
1✔
361
                                        $roles = array_values( $this->data['sitemap']['exclude_roles'] );
×
362
                                }
363

364
                                return ! empty( $roles ) ? $roles : null;
1✔
365
                        },
1✔
366
                        'excludedUserDatabaseIds' => ! empty( $this->data['sitemap']['exclude_users'] ) ? array_map( 'absint', explode( ',', $this->data['sitemap']['exclude_users'] ) ) : null,
1✔
367
                        'sitemapUrl'              => Router::get_base_url( 'author-sitemap.xml' ),
1✔
368
                ];
1✔
369
        }
370

371
        /**
372
         * Resolve the sitemap post type settings.
373
         */
374
        private function sitemap_content_type_fields() : array {
375
                $post_types = \WPGraphQL::get_allowed_post_types();
1✔
376

377
                $fields = [];
1✔
378

379
                foreach ( $post_types as $post_type ) {
1✔
380
                        $prefix = 'pt_' . $post_type;
1✔
381

382
                        $fields[ $post_type ] = [
1✔
383
                                'customImageMetaKeys' => ! empty( $this->data['sitemap'][ $prefix . '_image_customfields' ] ) ? preg_split( '/\r\n|\r|\n/', $this->data['sitemap'][ $prefix . '_image_customfields' ] ) : null,
1✔
384
                                'isInSitemap'         => ! empty( $this->data['sitemap'][ $prefix . '_sitemap' ] ),
1✔
385
                                'sitemapUrl'          => ! empty( $this->data['sitemap'][ $prefix . '_sitemap' ] ) ? Router::get_base_url( $post_type . '-sitemap.xml' ) : null,
1✔
386
                                'type'                => $post_type,
1✔
387
                        ];
1✔
388
                }
389

390
                return $fields;
1✔
391
        }
392

393
        /**
394
         * Resolve the sitemap taxonomy settings.
395
         */
396
        private function sitemap_taxonomy_fields() : array {
397
                $taxonomies = \WPGraphQL::get_allowed_taxonomies();
1✔
398

399
                $fields = [];
1✔
400

401
                foreach ( $taxonomies as $taxonomy ) {
1✔
402
                        $prefix = 'tax_' . $taxonomy;
1✔
403

404
                        $fields[ $taxonomy ] = [
1✔
405
                                'hasEmptyTerms' => ! empty( $this->data['sitemap'][ $prefix . '_include_empty' ] ),
1✔
406
                                'isInSitemap'   => ! empty( $this->data['sitemap'][ $prefix . '_sitemap' ] ),
1✔
407
                                'sitemapUrl'    => ! empty( $this->data['sitemap'][ $prefix . '_sitemap' ] ) ? Router::get_base_url( $taxonomy . '-sitemap.xml' ) : null,
1✔
408
                                'type'          => $taxonomy,
1✔
409

410
                        ];
1✔
411
                }
412

413
                return $fields;
1✔
414
        }
415
}
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