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

Yoast / wordpress-seo / 7257244093

19 Dec 2023 04:09AM UTC coverage: 49.388% (-0.002%) from 49.39%
7257244093

push

github

web-flow
Merge pull request #20987 from Yoast/JRF/docs/more-fixes

Docs: more fixes

15425 of 31232 relevant lines covered (49.39%)

4.07 hits per line

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

21.66
/src/integrations/settings-integration.php
1
<?php
2

3
namespace Yoast\WP\SEO\Integrations;
4

5
use WP_Post;
6
use WP_Post_Type;
7
use WP_Taxonomy;
8
use WP_User;
9
use WPSEO_Admin_Asset_Manager;
10
use WPSEO_Admin_Editor_Specific_Replace_Vars;
11
use WPSEO_Admin_Recommended_Replace_Vars;
12
use WPSEO_Option_Titles;
13
use WPSEO_Options;
14
use WPSEO_Replace_Vars;
15
use WPSEO_Shortlinker;
16
use WPSEO_Sitemaps_Router;
17
use Yoast\WP\SEO\Conditionals\Settings_Conditional;
18
use Yoast\WP\SEO\Config\Schema_Types;
19
use Yoast\WP\SEO\Content_Type_Visibility\Application\Content_Type_Visibility_Dismiss_Notifications;
20
use Yoast\WP\SEO\Helpers\Current_Page_Helper;
21
use Yoast\WP\SEO\Helpers\Language_Helper;
22
use Yoast\WP\SEO\Helpers\Options_Helper;
23
use Yoast\WP\SEO\Helpers\Post_Type_Helper;
24
use Yoast\WP\SEO\Helpers\Product_Helper;
25
use Yoast\WP\SEO\Helpers\Schema\Article_Helper;
26
use Yoast\WP\SEO\Helpers\Taxonomy_Helper;
27
use Yoast\WP\SEO\Helpers\User_Helper;
28
use Yoast\WP\SEO\Helpers\Woocommerce_Helper;
29
use Yoast\WP\SEO\Promotions\Application\Promotion_Manager;
30

31
/**
32
 * Class Settings_Integration.
33
 */
34
class Settings_Integration implements Integration_Interface {
35

36
        public const PAGE = 'wpseo_page_settings';
37

38
        /**
39
         * Holds the included WordPress options.
40
         *
41
         * @var string[]
42
         */
43
        public const WP_OPTIONS = [ 'blogdescription' ];
44

45
        /**
46
         * Holds the allowed option groups.
47
         *
48
         * @var array
49
         */
50
        public const ALLOWED_OPTION_GROUPS = [ 'wpseo', 'wpseo_titles', 'wpseo_social' ];
51

52
        /**
53
         * Holds the disallowed settings, per option group.
54
         *
55
         * @var array
56
         */
57
        public const DISALLOWED_SETTINGS = [
58
                'wpseo'        => [
59
                        'myyoast-oauth',
60
                        'semrush_tokens',
61
                        'custom_taxonomy_slugs',
62
                        'zapier_subscription',
63
                        'import_cursors',
64
                        'workouts_data',
65
                        'configuration_finished_steps',
66
                        'importing_completed',
67
                        'wincher_tokens',
68
                        'least_readability_ignore_list',
69
                        'least_seo_score_ignore_list',
70
                        'most_linked_ignore_list',
71
                        'least_linked_ignore_list',
72
                        'indexables_page_reading_list',
73
                        'show_new_content_type_notification',
74
                        'new_post_types',
75
                        'new_taxonomies',
76
                ],
77
                'wpseo_titles' => [
78
                        'company_logo_meta',
79
                        'person_logo_meta',
80
                ],
81
        ];
82

83
        /**
84
         * Holds the disabled on multisite settings, per option group.
85
         *
86
         * @var array
87
         */
88
        public const DISABLED_ON_MULTISITE_SETTINGS = [
89
                'wpseo' => [
90
                        'deny_search_crawling',
91
                        'deny_wp_json_crawling',
92
                        'deny_adsbot_crawling',
93
                        'deny_ccbot_crawling',
94
                        'deny_google_extended_crawling',
95
                        'deny_gptbot_crawling',
96
                ],
97
        ];
98

99
        /**
100
         * Holds the WPSEO_Admin_Asset_Manager.
101
         *
102
         * @var WPSEO_Admin_Asset_Manager
103
         */
104
        protected $asset_manager;
105

106
        /**
107
         * Holds the WPSEO_Replace_Vars.
108
         *
109
         * @var WPSEO_Replace_Vars
110
         */
111
        protected $replace_vars;
112

113
        /**
114
         * Holds the Schema_Types.
115
         *
116
         * @var Schema_Types
117
         */
118
        protected $schema_types;
119

120
        /**
121
         * Holds the Current_Page_Helper.
122
         *
123
         * @var Current_Page_Helper
124
         */
125
        protected $current_page_helper;
126

127
        /**
128
         * Holds the Post_Type_Helper.
129
         *
130
         * @var Post_Type_Helper
131
         */
132
        protected $post_type_helper;
133

134
        /**
135
         * Holds the Language_Helper.
136
         *
137
         * @var Language_Helper
138
         */
139
        protected $language_helper;
140

141
        /**
142
         * Holds the Taxonomy_Helper.
143
         *
144
         * @var Taxonomy_Helper
145
         */
146
        protected $taxonomy_helper;
147

148
        /**
149
         * Holds the Product_Helper.
150
         *
151
         * @var Product_Helper
152
         */
153
        protected $product_helper;
154

155
        /**
156
         * Holds the Woocommerce_Helper.
157
         *
158
         * @var Woocommerce_Helper
159
         */
160
        protected $woocommerce_helper;
161

162
        /**
163
         * Holds the Article_Helper.
164
         *
165
         * @var Article_Helper
166
         */
167
        protected $article_helper;
168

169
        /**
170
         * Holds the User_Helper.
171
         *
172
         * @var User_Helper
173
         */
174
        protected $user_helper;
175

176
        /**
177
         * Holds the Options_Helper instance.
178
         *
179
         * @var Options_Helper
180
         */
181
        protected $options;
182

183
        /**
184
         * Holds the Content_Type_Visibility_Dismiss_Notifications instance.
185
         *
186
         * @var Content_Type_Visibility_Dismiss_Notifications
187
         */
188
        protected $content_type_visibility;
189

190
        /**
191
         * Constructs Settings_Integration.
192
         *
193
         * @param WPSEO_Admin_Asset_Manager                     $asset_manager           The WPSEO_Admin_Asset_Manager.
194
         * @param WPSEO_Replace_Vars                            $replace_vars            The WPSEO_Replace_Vars.
195
         * @param Schema_Types                                  $schema_types            The Schema_Types.
196
         * @param Current_Page_Helper                           $current_page_helper     The Current_Page_Helper.
197
         * @param Post_Type_Helper                              $post_type_helper        The Post_Type_Helper.
198
         * @param Language_Helper                               $language_helper         The Language_Helper.
199
         * @param Taxonomy_Helper                               $taxonomy_helper         The Taxonomy_Helper.
200
         * @param Product_Helper                                $product_helper          The Product_Helper.
201
         * @param Woocommerce_Helper                            $woocommerce_helper      The Woocommerce_Helper.
202
         * @param Article_Helper                                $article_helper          The Article_Helper.
203
         * @param User_Helper                                   $user_helper             The User_Helper.
204
         * @param Options_Helper                                $options                 The options helper.
205
         * @param Content_Type_Visibility_Dismiss_Notifications $content_type_visibility The Content_Type_Visibility_Dismiss_Notifications instance.
206
         */
207
        public function __construct(
2✔
208
                WPSEO_Admin_Asset_Manager $asset_manager,
209
                WPSEO_Replace_Vars $replace_vars,
210
                Schema_Types $schema_types,
211
                Current_Page_Helper $current_page_helper,
212
                Post_Type_Helper $post_type_helper,
213
                Language_Helper $language_helper,
214
                Taxonomy_Helper $taxonomy_helper,
215
                Product_Helper $product_helper,
216
                Woocommerce_Helper $woocommerce_helper,
217
                Article_Helper $article_helper,
218
                User_Helper $user_helper,
219
                Options_Helper $options,
220
                Content_Type_Visibility_Dismiss_Notifications $content_type_visibility
221
        ) {
1✔
222
                $this->asset_manager           = $asset_manager;
2✔
223
                $this->replace_vars            = $replace_vars;
2✔
224
                $this->schema_types            = $schema_types;
2✔
225
                $this->current_page_helper     = $current_page_helper;
2✔
226
                $this->taxonomy_helper         = $taxonomy_helper;
2✔
227
                $this->post_type_helper        = $post_type_helper;
2✔
228
                $this->language_helper         = $language_helper;
2✔
229
                $this->product_helper          = $product_helper;
2✔
230
                $this->woocommerce_helper      = $woocommerce_helper;
2✔
231
                $this->article_helper          = $article_helper;
2✔
232
                $this->user_helper             = $user_helper;
2✔
233
                $this->options                 = $options;
2✔
234
                $this->content_type_visibility = $content_type_visibility;
2✔
235
        }
1✔
236

237
        /**
238
         * Returns the conditionals based on which this loadable should be active.
239
         *
240
         * @return array
241
         */
242
        public static function get_conditionals() {
2✔
243
                return [ Settings_Conditional::class ];
2✔
244
        }
245

246
        /**
247
         * Initializes the integration.
248
         *
249
         * This is the place to register hooks and filters.
250
         *
251
         * @return void
252
         */
253
        public function register_hooks() {
×
254
                // Add page.
255
                \add_filter( 'wpseo_submenu_pages', [ $this, 'add_page' ] );
×
256
                \add_filter( 'admin_menu', [ $this, 'add_settings_saved_page' ] );
×
257

258
                // Are we saving the settings?
259
                if ( $this->current_page_helper->get_current_admin_page() === 'options.php' ) {
×
260
                        // phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged -- This deprecation will be addressed later.
261
                        $post_action = \filter_input( \INPUT_POST, 'action', @\FILTER_SANITIZE_STRING );
×
262
                        $option_page = \filter_input( \INPUT_POST, 'option_page', @\FILTER_SANITIZE_STRING );
×
263
                        // phpcs:enable
264

265
                        if ( $post_action === 'update' && $option_page === self::PAGE ) {
×
266
                                \add_action( 'admin_init', [ $this, 'register_setting' ] );
×
267
                                \add_action( 'in_admin_header', [ $this, 'remove_notices' ], \PHP_INT_MAX );
×
268
                        }
269

270
                        return;
×
271
                }
272

273
                // Are we on the settings page?
274
                if ( $this->current_page_helper->get_current_yoast_seo_page() === self::PAGE ) {
×
275
                        \add_action( 'admin_init', [ $this, 'register_setting' ] );
×
276
                        \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
×
277
                        \add_action( 'in_admin_header', [ $this, 'remove_notices' ], \PHP_INT_MAX );
×
278
                }
279
        }
280

281
        /**
282
         * Registers the different options under the setting.
283
         *
284
         * @return void
285
         */
286
        public function register_setting() {
×
287
                foreach ( WPSEO_Options::$options as $name => $instance ) {
×
288
                        if ( \in_array( $name, self::ALLOWED_OPTION_GROUPS, true ) ) {
×
289
                                \register_setting( self::PAGE, $name );
×
290
                        }
291
                }
292
                // Only register WP options when the user is allowed to manage them.
293
                if ( \current_user_can( 'manage_options' ) ) {
×
294
                        foreach ( self::WP_OPTIONS as $name ) {
×
295
                                \register_setting( self::PAGE, $name );
×
296
                        }
297
                }
298
        }
299

300
        /**
301
         * Adds the page.
302
         *
303
         * @param array $pages The pages.
304
         *
305
         * @return array The pages.
306
         */
307
        public function add_page( $pages ) {
×
308
                \array_splice(
×
309
                        $pages,
×
310
                        1,
×
311
                        0,
×
312
                        [
313
                                [
314
                                        'wpseo_dashboard',
×
315
                                        '',
×
316
                                        \__( 'Settings', 'wordpress-seo' ),
×
317
                                        'wpseo_manage_options',
×
318
                                        self::PAGE,
×
319
                                        [ $this, 'display_page' ],
×
320
                                ],
321
                        ]
322
                );
323

324
                return $pages;
×
325
        }
326

327
        /**
328
         * Adds a dummy page.
329
         *
330
         * Because the options route NEEDS to redirect to something.
331
         *
332
         * @param array $pages The pages.
333
         *
334
         * @return array The pages.
335
         */
336
        public function add_settings_saved_page( $pages ) {
2✔
337
                \add_submenu_page(
2✔
338
                        '',
2✔
339
                        '',
2✔
340
                        '',
2✔
341
                        'wpseo_manage_options',
2✔
342
                        self::PAGE . '_saved',
2✔
343
                        static function () {
1✔
344
                                // Add success indication to HTML response.
345
                                $success = empty( \get_settings_errors() ) ? 'true' : 'false';
×
346
                                echo \esc_html( "{{ yoast-success: $success }}" );
×
347
                        }
2✔
348
                );
1✔
349

350
                return $pages;
2✔
351
        }
352

353
        /**
354
         * Displays the page.
355
         */
356
        public function display_page() {
×
357
                echo '<div id="yoast-seo-settings"></div>';
×
358
        }
359

360
        /**
361
         * Enqueues the assets.
362
         *
363
         * @return void
364
         */
365
        public function enqueue_assets() {
×
366
                // Remove the emoji script as it is incompatible with both React and any contenteditable fields.
367
                \remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
×
368
                \wp_enqueue_media();
×
369
                $this->asset_manager->enqueue_script( 'new-settings' );
×
370
                $this->asset_manager->enqueue_style( 'new-settings' );
×
371
                if ( \YoastSEO()->classes->get( Promotion_Manager::class )->is( 'black-friday-2023-promotion' ) ) {
×
372
                        $this->asset_manager->enqueue_style( 'black-friday-banner' );
×
373
                }
374
                $this->asset_manager->localize_script( 'new-settings', 'wpseoScriptData', $this->get_script_data() );
×
375
        }
376

377
        /**
378
         * Removes all current WP notices.
379
         *
380
         * @return void
381
         */
382
        public function remove_notices() {
×
383
                \remove_all_actions( 'admin_notices' );
×
384
                \remove_all_actions( 'user_admin_notices' );
×
385
                \remove_all_actions( 'network_admin_notices' );
×
386
                \remove_all_actions( 'all_admin_notices' );
×
387
        }
388

389
        /**
390
         * Creates the script data.
391
         *
392
         * @return array The script data.
393
         */
394
        protected function get_script_data() {
×
395
                $default_setting_values = $this->get_default_setting_values();
×
396
                $settings               = $this->get_settings( $default_setting_values );
×
397
                $post_types             = $this->post_type_helper->get_indexable_post_type_objects();
×
398
                $taxonomies             = $this->taxonomy_helper->get_indexable_taxonomy_objects();
×
399

400
                // Check if attachments are included in indexation.
401
                if ( ! \array_key_exists( 'attachment', $post_types ) ) {
×
402
                        // Always include attachments in the settings, to let the user enable them again.
403
                        $attachment_object = \get_post_type_object( 'attachment' );
×
404
                        if ( ! empty( $attachment_object ) ) {
×
405
                                $post_types['attachment'] = $attachment_object;
×
406
                        }
407
                }
408
                // Check if post formats are included in indexation.
409
                if ( ! \array_key_exists( 'post_format', $taxonomies ) ) {
×
410
                        // Always include post_format in the settings, to let the user enable them again.
411
                        $post_format_object = \get_taxonomy( 'post_format' );
×
412
                        if ( ! empty( $post_format_object ) ) {
×
413
                                $taxonomies['post_format'] = $post_format_object;
×
414
                        }
415
                }
416

417
                $transformed_post_types = $this->transform_post_types( $post_types );
×
418
                $transformed_taxonomies = $this->transform_taxonomies( $taxonomies, \array_keys( $transformed_post_types ) );
×
419

420
                // Check if there is a new content type to show notification only once in the settings.
421
                $show_new_content_type_notification = $this->content_type_visibility->maybe_add_settings_notification();
×
422

423
                return [
424
                        'settings'                       => $this->transform_settings( $settings ),
×
425
                        'defaultSettingValues'           => $default_setting_values,
×
426
                        'disabledSettings'               => $this->get_disabled_settings( $settings ),
×
427
                        'endpoint'                       => \admin_url( 'options.php' ),
×
428
                        'nonce'                          => \wp_create_nonce( self::PAGE . '-options' ),
×
429
                        'separators'                     => WPSEO_Option_Titles::get_instance()->get_separator_options_for_display(),
×
430
                        'replacementVariables'           => $this->get_replacement_variables(),
×
431
                        'schema'                         => $this->get_schema( $transformed_post_types ),
×
432
                        'preferences'                    => $this->get_preferences( $settings ),
×
433
                        'linkParams'                     => WPSEO_Shortlinker::get_query_params(),
×
434
                        'postTypes'                      => $transformed_post_types,
×
435
                        'taxonomies'                     => $transformed_taxonomies,
×
436
                        'fallbacks'                      => $this->get_fallbacks(),
×
437
                        'showNewContentTypeNotification' => $show_new_content_type_notification,
×
438
                ];
439
        }
440

441
        /**
442
         * Retrieves the preferences.
443
         *
444
         * @param array $settings The settings.
445
         *
446
         * @return array The preferences.
447
         */
448
        protected function get_preferences( $settings ) {
×
449
                $shop_page_id             = $this->woocommerce_helper->get_shop_page_id();
×
450
                $homepage_is_latest_posts = \get_option( 'show_on_front' ) === 'posts';
×
451
                $page_on_front            = \get_option( 'page_on_front' );
×
452
                $page_for_posts           = \get_option( 'page_for_posts' );
×
453

454
                if ( empty( $page_on_front ) ) {
×
455
                        $page_on_front = $page_for_posts;
×
456
                }
457

458
                return [
459
                        'isPremium'                     => $this->product_helper->is_premium(),
×
460
                        'isRtl'                         => \is_rtl(),
×
461
                        'isNetworkAdmin'                => \is_network_admin(),
×
462
                        'isMainSite'                    => \is_main_site(),
×
463
                        'isMultisite'                   => \is_multisite(),
×
464
                        'isWooCommerceActive'           => $this->woocommerce_helper->is_active(),
×
465
                        'isLocalSeoActive'              => \defined( 'WPSEO_LOCAL_FILE' ),
×
466
                        'isNewsSeoActive'               => \defined( 'WPSEO_NEWS_FILE' ),
×
467
                        'promotions'                    => \YoastSEO()->classes->get( Promotion_Manager::class )->get_current_promotions(),
×
468
                        'siteUrl'                       => \get_bloginfo( 'url' ),
×
469
                        'siteTitle'                     => \get_bloginfo( 'name' ),
×
470
                        'sitemapUrl'                    => WPSEO_Sitemaps_Router::get_base_url( 'sitemap_index.xml' ),
×
471
                        'hasWooCommerceShopPage'        => $shop_page_id !== -1,
472
                        'editWooCommerceShopPageUrl'    => \get_edit_post_link( $shop_page_id, 'js' ),
×
473
                        'wooCommerceShopPageSettingUrl' => \get_admin_url( null, 'admin.php?page=wc-settings&tab=products' ),
×
474
                        'homepageIsLatestPosts'         => $homepage_is_latest_posts,
×
475
                        'homepagePageEditUrl'           => \get_edit_post_link( $page_on_front, 'js' ),
×
476
                        'homepagePostsEditUrl'          => \get_edit_post_link( $page_for_posts, 'js' ),
×
477
                        'createUserUrl'                 => \admin_url( 'user-new.php' ),
×
478
                        'createPageUrl'                 => \admin_url( 'post-new.php?post_type=page' ),
×
479
                        'editUserUrl'                   => \admin_url( 'user-edit.php' ),
×
480
                        'editTaxonomyUrl'               => \admin_url( 'edit-tags.php' ),
×
481
                        'generalSettingsUrl'            => \admin_url( 'options-general.php' ),
×
482
                        'companyOrPersonMessage'        => \apply_filters( 'wpseo_knowledge_graph_setting_msg', '' ),
×
483
                        'currentUserId'                 => \get_current_user_id(),
×
484
                        'canCreateUsers'                => \current_user_can( 'create_users' ),
×
485
                        'canCreatePages'                => \current_user_can( 'edit_pages' ),
×
486
                        'canEditUsers'                  => \current_user_can( 'edit_users' ),
×
487
                        'canManageOptions'              => \current_user_can( 'manage_options' ),
×
488
                        'userLocale'                    => \str_replace( '_', '-', \get_user_locale() ),
×
489
                        'pluginUrl'                     => \plugins_url( '', \WPSEO_FILE ),
×
490
                        'showForceRewriteTitlesSetting' => ! \current_theme_supports( 'title-tag' ) && ! ( \function_exists( 'wp_is_block_theme' ) && \wp_is_block_theme() ),
×
491
                        'upsellSettings'                => $this->get_upsell_settings(),
×
492
                        'siteRepresentsPerson'          => $this->get_site_represents_person( $settings ),
×
493
                        'siteBasicsPolicies'            => $this->get_site_basics_policies( $settings ),
×
494
                ];
495
        }
496

497
        /**
498
         * Retrieves the currently represented person.
499
         *
500
         * @param array $settings The settings.
501
         *
502
         * @return array The currently represented person's ID and name.
503
         */
504
        protected function get_site_represents_person( $settings ) {
×
505
                $person = [
506
                        'id'   => false,
×
507
                        'name' => '',
508
                ];
509

510
                if ( isset( $settings['wpseo_titles']['company_or_person_user_id'] ) ) {
×
511
                        $person['id'] = $settings['wpseo_titles']['company_or_person_user_id'];
×
512
                        $user         = \get_userdata( $person['id'] );
×
513
                        if ( $user instanceof WP_User ) {
×
514
                                $person['name'] = $user->get( 'display_name' );
×
515
                        }
516
                }
517

518
                return $person;
×
519
        }
520

521
        /**
522
         * Get site policy data.
523
         *
524
         * @param array $settings The settings.
525
         *
526
         * @return array The policy data.
527
         */
528
        private function get_site_basics_policies( $settings ) {
×
529
                $policies = [];
×
530

531
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['publishing_principles_id'], 'publishing_principles_id' );
×
532
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['ownership_funding_info_id'], 'ownership_funding_info_id' );
×
533
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['actionable_feedback_policy_id'], 'actionable_feedback_policy_id' );
×
534
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['corrections_policy_id'], 'corrections_policy_id' );
×
535
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['ethics_policy_id'], 'ethics_policy_id' );
×
536
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['diversity_policy_id'], 'diversity_policy_id' );
×
537
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['diversity_staffing_report_id'], 'diversity_staffing_report_id' );
×
538

539
                return $policies;
×
540
        }
541

542
        /**
543
         * Adds policy data if it is present.
544
         *
545
         * @param array  $policies The existing policy data.
546
         * @param int    $policy   The policy id to check.
547
         * @param string $key      The option key name.
548
         *
549
         * @return array The policy data.
550
         */
551
        private function maybe_add_policy( $policies, $policy, $key ) {
×
552
                $policy_array = [
553
                        'id'   => 0,
×
554
                        'name' => \__( 'None', 'wordpress-seo' ),
×
555
                ];
556

557
                if ( isset( $policy ) && \is_int( $policy ) ) {
×
558
                        $policy_array['id'] = $policy;
×
559
                        $post               = \get_post( $policy );
×
560
                        if ( $post instanceof WP_Post ) {
×
561
                                if ( $post->post_status !== 'publish' || $post->post_password !== '' ) {
×
562
                                        return $policies;
×
563
                                }
564
                                $policy_array['name'] = $post->post_title;
×
565
                        }
566
                }
567

568
                $policies[ $key ] = $policy_array;
×
569

570
                return $policies;
×
571
        }
572

573
        /**
574
         * Returns settings for the Call to Buy (CTB) buttons.
575
         *
576
         * @return string[] The array of CTB settings.
577
         */
578
        public function get_upsell_settings() {
×
579
                return [
580
                        'actionId'     => 'load-nfd-ctb',
×
581
                        'premiumCtbId' => 'f6a84663-465f-4cb5-8ba5-f7a6d72224b2',
582
                ];
583
        }
584

585
        /**
586
         * Retrieves the default setting values.
587
         *
588
         * These default values are currently being used in the UI for dummy fields.
589
         * Dummy fields should not expose or reflect the actual data.
590
         *
591
         * @return array The default setting values.
592
         */
593
        protected function get_default_setting_values() {
×
594
                $defaults = [];
×
595

596
                // Add Yoast settings.
597
                foreach ( WPSEO_Options::$options as $option_name => $instance ) {
×
598
                        if ( \in_array( $option_name, self::ALLOWED_OPTION_GROUPS, true ) ) {
×
599
                                $option_instance          = WPSEO_Options::get_option_instance( $option_name );
×
600
                                $defaults[ $option_name ] = ( $option_instance ) ? $option_instance->get_defaults() : [];
×
601
                        }
602
                }
603
                // Add WP settings.
604
                foreach ( self::WP_OPTIONS as $option_name ) {
×
605
                        $defaults[ $option_name ] = '';
×
606
                }
607

608
                // Remove disallowed settings.
609
                foreach ( self::DISALLOWED_SETTINGS as $option_name => $disallowed_settings ) {
×
610
                        foreach ( $disallowed_settings as $disallowed_setting ) {
×
611
                                unset( $defaults[ $option_name ][ $disallowed_setting ] );
×
612
                        }
613
                }
614

615
                return $defaults;
×
616
        }
617

618
        /**
619
         * Retrieves the settings and their values.
620
         *
621
         * @param array $default_setting_values The default setting values.
622
         *
623
         * @return array The settings.
624
         */
625
        protected function get_settings( $default_setting_values ) {
×
626
                $settings = [];
×
627

628
                // Add Yoast settings.
629
                foreach ( WPSEO_Options::$options as $option_name => $instance ) {
×
630
                        if ( \in_array( $option_name, self::ALLOWED_OPTION_GROUPS, true ) ) {
×
631
                                $settings[ $option_name ] = \array_merge( $default_setting_values[ $option_name ], WPSEO_Options::get_option( $option_name ) );
×
632
                        }
633
                }
634
                // Add WP settings.
635
                foreach ( self::WP_OPTIONS as $option_name ) {
×
636
                        $settings[ $option_name ] = \get_option( $option_name );
×
637
                }
638

639
                // Remove disallowed settings.
640
                foreach ( self::DISALLOWED_SETTINGS as $option_name => $disallowed_settings ) {
×
641
                        foreach ( $disallowed_settings as $disallowed_setting ) {
×
642
                                unset( $settings[ $option_name ][ $disallowed_setting ] );
×
643
                        }
644
                }
645

646
                return $settings;
×
647
        }
648

649
        /**
650
         * Transforms setting values.
651
         *
652
         * @param array $settings The settings.
653
         *
654
         * @return array The settings.
655
         */
656
        protected function transform_settings( $settings ) {
×
657
                if ( isset( $settings['wpseo_titles']['breadcrumbs-sep'] ) ) {
×
658
                        /**
659
                         * The breadcrumbs separator default value is the HTML entity `&raquo;`.
660
                         * Which does not get decoded in our JS, while it did in our Yoast form. Decode it here as an exception.
661
                         */
662
                        $settings['wpseo_titles']['breadcrumbs-sep'] = \html_entity_decode(
×
663
                                $settings['wpseo_titles']['breadcrumbs-sep'],
×
664
                                ( \ENT_NOQUOTES | \ENT_HTML5 ),
×
665
                                'UTF-8'
×
666
                        );
667
                }
668

669
                /**
670
                 * Decode some WP options.
671
                 */
672
                $settings['blogdescription'] = \html_entity_decode(
×
673
                        $settings['blogdescription'],
×
674
                        ( \ENT_NOQUOTES | \ENT_HTML5 ),
×
675
                        'UTF-8'
×
676
                );
677

678
                return $settings;
×
679
        }
680

681
        /**
682
         * Retrieves the disabled settings.
683
         *
684
         * @param array $settings The settings.
685
         *
686
         * @return array The settings.
687
         */
688
        protected function get_disabled_settings( $settings ) {
×
689
                $disabled_settings = [];
×
690
                $site_language     = $this->language_helper->get_language();
×
691

692
                foreach ( WPSEO_Options::$options as $option_name => $instance ) {
×
693
                        if ( ! \in_array( $option_name, self::ALLOWED_OPTION_GROUPS, true ) ) {
×
694
                                continue;
×
695
                        }
696

697
                        $disabled_settings[ $option_name ] = [];
×
698
                        $option_instance                   = WPSEO_Options::get_option_instance( $option_name );
×
699
                        if ( $option_instance === false ) {
×
700
                                continue;
×
701
                        }
702
                        foreach ( $settings[ $option_name ] as $setting_name => $setting_value ) {
×
703
                                if ( $option_instance->is_disabled( $setting_name ) ) {
×
704
                                        $disabled_settings[ $option_name ][ $setting_name ] = 'network';
×
705
                                }
706
                        }
707
                }
708

709
                // Remove disabled on multisite settings.
710
                if ( \is_multisite() ) {
×
711
                        foreach ( self::DISABLED_ON_MULTISITE_SETTINGS as $option_name => $disabled_ms_settings ) {
×
712
                                if ( \array_key_exists( $option_name, $disabled_settings ) ) {
×
713
                                        foreach ( $disabled_ms_settings as $disabled_ms_setting ) {
×
714
                                                $disabled_settings[ $option_name ][ $disabled_ms_setting ] = 'multisite';
×
715
                                        }
716
                                }
717
                        }
718
                }
719

720
                if ( \array_key_exists( 'wpseo', $disabled_settings ) && ! $this->language_helper->has_inclusive_language_support( $site_language ) ) {
×
721
                        $disabled_settings['wpseo']['inclusive_language_analysis_active'] = 'language';
×
722
                }
723

724
                return $disabled_settings;
×
725
        }
726

727
        /**
728
         * Retrieves the replacement variables.
729
         *
730
         * @return array The replacement variables.
731
         */
732
        protected function get_replacement_variables() {
×
733
                $recommended_replace_vars = new WPSEO_Admin_Recommended_Replace_Vars();
×
734
                $specific_replace_vars    = new WPSEO_Admin_Editor_Specific_Replace_Vars();
×
735
                $replacement_variables    = $this->replace_vars->get_replacement_variables_with_labels();
×
736

737
                return [
738
                        'variables'   => $replacement_variables,
×
739
                        'recommended' => $recommended_replace_vars->get_recommended_replacevars(),
×
740
                        'specific'    => $specific_replace_vars->get(),
×
741
                        'shared'      => $specific_replace_vars->get_generic( $replacement_variables ),
×
742
                ];
743
        }
744

745
        /**
746
         * Retrieves the schema.
747
         *
748
         * @param array $post_types The post types.
749
         *
750
         * @return array The schema.
751
         */
752
        protected function get_schema( array $post_types ) {
×
753
                $schema = [];
×
754

755
                foreach ( $this->schema_types->get_article_type_options() as $article_type ) {
×
756
                        $schema['articleTypes'][ $article_type['value'] ] = [
×
757
                                'label' => $article_type['name'],
×
758
                                'value' => $article_type['value'],
×
759
                        ];
760
                }
761

762
                foreach ( $this->schema_types->get_page_type_options() as $page_type ) {
×
763
                        $schema['pageTypes'][ $page_type['value'] ] = [
×
764
                                'label' => $page_type['name'],
×
765
                                'value' => $page_type['value'],
×
766
                        ];
767
                }
768

769
                $schema['articleTypeDefaults'] = [];
×
770
                $schema['pageTypeDefaults']    = [];
×
771
                foreach ( $post_types as $name => $post_type ) {
×
772
                        $schema['articleTypeDefaults'][ $name ] = WPSEO_Options::get_default( 'wpseo_titles', "schema-article-type-$name" );
×
773
                        $schema['pageTypeDefaults'][ $name ]    = WPSEO_Options::get_default( 'wpseo_titles', "schema-page-type-$name" );
×
774
                }
775

776
                return $schema;
×
777
        }
778

779
        /**
780
         * Transforms the post types, to represent them.
781
         *
782
         * @param WP_Post_Type[] $post_types The WP_Post_Type array to transform.
783
         *
784
         * @return array The post types.
785
         */
786
        protected function transform_post_types( $post_types ) {
4✔
787
                $transformed    = [];
4✔
788
                $new_post_types = $this->options->get( 'new_post_types', [] );
4✔
789
                foreach ( $post_types as $post_type ) {
4✔
790
                        $transformed[ $post_type->name ] = [
4✔
791
                                'name'                 => $post_type->name,
4✔
792
                                'route'                => $this->get_route( $post_type->name, $post_type->rewrite, $post_type->rest_base ),
4✔
793
                                'label'                => $post_type->label,
4✔
794
                                'singularLabel'        => $post_type->labels->singular_name,
4✔
795
                                'hasArchive'           => $this->post_type_helper->has_archive( $post_type ),
4✔
796
                                'hasSchemaArticleType' => $this->article_helper->is_article_post_type( $post_type->name ),
4✔
797
                                'menuPosition'         => $post_type->menu_position,
4✔
798
                                'isNew'                => \in_array( $post_type->name, $new_post_types, true ),
4✔
799
                        ];
2✔
800
                }
801

802
                \uasort( $transformed, [ $this, 'compare_post_types' ] );
4✔
803

804
                return $transformed;
4✔
805
        }
806

807
        /**
808
         * Compares two post types.
809
         *
810
         * @param array $a The first post type.
811
         * @param array $b The second post type.
812
         *
813
         * @return int The order.
814
         */
815
        protected function compare_post_types( $a, $b ) {
×
816
                if ( $a['menuPosition'] === null && $b['menuPosition'] !== null ) {
×
817
                        return 1;
×
818
                }
819
                if ( $a['menuPosition'] !== null && $b['menuPosition'] === null ) {
×
820
                        return -1;
×
821
                }
822

823
                if ( $a['menuPosition'] === null && $b['menuPosition'] === null ) {
×
824
                        // No position specified, order alphabetically by label.
825
                        return \strnatcmp( $a['label'], $b['label'] );
×
826
                }
827

828
                return ( ( $a['menuPosition'] < $b['menuPosition'] ) ? -1 : 1 );
×
829
        }
830

831
        /**
832
         * Transforms the taxonomies, to represent them.
833
         *
834
         * @param WP_Taxonomy[] $taxonomies      The WP_Taxonomy array to transform.
835
         * @param string[]      $post_type_names The post type names.
836
         *
837
         * @return array The taxonomies.
838
         */
839
        protected function transform_taxonomies( $taxonomies, $post_type_names ) {
4✔
840
                $transformed    = [];
4✔
841
                $new_taxonomies = $this->options->get( 'new_taxonomies', [] );
4✔
842
                foreach ( $taxonomies as $taxonomy ) {
4✔
843
                        $transformed[ $taxonomy->name ] = [
4✔
844
                                'name'          => $taxonomy->name,
4✔
845
                                'route'         => $this->get_route( $taxonomy->name, $taxonomy->rewrite, $taxonomy->rest_base ),
4✔
846
                                'label'         => $taxonomy->label,
4✔
847
                                'showUi'        => $taxonomy->show_ui,
4✔
848
                                'singularLabel' => $taxonomy->labels->singular_name,
4✔
849
                                'postTypes'     => \array_filter(
4✔
850
                                        $taxonomy->object_type,
4✔
851
                                        static function ( $object_type ) use ( $post_type_names ) {
2✔
852
                                                return \in_array( $object_type, $post_type_names, true );
4✔
853
                                        }
2✔
854
                                ),
4✔
855
                                'isNew'         => \in_array( $taxonomy->name, $new_taxonomies, true ),
2✔
856
                        ];
2✔
857
                }
858

859
                \uasort(
4✔
860
                        $transformed,
2✔
861
                        static function ( $a, $b ) {
2✔
862
                                return \strnatcmp( $a['label'], $b['label'] );
863
                        }
2✔
864
                );
4✔
865

866
                return $transformed;
867
        }
868

869
        /**
870
         * Gets the route from a name, rewrite and rest_base.
871
         *
872
         * @param string $name      The name.
873
         * @param array  $rewrite   The rewrite data.
874
         * @param string $rest_base The rest base.
875
         *
876
         * @return string The route.
877
         */
878
        protected function get_route( $name, $rewrite, $rest_base ) {
×
879
                $route = $name;
×
880
                if ( isset( $rewrite['slug'] ) ) {
881
                        $route = $rewrite['slug'];
×
882
                }
883
                if ( ! empty( $rest_base ) ) {
884
                        $route = $rest_base;
885
                }
886
                // Always strip leading slashes.
887
                while ( \substr( $route, 0, 1 ) === '/' ) {
888
                        $route = \substr( $route, 1 );
889
                }
890

891
                return \rawurlencode( $route );
892
        }
893

894
        /**
895
         * Retrieves the fallbacks.
896
         *
897
         * @return array The fallbacks.
898
         */
899
        protected function get_fallbacks() {
×
900
                $site_logo_id = \get_option( 'site_logo' );
×
901
                if ( ! $site_logo_id ) {
902
                        $site_logo_id = \get_theme_mod( 'custom_logo' );
×
903
                }
904
                if ( ! $site_logo_id ) {
905
                        $site_logo_id = '0';
906
                }
907

908
                return [
909
                        'siteLogoId' => $site_logo_id,
910
                ];
911
        }
912
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc