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

Yoast / wordpress-seo / 5025760653

pending completion
5025760653

push

github

aidamarfuaty
Merge branch 'trunk' of github.com:Yoast/wordpress-seo into feature/html-parser

97 of 172 new or added lines in 42 files covered. (56.4%)

9584 of 24000 relevant lines covered (39.93%)

3.32 hits per line

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

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

3
namespace Yoast\WP\SEO\Integrations;
4

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

28
/**
29
 * Class Settings_Integration.
30
 */
31
class Settings_Integration implements Integration_Interface {
32

33
        const PAGE = 'wpseo_page_settings';
34

35
        /**
36
         * Holds the included WordPress options.
37
         *
38
         * @var string[]
39
         */
40
        const WP_OPTIONS = [ 'blogdescription' ];
41

42
        /**
43
         * Holds the allowed option groups.
44
         *
45
         * @var array
46
         */
47
        const ALLOWED_OPTION_GROUPS = [ 'wpseo', 'wpseo_titles', 'wpseo_social' ];
48

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

77
        /**
78
         * Holds the disabled on multisite settings, per option group.
79
         *
80
         * @var array
81
         */
82
        const DISABLED_ON_MULTISITE_SETTINGS = [
83
                'wpseo' => [
84
                        'deny_search_crawling',
85
                        'deny_wp_json_crawling',
86
                ],
87
        ];
88

89
        /**
90
         * Holds the WPSEO_Admin_Asset_Manager.
91
         *
92
         * @var WPSEO_Admin_Asset_Manager
93
         */
94
        protected $asset_manager;
95

96
        /**
97
         * Holds the WPSEO_Replace_Vars.
98
         *
99
         * @var WPSEO_Replace_Vars
100
         */
101
        protected $replace_vars;
102

103
        /**
104
         * Holds the Schema_Types.
105
         *
106
         * @var Schema_Types
107
         */
108
        protected $schema_types;
109

110
        /**
111
         * Holds the Current_Page_Helper.
112
         *
113
         * @var Current_Page_Helper
114
         */
115
        protected $current_page_helper;
116

117
        /**
118
         * Holds the Post_Type_Helper.
119
         *
120
         * @var Post_Type_Helper
121
         */
122
        protected $post_type_helper;
123

124
        /**
125
         * Holds the Language_Helper.
126
         *
127
         * @var Language_Helper
128
         */
129
        protected $language_helper;
130

131
        /**
132
         * Holds the Taxonomy_Helper.
133
         *
134
         * @var Taxonomy_Helper
135
         */
136
        protected $taxonomy_helper;
137

138
        /**
139
         * Holds the Product_Helper.
140
         *
141
         * @var Product_Helper
142
         */
143
        protected $product_helper;
144

145
        /**
146
         * Holds the Woocommerce_Helper.
147
         *
148
         * @var Woocommerce_Helper
149
         */
150
        protected $woocommerce_helper;
151

152
        /**
153
         * Holds the Article_Helper.
154
         *
155
         * @var Article_Helper
156
         */
157
        protected $article_helper;
158

159
        /**
160
         * Holds the User_Helper.
161
         *
162
         * @var User_Helper
163
         */
164
        protected $user_helper;
165

166
        /**
167
         * Constructs Settings_Integration.
168
         *
169
         * @param WPSEO_Admin_Asset_Manager $asset_manager       The WPSEO_Admin_Asset_Manager.
170
         * @param WPSEO_Replace_Vars        $replace_vars        The WPSEO_Replace_Vars.
171
         * @param Schema_Types              $schema_types        The Schema_Types.
172
         * @param Current_Page_Helper       $current_page_helper The Current_Page_Helper.
173
         * @param Post_Type_Helper          $post_type_helper    The Post_Type_Helper.
174
         * @param Language_Helper           $language_helper     The Language_Helper.
175
         * @param Taxonomy_Helper           $taxonomy_helper     The Taxonomy_Helper.
176
         * @param Product_Helper            $product_helper      The Product_Helper.
177
         * @param Woocommerce_Helper        $woocommerce_helper  The Woocommerce_Helper.
178
         * @param Article_Helper            $article_helper      The Article_Helper.
179
         * @param User_Helper               $user_helper         The User_Helper.
180
         */
181
        public function __construct(
182
                WPSEO_Admin_Asset_Manager $asset_manager,
183
                WPSEO_Replace_Vars $replace_vars,
184
                Schema_Types $schema_types,
185
                Current_Page_Helper $current_page_helper,
186
                Post_Type_Helper $post_type_helper,
187
                Language_Helper $language_helper,
188
                Taxonomy_Helper $taxonomy_helper,
189
                Product_Helper $product_helper,
190
                Woocommerce_Helper $woocommerce_helper,
191
                Article_Helper $article_helper,
192
                User_Helper $user_helper
193
        ) {
194
                $this->asset_manager       = $asset_manager;
195
                $this->replace_vars        = $replace_vars;
196
                $this->schema_types        = $schema_types;
197
                $this->current_page_helper = $current_page_helper;
198
                $this->taxonomy_helper     = $taxonomy_helper;
199
                $this->post_type_helper    = $post_type_helper;
200
                $this->language_helper     = $language_helper;
201
                $this->product_helper      = $product_helper;
202
                $this->woocommerce_helper  = $woocommerce_helper;
203
                $this->article_helper      = $article_helper;
204
                $this->user_helper         = $user_helper;
205
        }
206

207
        /**
208
         * Returns the conditionals based on which this loadable should be active.
209
         *
210
         * @return array
211
         */
212
        public static function get_conditionals() {
213
                return [ Settings_Conditional::class ];
214
        }
215

216
        /**
217
         * Initializes the integration.
218
         *
219
         * This is the place to register hooks and filters.
220
         *
221
         * @return void
222
         */
223
        public function register_hooks() {
224
                // Add page.
225
                \add_filter( 'wpseo_submenu_pages', [ $this, 'add_page' ] );
226
                \add_filter( 'admin_menu', [ $this, 'add_settings_saved_page' ] );
227

228
                // Are we saving the settings?
229
                if ( $this->current_page_helper->get_current_admin_page() === 'options.php' ) {
230
                        // phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged -- This deprecation will be addressed later.
231
                        $post_action = \filter_input( \INPUT_POST, 'action', @\FILTER_SANITIZE_STRING );
232
                        $option_page = \filter_input( \INPUT_POST, 'option_page', @\FILTER_SANITIZE_STRING );
233
                        // phpcs:enable
234

235
                        if ( $post_action === 'update' && $option_page === self::PAGE ) {
236
                                \add_action( 'admin_init', [ $this, 'register_setting' ] );
237
                                \add_action( 'in_admin_header', [ $this, 'remove_notices' ], \PHP_INT_MAX );
238
                        }
239

240
                        return;
241
                }
242

243
                // Are we on the settings page?
244
                if ( $this->current_page_helper->get_current_yoast_seo_page() === self::PAGE ) {
245
                        \add_action( 'admin_init', [ $this, 'register_setting' ] );
246
                        \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
247
                        \add_action( 'in_admin_header', [ $this, 'remove_notices' ], \PHP_INT_MAX );
248

249
                        // Remove the post types and taxonomies made public notifications (if any).
250
                        $this->remove_post_types_made_public_notification();
251
                        $this->remove_taxonomies_made_public_notification();
252
                }
253
        }
254

255
        /**
256
         * Registers the different options under the setting.
257
         *
258
         * @return void
259
         */
260
        public function register_setting() {
261
                foreach ( WPSEO_Options::$options as $name => $instance ) {
262
                        if ( \in_array( $name, self::ALLOWED_OPTION_GROUPS, true ) ) {
263
                                \register_setting( self::PAGE, $name );
264
                        }
265
                }
266
                // Only register WP options when the user is allowed to manage them.
267
                if ( \current_user_can( 'manage_options' ) ) {
268
                        foreach ( self::WP_OPTIONS as $name ) {
269
                                \register_setting( self::PAGE, $name );
270
                        }
271
                }
272
        }
273

274
        /**
275
         * Adds the page.
276
         *
277
         * @param array $pages The pages.
278
         *
279
         * @return array The pages.
280
         */
281
        public function add_page( $pages ) {
282
                \array_splice(
283
                        $pages,
284
                        1,
285
                        0,
286
                        [
287
                                [
288
                                        'wpseo_dashboard',
289
                                        '',
290
                                        \__( 'Settings', 'wordpress-seo' ),
291
                                        'wpseo_manage_options',
292
                                        self::PAGE,
293
                                        [ $this, 'display_page' ],
294
                                ],
295
                        ]
296
                );
297

298
                return $pages;
299
        }
300

301
        /**
302
         * Adds a dummy page.
303
         *
304
         * Because the options route NEEDS to redirect to something.
305
         *
306
         * @param array $pages The pages.
307
         *
308
         * @return array The pages.
309
         */
310
        public function add_settings_saved_page( $pages ) {
311
                \add_submenu_page(
312
                        '',
313
                        '',
314
                        '',
315
                        'wpseo_manage_options',
316
                        self::PAGE . '_saved',
317
                        static function () {
318
                                // Add success indication to HTML response.
319
                                $success = empty( \get_settings_errors() ) ? 'true' : 'false';
320
                                echo \esc_html( "{{ yoast-success: $success }}" );
321
                        }
322
                );
323

324
                return $pages;
325
        }
326

327
        /**
328
         * Displays the page.
329
         */
330
        public function display_page() {
331
                echo '<div id="yoast-seo-settings"></div>';
332
        }
333

334
        /**
335
         * Enqueues the assets.
336
         *
337
         * @return void
338
         */
339
        public function enqueue_assets() {
340
                // Remove the emoji script as it is incompatible with both React and any contenteditable fields.
341
                \remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
342
                \wp_enqueue_media();
343
                $this->asset_manager->enqueue_script( 'new-settings' );
344
                $this->asset_manager->enqueue_style( 'new-settings' );
345
                $this->asset_manager->localize_script( 'new-settings', 'wpseoScriptData', $this->get_script_data() );
346
        }
347

348
        /**
349
         * Removes all current WP notices.
350
         *
351
         * @return void
352
         */
353
        public function remove_notices() {
354
                \remove_all_actions( 'admin_notices' );
355
                \remove_all_actions( 'user_admin_notices' );
356
                \remove_all_actions( 'network_admin_notices' );
357
                \remove_all_actions( 'all_admin_notices' );
358
        }
359

360
        /**
361
         * Creates the script data.
362
         *
363
         * @return array The script data.
364
         */
365
        protected function get_script_data() {
366
                $default_setting_values = $this->get_default_setting_values();
367
                $settings               = $this->get_settings( $default_setting_values );
368
                $post_types             = $this->post_type_helper->get_indexable_post_type_objects();
369
                $taxonomies             = $this->taxonomy_helper->get_indexable_taxonomy_objects();
370

371
                // Check if attachments are included in indexation.
372
                if ( ! \array_key_exists( 'attachment', $post_types ) ) {
373
                        // Always include attachments in the settings, to let the user enable them again.
374
                        $attachment_object = \get_post_type_object( 'attachment' );
375
                        if ( ! empty( $attachment_object ) ) {
376
                                $post_types['attachment'] = $attachment_object;
377
                        }
378
                }
379
                // Check if post formats are included in indexation.
380
                if ( ! \array_key_exists( 'post_format', $taxonomies ) ) {
381
                        // Always include post_format in the settings, to let the user enable them again.
382
                        $post_format_object = \get_taxonomy( 'post_format' );
383
                        if ( ! empty( $post_format_object ) ) {
384
                                $taxonomies['post_format'] = $post_format_object;
385
                        }
386
                }
387

388
                $transformed_post_types = $this->transform_post_types( $post_types );
389
                $transformed_taxonomies = $this->transform_taxonomies( $taxonomies, \array_keys( $transformed_post_types ) );
390

391
                return [
392
                        'settings'             => $this->transform_settings( $settings ),
393
                        'defaultSettingValues' => $default_setting_values,
394
                        'disabledSettings'     => $this->get_disabled_settings( $settings ),
395
                        'endpoint'             => \admin_url( 'options.php' ),
396
                        'nonce'                => \wp_create_nonce( self::PAGE . '-options' ),
397
                        'separators'           => WPSEO_Option_Titles::get_instance()->get_separator_options_for_display(),
398
                        'replacementVariables' => $this->get_replacement_variables(),
399
                        'schema'               => $this->get_schema( $transformed_post_types ),
400
                        'preferences'          => $this->get_preferences( $settings ),
401
                        'linkParams'           => WPSEO_Shortlinker::get_query_params(),
402
                        'postTypes'            => $transformed_post_types,
403
                        'taxonomies'           => $transformed_taxonomies,
404
                        'fallbacks'            => $this->get_fallbacks(),
405
                ];
406
        }
407

408
        /**
409
         * Retrieves the preferences.
410
         *
411
         * @param array $settings The settings.
412
         *
413
         * @return array The preferences.
414
         */
415
        protected function get_preferences( $settings ) {
416
                $shop_page_id             = $this->woocommerce_helper->get_shop_page_id();
417
                $homepage_is_latest_posts = \get_option( 'show_on_front' ) === 'posts';
418
                $page_on_front            = \get_option( 'page_on_front' );
419
                $page_for_posts           = \get_option( 'page_for_posts' );
420

421
                if ( empty( $page_on_front ) ) {
422
                        $page_on_front = $page_for_posts;
423
                }
424

425
                return [
426
                        'isPremium'                     => $this->product_helper->is_premium(),
427
                        'isRtl'                         => \is_rtl(),
428
                        'isNetworkAdmin'                => \is_network_admin(),
429
                        'isMainSite'                    => \is_main_site(),
430
                        'isWooCommerceActive'           => $this->woocommerce_helper->is_active(),
431
                        'isLocalSeoActive'              => \defined( 'WPSEO_LOCAL_FILE' ),
432
                        'isNewsSeoActive'               => \defined( 'WPSEO_NEWS_FILE' ),
433
                        'siteUrl'                       => \get_bloginfo( 'url' ),
434
                        'siteTitle'                     => \get_bloginfo( 'name' ),
435
                        'sitemapUrl'                    => WPSEO_Sitemaps_Router::get_base_url( 'sitemap_index.xml' ),
436
                        'hasWooCommerceShopPage'        => $shop_page_id !== -1,
437
                        'editWooCommerceShopPageUrl'    => \get_edit_post_link( $shop_page_id, 'js' ),
438
                        'wooCommerceShopPageSettingUrl' => \get_admin_url( null, 'admin.php?page=wc-settings&tab=products' ),
439
                        'homepageIsLatestPosts'         => $homepage_is_latest_posts,
440
                        'homepagePageEditUrl'           => \get_edit_post_link( $page_on_front, 'js' ),
441
                        'homepagePostsEditUrl'          => \get_edit_post_link( $page_for_posts, 'js' ),
442
                        'createUserUrl'                 => \admin_url( 'user-new.php' ),
443
                        'editUserUrl'                   => \admin_url( 'user-edit.php' ),
444
                        'editTaxonomyUrl'               => \admin_url( 'edit-tags.php' ),
445
                        'generalSettingsUrl'            => \admin_url( 'options-general.php' ),
446
                        'companyOrPersonMessage'        => \apply_filters( 'wpseo_knowledge_graph_setting_msg', '' ),
447
                        'currentUserId'                 => \get_current_user_id(),
448
                        'canCreateUsers'                => \current_user_can( 'create_users' ),
449
                        'canEditUsers'                  => \current_user_can( 'edit_users' ),
450
                        'canManageOptions'              => \current_user_can( 'manage_options' ),
451
                        'userLocale'                    => \str_replace( '_', '-', \get_user_locale() ),
452
                        'pluginUrl'                     => \plugins_url( '', \WPSEO_FILE ),
453
                        'showForceRewriteTitlesSetting' => ! \current_theme_supports( 'title-tag' ) && ! ( \function_exists( 'wp_is_block_theme' ) && \wp_is_block_theme() ),
454
                        'upsellSettings'                => $this->get_upsell_settings(),
455
                        'siteRepresentsPerson'          => $this->get_site_represents_person( $settings ),
456
                ];
457
        }
458

459
        /**
460
         * Retrieves the currently represented person.
461
         *
462
         * @param array $settings The settings.
463
         *
464
         * @return array The currently represented person's ID and name.
465
         */
466
        protected function get_site_represents_person( $settings ) {
467
                $person = [
468
                        'id'   => false,
469
                        'name' => '',
470
                ];
471

472
                if ( isset( $settings['wpseo_titles']['company_or_person_user_id'] ) ) {
473
                        $person['id'] = $settings['wpseo_titles']['company_or_person_user_id'];
474
                        $user         = \get_userdata( $person['id'] );
NEW
475
                        if ( $user instanceof WP_User ) {
476
                                $person['name'] = $user->get( 'display_name' );
477
                        }
478
                }
479

480
                return $person;
481
        }
482

483
        /**
484
         * Returns settings for the Call to Buy (CTB) buttons.
485
         *
486
         * @return string[] The array of CTB settings.
487
         */
488
        public function get_upsell_settings() {
489
                return [
490
                        'actionId'     => 'load-nfd-ctb',
491
                        'premiumCtbId' => 'f6a84663-465f-4cb5-8ba5-f7a6d72224b2',
492
                ];
493
        }
494

495
        /**
496
         * Retrieves the default setting values.
497
         *
498
         * These default values are currently being used in the UI for dummy fields.
499
         * Dummy fields should not expose or reflect the actual data.
500
         *
501
         * @return array The default setting values.
502
         */
503
        protected function get_default_setting_values() {
504
                $defaults = [];
505

506
                // Add Yoast settings.
507
                foreach ( WPSEO_Options::$options as $option_name => $instance ) {
508
                        if ( \in_array( $option_name, self::ALLOWED_OPTION_GROUPS, true ) ) {
509
                                $option_instance          = WPSEO_Options::get_option_instance( $option_name );
510
                                $defaults[ $option_name ] = ( $option_instance ) ? $option_instance->get_defaults() : [];
511
                        }
512
                }
513
                // Add WP settings.
514
                foreach ( self::WP_OPTIONS as $option_name ) {
515
                        $defaults[ $option_name ] = '';
516
                }
517

518
                // Remove disallowed settings.
519
                foreach ( self::DISALLOWED_SETTINGS as $option_name => $disallowed_settings ) {
520
                        foreach ( $disallowed_settings as $disallowed_setting ) {
521
                                unset( $defaults[ $option_name ][ $disallowed_setting ] );
522
                        }
523
                }
524

525
                return $defaults;
526
        }
527

528
        /**
529
         * Retrieves the settings and their values.
530
         *
531
         * @param array $default_setting_values The default setting values.
532
         *
533
         * @return array The settings.
534
         */
535
        protected function get_settings( $default_setting_values ) {
536
                $settings = [];
537

538
                // Add Yoast settings.
539
                foreach ( WPSEO_Options::$options as $option_name => $instance ) {
540
                        if ( \in_array( $option_name, self::ALLOWED_OPTION_GROUPS, true ) ) {
541
                                $settings[ $option_name ] = \array_merge( $default_setting_values[ $option_name ], WPSEO_Options::get_option( $option_name ) );
542
                        }
543
                }
544
                // Add WP settings.
545
                foreach ( self::WP_OPTIONS as $option_name ) {
546
                        $settings[ $option_name ] = \get_option( $option_name );
547
                }
548

549
                // Remove disallowed settings.
550
                foreach ( self::DISALLOWED_SETTINGS as $option_name => $disallowed_settings ) {
551
                        foreach ( $disallowed_settings as $disallowed_setting ) {
552
                                unset( $settings[ $option_name ][ $disallowed_setting ] );
553
                        }
554
                }
555

556
                return $settings;
557
        }
558

559
        /**
560
         * Transforms setting values.
561
         *
562
         * @param array $settings The settings.
563
         *
564
         * @return array The settings.
565
         */
566
        protected function transform_settings( $settings ) {
567
                if ( isset( $settings['wpseo_titles']['breadcrumbs-sep'] ) ) {
568
                        /**
569
                         * The breadcrumbs separator default value is the HTML entity `&raquo;`.
570
                         * Which does not get decoded in our JS, while it did in our Yoast form. Decode it here as an exception.
571
                         */
572
                        $settings['wpseo_titles']['breadcrumbs-sep'] = \html_entity_decode(
573
                                $settings['wpseo_titles']['breadcrumbs-sep'],
574
                                ( \ENT_NOQUOTES | \ENT_HTML5 ),
575
                                'UTF-8'
576
                        );
577
                }
578

579
                /**
580
                 * Decode some WP options.
581
                 */
582
                $settings['blogdescription'] = \html_entity_decode(
583
                        $settings['blogdescription'],
584
                        ( \ENT_NOQUOTES | \ENT_HTML5 ),
585
                        'UTF-8'
586
                );
587

588
                return $settings;
589
        }
590

591
        /**
592
         * Retrieves the disabled settings.
593
         *
594
         * @param array $settings The settings.
595
         *
596
         * @return array The settings.
597
         */
598
        protected function get_disabled_settings( $settings ) {
599
                $disabled_settings = [];
600
                $site_language     = $this->language_helper->get_language();
601

602
                foreach ( WPSEO_Options::$options as $option_name => $instance ) {
603
                        if ( ! \in_array( $option_name, self::ALLOWED_OPTION_GROUPS, true ) ) {
604
                                continue;
605
                        }
606

607
                        $disabled_settings[ $option_name ] = [];
608
                        $option_instance                   = WPSEO_Options::get_option_instance( $option_name );
609
                        if ( $option_instance === false ) {
610
                                continue;
611
                        }
612
                        foreach ( $settings[ $option_name ] as $setting_name => $setting_value ) {
613
                                if ( $option_instance->is_disabled( $setting_name ) ) {
614
                                        $disabled_settings[ $option_name ][ $setting_name ] = 'network';
615
                                }
616
                        }
617
                }
618

619
                // Remove disabled on multisite settings.
620
                if ( \is_multisite() ) {
621
                        foreach ( self::DISABLED_ON_MULTISITE_SETTINGS as $option_name => $disabled_ms_settings ) {
622
                                if ( \array_key_exists( $option_name, $disabled_settings ) ) {
623
                                        foreach ( $disabled_ms_settings as $disabled_ms_setting ) {
624
                                                $disabled_settings[ $option_name ][ $disabled_ms_setting ] = 'multisite';
625
                                        }
626
                                }
627
                        }
628
                }
629

630
                if ( \array_key_exists( 'wpseo', $disabled_settings ) && ! $this->language_helper->has_inclusive_language_support( $site_language ) ) {
631
                        $disabled_settings['wpseo']['inclusive_language_analysis_active'] = 'language';
632
                }
633

634
                return $disabled_settings;
635
        }
636

637
        /**
638
         * Retrieves the replacement variables.
639
         *
640
         * @return array The replacement variables.
641
         */
642
        protected function get_replacement_variables() {
643
                $recommended_replace_vars = new WPSEO_Admin_Recommended_Replace_Vars();
644
                $specific_replace_vars    = new WPSEO_Admin_Editor_Specific_Replace_Vars();
645
                $replacement_variables    = $this->replace_vars->get_replacement_variables_with_labels();
646

647
                return [
648
                        'variables'   => $replacement_variables,
649
                        'recommended' => $recommended_replace_vars->get_recommended_replacevars(),
650
                        'specific'    => $specific_replace_vars->get(),
651
                        'shared'      => $specific_replace_vars->get_generic( $replacement_variables ),
652
                ];
653
        }
654

655
        /**
656
         * Retrieves the schema.
657
         *
658
         * @param array $post_types The post types.
659
         *
660
         * @return array The schema.
661
         */
662
        protected function get_schema( array $post_types ) {
663
                $schema = [];
664

665
                foreach ( $this->schema_types->get_article_type_options() as $article_type ) {
666
                        $schema['articleTypes'][ $article_type['value'] ] = [
667
                                'label' => $article_type['name'],
668
                                'value' => $article_type['value'],
669
                        ];
670
                }
671

672
                foreach ( $this->schema_types->get_page_type_options() as $page_type ) {
673
                        $schema['pageTypes'][ $page_type['value'] ] = [
674
                                'label' => $page_type['name'],
675
                                'value' => $page_type['value'],
676
                        ];
677
                }
678

679
                $schema['articleTypeDefaults'] = [];
680
                $schema['pageTypeDefaults']    = [];
681
                foreach ( $post_types as $name => $post_type ) {
682
                        $schema['articleTypeDefaults'][ $name ] = WPSEO_Options::get_default( 'wpseo_titles', "schema-article-type-$name" );
683
                        $schema['pageTypeDefaults'][ $name ]    = WPSEO_Options::get_default( 'wpseo_titles', "schema-page-type-$name" );
684
                }
685

686
                return $schema;
687
        }
688

689
        /**
690
         * Transforms the post types, to represent them.
691
         *
692
         * @param WP_Post_Type[] $post_types The WP_Post_Type array to transform.
693
         *
694
         * @return array The post types.
695
         */
696
        protected function transform_post_types( $post_types ) {
697
                $transformed = [];
698
                foreach ( $post_types as $post_type ) {
699
                        $transformed[ $post_type->name ] = [
700
                                'name'                 => $post_type->name,
701
                                'route'                => $this->get_route( $post_type->name, $post_type->rewrite, $post_type->rest_base ),
702
                                'label'                => $post_type->label,
703
                                'singularLabel'        => $post_type->labels->singular_name,
704
                                'hasArchive'           => $this->post_type_helper->has_archive( $post_type ),
705
                                'hasSchemaArticleType' => $this->article_helper->is_article_post_type( $post_type->name ),
706
                                'menuPosition'         => $post_type->menu_position,
707
                        ];
708
                }
709

710
                \uasort( $transformed, [ $this, 'compare_post_types' ] );
711

712
                return $transformed;
713
        }
714

715
        /**
716
         * Compares two post types.
717
         *
718
         * @param array $a The first post type.
719
         * @param array $b The second post type.
720
         *
721
         * @return int The order.
722
         */
723
        protected function compare_post_types( $a, $b ) {
724
                if ( $a['menuPosition'] === null && $b['menuPosition'] !== null ) {
725
                        return 1;
726
                }
727
                if ( $a['menuPosition'] !== null && $b['menuPosition'] === null ) {
728
                        return -1;
729
                }
730

731
                if ( $a['menuPosition'] === null && $b['menuPosition'] === null ) {
732
                        // No position specified, order alphabetically by label.
733
                        return \strnatcmp( $a['label'], $b['label'] );
734
                }
735

736
                return ( ( $a['menuPosition'] < $b['menuPosition'] ) ? -1 : 1 );
737
        }
738

739
        /**
740
         * Transforms the taxonomies, to represent them.
741
         *
742
         * @param WP_Taxonomy[] $taxonomies      The WP_Taxonomy array to transform.
743
         * @param string[]      $post_type_names The post type names.
744
         *
745
         * @return array The taxonomies.
746
         */
747
        protected function transform_taxonomies( $taxonomies, $post_type_names ) {
748
                $transformed = [];
749
                foreach ( $taxonomies as $taxonomy ) {
750
                        $transformed[ $taxonomy->name ] = [
751
                                'name'          => $taxonomy->name,
752
                                'route'         => $this->get_route( $taxonomy->name, $taxonomy->rewrite, $taxonomy->rest_base ),
753
                                'label'         => $taxonomy->label,
754
                                'showUi'        => $taxonomy->show_ui,
755
                                'singularLabel' => $taxonomy->labels->singular_name,
756
                                'postTypes'     => \array_filter(
757
                                        $taxonomy->object_type,
758
                                        static function ( $object_type ) use ( $post_type_names ) {
759
                                                return \in_array( $object_type, $post_type_names, true );
760
                                        }
761
                                ),
762
                        ];
763
                }
764

765
                \uasort(
766
                        $transformed,
767
                        static function ( $a, $b ) {
768
                                return \strnatcmp( $a['label'], $b['label'] );
769
                        }
770
                );
771

772
                return $transformed;
773
        }
774

775
        /**
776
         * Gets the route from a name, rewrite and rest_base.
777
         *
778
         * @param string $name      The name.
779
         * @param array  $rewrite   The rewrite data.
780
         * @param string $rest_base The rest base.
781
         *
782
         * @return string The route.
783
         */
784
        protected function get_route( $name, $rewrite, $rest_base ) {
785
                $route = $name;
786
                if ( isset( $rewrite['slug'] ) ) {
787
                        $route = $rewrite['slug'];
788
                }
789
                if ( ! empty( $rest_base ) ) {
790
                        $route = $rest_base;
791
                }
792
                // Always strip leading slashes.
793
                while ( \substr( $route, 0, 1 ) === '/' ) {
794
                        $route = \substr( $route, 1 );
795
                }
796

797
                return \rawurlencode( $route );
798
        }
799

800
        /**
801
         * Retrieves the fallbacks.
802
         *
803
         * @return array The fallbacks.
804
         */
805
        protected function get_fallbacks() {
806
                $site_logo_id = \get_option( 'site_logo' );
807
                if ( ! $site_logo_id ) {
808
                        $site_logo_id = \get_theme_mod( 'custom_logo' );
809
                }
810
                if ( ! $site_logo_id ) {
811
                        $site_logo_id = '0';
812
                }
813

814
                return [
815
                        'siteLogoId' => $site_logo_id,
816
                ];
817
        }
818

819
        /**
820
         * Removes the notification related to the post types which have been made public.
821
         *
822
         * @return void
823
         */
824
        private function remove_post_types_made_public_notification() {
825
                $notification_center = Yoast_Notification_Center::get();
826
                $notification_center->remove_notification_by_id( 'post-types-made-public' );
827
        }
828

829
        /**
830
         * Removes the notification related to the taxonomies which have been made public.
831
         *
832
         * @return void
833
         */
834
        private function remove_taxonomies_made_public_notification() {
835
                $notification_center = Yoast_Notification_Center::get();
836
                $notification_center->remove_notification_by_id( 'taxonomies-made-public' );
837
        }
838
}
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