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

Yoast / wordpress-seo / 690a94f3a2f5b90a5eaa9513ba5e3190f1c0d4af

21 May 2025 09:32AM UTC coverage: 52.795% (-0.2%) from 53.032%
690a94f3a2f5b90a5eaa9513ba5e3190f1c0d4af

push

github

web-flow
Merge pull request #22291 from Yoast/feature/llms-txt

Introduce the llms.txt feature

8175 of 14237 branches covered (57.42%)

Branch coverage included in aggregate %.

52 of 406 new or added lines in 31 files covered. (12.81%)

2 existing lines in 2 files now uncovered.

29656 of 57419 relevant lines covered (51.65%)

41580.34 hits per line

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

25.95
/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_Addon_Manager;
10
use WPSEO_Admin_Asset_Manager;
11
use WPSEO_Admin_Editor_Specific_Replace_Vars;
12
use WPSEO_Admin_Recommended_Replace_Vars;
13
use WPSEO_Option_Titles;
14
use WPSEO_Options;
15
use WPSEO_Replace_Vars;
16
use WPSEO_Shortlinker;
17
use WPSEO_Sitemaps_Router;
18
use Yoast\WP\SEO\Conditionals\Settings_Conditional;
19
use Yoast\WP\SEO\Config\Schema_Types;
20
use Yoast\WP\SEO\Content_Type_Visibility\Application\Content_Type_Visibility_Dismiss_Notifications;
21
use Yoast\WP\SEO\Helpers\Current_Page_Helper;
22
use Yoast\WP\SEO\Helpers\Language_Helper;
23
use Yoast\WP\SEO\Helpers\Options_Helper;
24
use Yoast\WP\SEO\Helpers\Post_Type_Helper;
25
use Yoast\WP\SEO\Helpers\Product_Helper;
26
use Yoast\WP\SEO\Helpers\Schema\Article_Helper;
27
use Yoast\WP\SEO\Helpers\Taxonomy_Helper;
28
use Yoast\WP\SEO\Helpers\User_Helper;
29
use Yoast\WP\SEO\Helpers\Woocommerce_Helper;
30
use Yoast\WP\SEO\Promotions\Application\Promotion_Manager;
31

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

37
        public const PAGE = 'wpseo_page_settings';
38

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

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

53
        /**
54
         * Holds the disallowed settings, per option group.
55
         *
56
         * @var array
57
         */
58
        public const DISALLOWED_SETTINGS = [
59
                'wpseo'        => [
60
                        'myyoast-oauth',
61
                        'semrush_tokens',
62
                        'custom_taxonomy_slugs',
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
                        'enable_llms_txt',
97
                ],
98
        ];
99

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

259
                // Are we saving the settings?
260
                if ( $this->current_page_helper->get_current_admin_page() === 'options.php' ) {
×
261
                        $post_action = '';
×
262
                        // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: We are not processing form information.
263
                        if ( isset( $_POST['action'] ) && \is_string( $_POST['action'] ) ) {
×
264
                                // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information.
265
                                $post_action = \wp_unslash( $_POST['action'] );
×
266
                        }
267
                        $option_page = '';
×
268
                        // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: We are not processing form information.
269
                        if ( isset( $_POST['option_page'] ) && \is_string( $_POST['option_page'] ) ) {
×
270
                                // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information.
271
                                $option_page = \wp_unslash( $_POST['option_page'] );
×
272
                        }
273

274
                        if ( $post_action === 'update' && $option_page === self::PAGE ) {
×
275
                                \add_action( 'admin_init', [ $this, 'register_setting' ] );
×
276
                                \add_action( 'in_admin_header', [ $this, 'remove_notices' ], \PHP_INT_MAX );
×
277
                        }
278

279
                        return;
×
280
                }
281

282
                // Are we on the settings page?
283
                if ( $this->current_page_helper->get_current_yoast_seo_page() === self::PAGE ) {
×
284
                        \add_action( 'admin_init', [ $this, 'register_setting' ] );
×
285
                        \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
×
286
                        \add_action( 'in_admin_header', [ $this, 'remove_notices' ], \PHP_INT_MAX );
×
287
                }
288
        }
289

290
        /**
291
         * Registers the different options under the setting.
292
         *
293
         * @return void
294
         */
295
        public function register_setting() {
×
296
                foreach ( WPSEO_Options::$options as $name => $instance ) {
×
297
                        if ( \in_array( $name, self::ALLOWED_OPTION_GROUPS, true ) ) {
×
298
                                \register_setting( self::PAGE, $name );
×
299
                        }
300
                }
301
                // Only register WP options when the user is allowed to manage them.
302
                if ( \current_user_can( 'manage_options' ) ) {
×
303
                        foreach ( self::WP_OPTIONS as $name ) {
×
304
                                \register_setting( self::PAGE, $name );
×
305
                        }
306
                }
307
        }
308

309
        /**
310
         * Adds the page.
311
         *
312
         * @param array $pages The pages.
313
         *
314
         * @return array The pages.
315
         */
316
        public function add_page( $pages ) {
×
317
                \array_splice(
×
318
                        $pages,
×
319
                        1,
×
320
                        0,
×
321
                        [
×
322
                                [
×
323
                                        'wpseo_dashboard',
×
324
                                        '',
×
325
                                        \__( 'Settings', 'wordpress-seo' ),
×
326
                                        'wpseo_manage_options',
×
327
                                        self::PAGE,
×
328
                                        [ $this, 'display_page' ],
×
329
                                ],
×
330
                        ]
×
331
                );
×
332

333
                return $pages;
×
334
        }
335

336
        /**
337
         * Adds a dummy page.
338
         *
339
         * Because the options route NEEDS to redirect to something.
340
         *
341
         * @param array $pages The pages.
342
         *
343
         * @return array The pages.
344
         */
345
        public function add_settings_saved_page( $pages ) {
2✔
346
                \add_submenu_page(
2✔
347
                        '',
2✔
348
                        '',
2✔
349
                        '',
2✔
350
                        'wpseo_manage_options',
2✔
351
                        self::PAGE . '_saved',
2✔
352
                        static function () {
2✔
353
                                // Add success indication to HTML response.
354
                                $success = empty( \get_settings_errors() ) ? 'true' : 'false';
×
355
                                echo \esc_html( "{{ yoast-success: $success }}" );
×
356
                        }
2✔
357
                );
2✔
358

359
                return $pages;
2✔
360
        }
361

362
        /**
363
         * Displays the page.
364
         *
365
         * @return void
366
         */
367
        public function display_page() {
×
368
                echo '<div id="yoast-seo-settings"></div>';
×
369
        }
370

371
        /**
372
         * Enqueues the assets.
373
         *
374
         * @return void
375
         */
376
        public function enqueue_assets() {
×
377
                // Remove the emoji script as it is incompatible with both React and any contenteditable fields.
378
                \remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
×
379
                \wp_enqueue_media();
×
380
                $this->asset_manager->enqueue_script( 'new-settings' );
×
381
                $this->asset_manager->enqueue_style( 'new-settings' );
×
382
                if ( \YoastSEO()->classes->get( Promotion_Manager::class )->is( 'black-friday-2024-promotion' ) ) {
×
383
                        $this->asset_manager->enqueue_style( 'black-friday-banner' );
×
384
                }
385
                $this->asset_manager->localize_script( 'new-settings', 'wpseoScriptData', $this->get_script_data() );
×
386
        }
387

388
        /**
389
         * Removes all current WP notices.
390
         *
391
         * @return void
392
         */
393
        public function remove_notices() {
×
394
                \remove_all_actions( 'admin_notices' );
×
395
                \remove_all_actions( 'user_admin_notices' );
×
396
                \remove_all_actions( 'network_admin_notices' );
×
397
                \remove_all_actions( 'all_admin_notices' );
×
398
        }
399

400
        /**
401
         * Creates the script data.
402
         *
403
         * @return array The script data.
404
         */
405
        protected function get_script_data() {
×
406
                $default_setting_values = $this->get_default_setting_values();
×
407
                $settings               = $this->get_settings( $default_setting_values );
×
408
                $post_types             = $this->post_type_helper->get_indexable_post_type_objects();
×
409
                $taxonomies             = $this->taxonomy_helper->get_indexable_taxonomy_objects();
×
410

411
                // Check if attachments are included in indexation.
412
                if ( ! \array_key_exists( 'attachment', $post_types ) ) {
×
413
                        // Always include attachments in the settings, to let the user enable them again.
414
                        $attachment_object = \get_post_type_object( 'attachment' );
×
415
                        if ( ! empty( $attachment_object ) ) {
×
416
                                $post_types['attachment'] = $attachment_object;
×
417
                        }
418
                }
419
                // Check if post formats are included in indexation.
420
                if ( ! \array_key_exists( 'post_format', $taxonomies ) ) {
×
421
                        // Always include post_format in the settings, to let the user enable them again.
422
                        $post_format_object = \get_taxonomy( 'post_format' );
×
423
                        if ( ! empty( $post_format_object ) ) {
×
424
                                $taxonomies['post_format'] = $post_format_object;
×
425
                        }
426
                }
427

428
                $transformed_post_types = $this->transform_post_types( $post_types );
×
429
                $transformed_taxonomies = $this->transform_taxonomies( $taxonomies, \array_keys( $transformed_post_types ) );
×
430

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

434
                return [
×
435
                        'settings'                       => $this->transform_settings( $settings ),
×
436
                        'defaultSettingValues'           => $default_setting_values,
×
437
                        'disabledSettings'               => $this->get_disabled_settings( $settings ),
×
438
                        'endpoint'                       => \admin_url( 'options.php' ),
×
439
                        'nonce'                          => \wp_create_nonce( self::PAGE . '-options' ),
×
440
                        'separators'                     => WPSEO_Option_Titles::get_instance()->get_separator_options_for_display(),
×
441
                        'replacementVariables'           => $this->get_replacement_variables(),
×
442
                        'schema'                         => $this->get_schema( $transformed_post_types ),
×
443
                        'preferences'                    => $this->get_preferences( $settings ),
×
444
                        'linkParams'                     => WPSEO_Shortlinker::get_query_params(),
×
445
                        'postTypes'                      => $transformed_post_types,
×
446
                        'taxonomies'                     => $transformed_taxonomies,
×
447
                        'fallbacks'                      => $this->get_fallbacks(),
×
448
                        'showNewContentTypeNotification' => $show_new_content_type_notification,
×
449
                        'currentPromotions'              => \YoastSEO()->classes->get( Promotion_Manager::class )->get_current_promotions(),
×
450
                ];
×
451
        }
452

453
        /**
454
         * Retrieves the preferences.
455
         *
456
         * @param array $settings The settings.
457
         *
458
         * @return array The preferences.
459
         */
460
        protected function get_preferences( $settings ) {
×
461
                $shop_page_id             = $this->woocommerce_helper->get_shop_page_id();
×
462
                $homepage_is_latest_posts = \get_option( 'show_on_front' ) === 'posts';
×
463
                $page_on_front            = \get_option( 'page_on_front' );
×
464
                $page_for_posts           = \get_option( 'page_for_posts' );
×
465

466
                $addon_manager          = new WPSEO_Addon_Manager();
×
467
                $woocommerce_seo_active = \is_plugin_active( $addon_manager->get_plugin_file( WPSEO_Addon_Manager::WOOCOMMERCE_SLUG ) );
×
468

469
                if ( empty( $page_on_front ) ) {
×
470
                        $page_on_front = $page_for_posts;
×
471
                }
472

473
                $business_settings_url = \get_admin_url( null, 'admin.php?page=wpseo_local' );
×
474
                if ( \defined( 'WPSEO_LOCAL_FILE' ) ) {
×
475
                        $local_options      = \get_option( 'wpseo_local' );
×
476
                        $multiple_locations = $local_options['use_multiple_locations'];
×
477
                        $same_organization  = $local_options['multiple_locations_same_organization'];
×
478
                        if ( $multiple_locations === 'on' && $same_organization !== 'on' ) {
×
479
                                $business_settings_url = \get_admin_url( null, 'edit.php?post_type=wpseo_locations' );
×
480
                        }
481
                }
482

483
                return [
×
484
                        'isPremium'                     => $this->product_helper->is_premium(),
×
485
                        'isRtl'                         => \is_rtl(),
×
486
                        'isNetworkAdmin'                => \is_network_admin(),
×
487
                        'isMainSite'                    => \is_main_site(),
×
488
                        'isMultisite'                   => \is_multisite(),
×
489
                        'isWooCommerceActive'           => $this->woocommerce_helper->is_active(),
×
490
                        'isLocalSeoActive'              => \defined( 'WPSEO_LOCAL_FILE' ),
×
491
                        'isNewsSeoActive'               => \defined( 'WPSEO_NEWS_FILE' ),
×
492
                        'isWooCommerceSEOActive'        => $woocommerce_seo_active,
×
493
                        'siteUrl'                       => \get_bloginfo( 'url' ),
×
494
                        'siteTitle'                     => \get_bloginfo( 'name' ),
×
495
                        'sitemapUrl'                    => WPSEO_Sitemaps_Router::get_base_url( 'sitemap_index.xml' ),
×
496
                        'hasWooCommerceShopPage'        => $shop_page_id !== -1,
×
497
                        'editWooCommerceShopPageUrl'    => \get_edit_post_link( $shop_page_id, 'js' ),
×
498
                        'wooCommerceShopPageSettingUrl' => \get_admin_url( null, 'admin.php?page=wc-settings&tab=products' ),
×
499
                        'localSeoPageSettingUrl'        => $business_settings_url,
×
500
                        'homepageIsLatestPosts'         => $homepage_is_latest_posts,
×
501
                        'homepagePageEditUrl'           => \get_edit_post_link( $page_on_front, 'js' ),
×
502
                        'homepagePostsEditUrl'          => \get_edit_post_link( $page_for_posts, 'js' ),
×
503
                        'createUserUrl'                 => \admin_url( 'user-new.php' ),
×
504
                        'createPageUrl'                 => \admin_url( 'post-new.php?post_type=page' ),
×
505
                        'editUserUrl'                   => \admin_url( 'user-edit.php' ),
×
506
                        'editTaxonomyUrl'               => \admin_url( 'edit-tags.php' ),
×
507
                        'generalSettingsUrl'            => \admin_url( 'options-general.php' ),
×
508
                        'companyOrPersonMessage'        => \apply_filters( 'wpseo_knowledge_graph_setting_msg', '' ),
×
509
                        'currentUserId'                 => \get_current_user_id(),
×
510
                        'canCreateUsers'                => \current_user_can( 'create_users' ),
×
511
                        'canCreatePages'                => \current_user_can( 'edit_pages' ),
×
512
                        'canEditUsers'                  => \current_user_can( 'edit_users' ),
×
513
                        'canManageOptions'              => \current_user_can( 'manage_options' ),
×
514
                        'userLocale'                    => \str_replace( '_', '-', \get_user_locale() ),
×
515
                        'pluginUrl'                     => \plugins_url( '', \WPSEO_FILE ),
×
516
                        'showForceRewriteTitlesSetting' => ! \current_theme_supports( 'title-tag' ) && ! ( \function_exists( 'wp_is_block_theme' ) && \wp_is_block_theme() ),
×
517
                        'upsellSettings'                => $this->get_upsell_settings(),
×
518
                        'siteRepresentsPerson'          => $this->get_site_represents_person( $settings ),
×
519
                        'siteBasicsPolicies'            => $this->get_site_basics_policies( $settings ),
×
NEW
520
                        'llmsTxtUrl'                    => \home_url( 'llms.txt' ),
×
UNCOV
521
                ];
×
522
        }
523

524
        /**
525
         * Retrieves the currently represented person.
526
         *
527
         * @param array $settings The settings.
528
         *
529
         * @return array The currently represented person's ID and name.
530
         */
531
        protected function get_site_represents_person( $settings ) {
×
532
                $person = [
×
533
                        'id'   => false,
×
534
                        'name' => '',
×
535
                ];
×
536

537
                if ( isset( $settings['wpseo_titles']['company_or_person_user_id'] ) ) {
×
538
                        $person['id'] = $settings['wpseo_titles']['company_or_person_user_id'];
×
539
                        $user         = \get_userdata( $person['id'] );
×
540
                        if ( $user instanceof WP_User ) {
×
541
                                $person['name'] = $user->get( 'display_name' );
×
542
                        }
543
                }
544

545
                return $person;
×
546
        }
547

548
        /**
549
         * Get site policy data.
550
         *
551
         * @param array $settings The settings.
552
         *
553
         * @return array The policy data.
554
         */
555
        private function get_site_basics_policies( $settings ) {
×
556
                $policies = [];
×
557

558
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['publishing_principles_id'], 'publishing_principles_id' );
×
559
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['ownership_funding_info_id'], 'ownership_funding_info_id' );
×
560
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['actionable_feedback_policy_id'], 'actionable_feedback_policy_id' );
×
561
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['corrections_policy_id'], 'corrections_policy_id' );
×
562
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['ethics_policy_id'], 'ethics_policy_id' );
×
563
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['diversity_policy_id'], 'diversity_policy_id' );
×
564
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['diversity_staffing_report_id'], 'diversity_staffing_report_id' );
×
565

566
                return $policies;
×
567
        }
568

569
        /**
570
         * Adds policy data if it is present.
571
         *
572
         * @param array  $policies The existing policy data.
573
         * @param int    $policy   The policy id to check.
574
         * @param string $key      The option key name.
575
         *
576
         * @return array<int, string> The policy data.
577
         */
578
        private function maybe_add_policy( $policies, $policy, $key ) {
×
579
                $policy_array = [
×
580
                        'id'   => 0,
×
581
                        'name' => \__( 'None', 'wordpress-seo' ),
×
582
                ];
×
583

584
                if ( isset( $policy ) && \is_int( $policy ) ) {
×
585
                        $policy_array['id'] = $policy;
×
586
                        $post               = \get_post( $policy );
×
587
                        if ( $post instanceof WP_Post ) {
×
588
                                if ( $post->post_status !== 'publish' || $post->post_password !== '' ) {
×
589
                                        return $policies;
×
590
                                }
591
                                $policy_array['name'] = $post->post_title;
×
592
                        }
593
                }
594

595
                $policies[ $key ] = $policy_array;
×
596

597
                return $policies;
×
598
        }
599

600
        /**
601
         * Returns settings for the Call to Buy (CTB) buttons.
602
         *
603
         * @return array<string> The array of CTB settings.
604
         */
605
        public function get_upsell_settings() {
×
606
                return [
×
607
                        'actionId'     => 'load-nfd-ctb',
×
608
                        'premiumCtbId' => 'f6a84663-465f-4cb5-8ba5-f7a6d72224b2',
×
609
                ];
×
610
        }
611

612
        /**
613
         * Retrieves the default setting values.
614
         *
615
         * These default values are currently being used in the UI for dummy fields.
616
         * Dummy fields should not expose or reflect the actual data.
617
         *
618
         * @return array The default setting values.
619
         */
620
        protected function get_default_setting_values() {
×
621
                $defaults = [];
×
622

623
                // Add Yoast settings.
624
                foreach ( WPSEO_Options::$options as $option_name => $instance ) {
×
625
                        if ( \in_array( $option_name, self::ALLOWED_OPTION_GROUPS, true ) ) {
×
626
                                $option_instance          = WPSEO_Options::get_option_instance( $option_name );
×
627
                                $defaults[ $option_name ] = ( $option_instance ) ? $option_instance->get_defaults() : [];
×
628
                        }
629
                }
630
                // Add WP settings.
631
                foreach ( self::WP_OPTIONS as $option_name ) {
×
632
                        $defaults[ $option_name ] = '';
×
633
                }
634

635
                // Remove disallowed settings.
636
                foreach ( self::DISALLOWED_SETTINGS as $option_name => $disallowed_settings ) {
×
637
                        foreach ( $disallowed_settings as $disallowed_setting ) {
×
638
                                unset( $defaults[ $option_name ][ $disallowed_setting ] );
×
639
                        }
640
                }
641

642
                if ( \defined( 'WPSEO_LOCAL_FILE' ) ) {
×
643
                        $defaults = $this->get_defaults_from_local_seo( $defaults );
×
644
                }
645

646
                return $defaults;
×
647
        }
648

649
        /**
650
         * Retrieves the organization schema values from Local SEO for defaults in Site representation fields.
651
         * Specifically for the org-vat-id, org-tax-id, org-email and org-phone options.
652
         *
653
         * @param array<string|int|bool> $defaults The settings defaults.
654
         *
655
         * @return array<string|int|bool> The settings defaults with local seo overides.
656
         */
657
        protected function get_defaults_from_local_seo( $defaults ) {
8✔
658
                $local_options      = \get_option( 'wpseo_local' );
8✔
659
                $multiple_locations = $local_options['use_multiple_locations'];
8✔
660
                $same_organization  = $local_options['multiple_locations_same_organization'];
8✔
661
                $shared_info        = $local_options['multiple_locations_shared_business_info'];
8✔
662
                if ( $multiple_locations !== 'on' || ( $multiple_locations === 'on' && $same_organization === 'on' && $shared_info === 'on' ) ) {
8✔
663
                        $defaults['wpseo_titles']['org-vat-id'] = $local_options['location_vat_id'];
6✔
664
                        $defaults['wpseo_titles']['org-tax-id'] = $local_options['location_tax_id'];
6✔
665
                        $defaults['wpseo_titles']['org-email']  = $local_options['location_email'];
6✔
666
                        $defaults['wpseo_titles']['org-phone']  = $local_options['location_phone'];
6✔
667
                }
668

669
                if ( \wpseo_has_primary_location() ) {
8✔
670
                        $primary_location = $local_options['multiple_locations_primary_location'];
4✔
671

672
                        $location_keys = [
4✔
673
                                'org-phone'  => [
4✔
674
                                        'is_overridden' => '_wpseo_is_overridden_business_phone',
4✔
675
                                        'value'         => '_wpseo_business_phone',
4✔
676
                                ],
4✔
677
                                'org-email'  => [
4✔
678
                                        'is_overridden' => '_wpseo_is_overridden_business_email',
4✔
679
                                        'value'         => '_wpseo_business_email',
4✔
680
                                ],
4✔
681
                                'org-tax-id' => [
4✔
682
                                        'is_overridden' => '_wpseo_is_overridden_business_tax_id',
4✔
683
                                        'value'         => '_wpseo_business_tax_id',
4✔
684
                                ],
4✔
685
                                'org-vat-id' => [
4✔
686
                                        'is_overridden' => '_wpseo_is_overridden_business_vat_id',
4✔
687
                                        'value'         => '_wpseo_business_vat_id',
4✔
688
                                ],
4✔
689
                        ];
4✔
690

691
                        foreach ( $location_keys as $key => $meta_keys ) {
4✔
692
                                $is_overridden = ( $shared_info === 'on' ) ? \get_post_meta( $primary_location, $meta_keys['is_overridden'], true ) : false;
4✔
693
                                if ( $is_overridden === 'on' || $shared_info !== 'on' ) {
4✔
694
                                        $post_meta_value                  = \get_post_meta( $primary_location, $meta_keys['value'], true );
4✔
695
                                        $defaults['wpseo_titles'][ $key ] = ( $post_meta_value ) ? $post_meta_value : '';
4✔
696
                                }
697
                        }
698
                }
699

700
                return $defaults;
8✔
701
        }
702

703
        /**
704
         * Retrieves the settings and their values.
705
         *
706
         * @param array $default_setting_values The default setting values.
707
         *
708
         * @return array The settings.
709
         */
710
        protected function get_settings( $default_setting_values ) {
×
711
                $settings = [];
×
712

713
                // Add Yoast settings.
714
                foreach ( WPSEO_Options::$options as $option_name => $instance ) {
×
715
                        if ( \in_array( $option_name, self::ALLOWED_OPTION_GROUPS, true ) ) {
×
716
                                $settings[ $option_name ] = \array_merge( $default_setting_values[ $option_name ], WPSEO_Options::get_option( $option_name ) );
×
717
                        }
718
                }
719
                // Add WP settings.
720
                foreach ( self::WP_OPTIONS as $option_name ) {
×
721
                        $settings[ $option_name ] = \get_option( $option_name );
×
722
                }
723

724
                // Remove disallowed settings.
725
                foreach ( self::DISALLOWED_SETTINGS as $option_name => $disallowed_settings ) {
×
726
                        foreach ( $disallowed_settings as $disallowed_setting ) {
×
727
                                unset( $settings[ $option_name ][ $disallowed_setting ] );
×
728
                        }
729
                }
730

731
                return $settings;
×
732
        }
733

734
        /**
735
         * Transforms setting values.
736
         *
737
         * @param array $settings The settings.
738
         *
739
         * @return array The settings.
740
         */
741
        protected function transform_settings( $settings ) {
×
742
                if ( isset( $settings['wpseo_titles']['breadcrumbs-sep'] ) ) {
×
743
                        /**
744
                         * The breadcrumbs separator default value is the HTML entity `&raquo;`.
745
                         * Which does not get decoded in our JS, while it did in our Yoast form. Decode it here as an exception.
746
                         */
747
                        $settings['wpseo_titles']['breadcrumbs-sep'] = \html_entity_decode(
×
748
                                $settings['wpseo_titles']['breadcrumbs-sep'],
×
749
                                ( \ENT_NOQUOTES | \ENT_HTML5 ),
×
750
                                'UTF-8'
×
751
                        );
×
752
                }
753

754
                /**
755
                 * Decode some WP options.
756
                 */
757
                $settings['blogdescription'] = \html_entity_decode(
×
758
                        $settings['blogdescription'],
×
759
                        ( \ENT_NOQUOTES | \ENT_HTML5 ),
×
760
                        'UTF-8'
×
761
                );
×
762

763
                return $settings;
×
764
        }
765

766
        /**
767
         * Retrieves the disabled settings.
768
         *
769
         * @param array $settings The settings.
770
         *
771
         * @return array The settings.
772
         */
773
        protected function get_disabled_settings( $settings ) {
×
774
                $disabled_settings = [];
×
775
                $site_language     = $this->language_helper->get_language();
×
776

777
                foreach ( WPSEO_Options::$options as $option_name => $instance ) {
×
778
                        if ( ! \in_array( $option_name, self::ALLOWED_OPTION_GROUPS, true ) ) {
×
779
                                continue;
×
780
                        }
781

782
                        $disabled_settings[ $option_name ] = [];
×
783
                        $option_instance                   = WPSEO_Options::get_option_instance( $option_name );
×
784
                        if ( $option_instance === false ) {
×
785
                                continue;
×
786
                        }
787
                        foreach ( $settings[ $option_name ] as $setting_name => $setting_value ) {
×
788
                                if ( $option_instance->is_disabled( $setting_name ) ) {
×
789
                                        $disabled_settings[ $option_name ][ $setting_name ] = 'network';
×
790
                                }
791
                        }
792
                }
793

794
                // Remove disabled on multisite settings.
795
                if ( \is_multisite() ) {
×
796
                        foreach ( self::DISABLED_ON_MULTISITE_SETTINGS as $option_name => $disabled_ms_settings ) {
×
797
                                if ( \array_key_exists( $option_name, $disabled_settings ) ) {
×
798
                                        foreach ( $disabled_ms_settings as $disabled_ms_setting ) {
×
799
                                                $disabled_settings[ $option_name ][ $disabled_ms_setting ] = 'multisite';
×
800
                                        }
801
                                }
802
                        }
803
                }
804

805
                if ( \array_key_exists( 'wpseo', $disabled_settings ) && ! $this->language_helper->has_inclusive_language_support( $site_language ) ) {
×
806
                        $disabled_settings['wpseo']['inclusive_language_analysis_active'] = 'language';
×
807
                }
808

809
                return $disabled_settings;
×
810
        }
811

812
        /**
813
         * Retrieves the replacement variables.
814
         *
815
         * @return array The replacement variables.
816
         */
817
        protected function get_replacement_variables() {
×
818
                $recommended_replace_vars = new WPSEO_Admin_Recommended_Replace_Vars();
×
819
                $specific_replace_vars    = new WPSEO_Admin_Editor_Specific_Replace_Vars();
×
820
                $replacement_variables    = $this->replace_vars->get_replacement_variables_with_labels();
×
821

822
                return [
×
823
                        'variables'   => $replacement_variables,
×
824
                        'recommended' => $recommended_replace_vars->get_recommended_replacevars(),
×
825
                        'specific'    => $specific_replace_vars->get(),
×
826
                        'shared'      => $specific_replace_vars->get_generic( $replacement_variables ),
×
827
                ];
×
828
        }
829

830
        /**
831
         * Retrieves the schema.
832
         *
833
         * @param array $post_types The post types.
834
         *
835
         * @return array The schema.
836
         */
837
        protected function get_schema( array $post_types ) {
×
838
                $schema = [];
×
839

840
                foreach ( $this->schema_types->get_article_type_options() as $article_type ) {
×
841
                        $schema['articleTypes'][ $article_type['value'] ] = [
×
842
                                'label' => $article_type['name'],
×
843
                                'value' => $article_type['value'],
×
844
                        ];
×
845
                }
846

847
                foreach ( $this->schema_types->get_page_type_options() as $page_type ) {
×
848
                        $schema['pageTypes'][ $page_type['value'] ] = [
×
849
                                'label' => $page_type['name'],
×
850
                                'value' => $page_type['value'],
×
851
                        ];
×
852
                }
853

854
                $schema['articleTypeDefaults'] = [];
×
855
                $schema['pageTypeDefaults']    = [];
×
856
                foreach ( $post_types as $name => $post_type ) {
×
857
                        $schema['articleTypeDefaults'][ $name ] = WPSEO_Options::get_default( 'wpseo_titles', "schema-article-type-$name" );
×
858
                        $schema['pageTypeDefaults'][ $name ]    = WPSEO_Options::get_default( 'wpseo_titles', "schema-page-type-$name" );
×
859
                }
860

861
                return $schema;
×
862
        }
863

864
        /**
865
         * Transforms the post types, to represent them.
866
         *
867
         * @param WP_Post_Type[] $post_types The WP_Post_Type array to transform.
868
         *
869
         * @return array The post types.
870
         */
871
        protected function transform_post_types( $post_types ) {
4✔
872
                $transformed    = [];
4✔
873
                $new_post_types = $this->options->get( 'new_post_types', [] );
4✔
874
                foreach ( $post_types as $post_type ) {
4✔
875
                        $transformed[ $post_type->name ] = [
4✔
876
                                'name'                 => $post_type->name,
4✔
877
                                'route'                => $this->get_route( $post_type->name, $post_type->rewrite, $post_type->rest_base ),
4✔
878
                                'label'                => $post_type->label,
4✔
879
                                'singularLabel'        => $post_type->labels->singular_name,
4✔
880
                                'hasArchive'           => $this->post_type_helper->has_archive( $post_type ),
4✔
881
                                'hasSchemaArticleType' => $this->article_helper->is_article_post_type( $post_type->name ),
4✔
882
                                'menuPosition'         => $post_type->menu_position,
4✔
883
                                'isNew'                => \in_array( $post_type->name, $new_post_types, true ),
4✔
884
                        ];
4✔
885
                }
886

887
                \uasort( $transformed, [ $this, 'compare_post_types' ] );
4✔
888

889
                return $transformed;
4✔
890
        }
891

892
        /**
893
         * Compares two post types.
894
         *
895
         * @param array $a The first post type.
896
         * @param array $b The second post type.
897
         *
898
         * @return int The order.
899
         */
900
        protected function compare_post_types( $a, $b ) {
×
901
                if ( $a['menuPosition'] === null && $b['menuPosition'] !== null ) {
×
902
                        return 1;
×
903
                }
904
                if ( $a['menuPosition'] !== null && $b['menuPosition'] === null ) {
×
905
                        return -1;
×
906
                }
907

908
                if ( $a['menuPosition'] === null && $b['menuPosition'] === null ) {
×
909
                        // No position specified, order alphabetically by label.
910
                        return \strnatcmp( $a['label'], $b['label'] );
×
911
                }
912

913
                return ( ( $a['menuPosition'] < $b['menuPosition'] ) ? -1 : 1 );
×
914
        }
915

916
        /**
917
         * Transforms the taxonomies, to represent them.
918
         *
919
         * @param WP_Taxonomy[] $taxonomies      The WP_Taxonomy array to transform.
920
         * @param string[]      $post_type_names The post type names.
921
         *
922
         * @return array The taxonomies.
923
         */
924
        protected function transform_taxonomies( $taxonomies, $post_type_names ) {
4✔
925
                $transformed    = [];
4✔
926
                $new_taxonomies = $this->options->get( 'new_taxonomies', [] );
4✔
927
                foreach ( $taxonomies as $taxonomy ) {
4✔
928
                        $transformed[ $taxonomy->name ] = [
4✔
929
                                'name'          => $taxonomy->name,
4✔
930
                                'route'         => $this->get_route( $taxonomy->name, $taxonomy->rewrite, $taxonomy->rest_base ),
4✔
931
                                'label'         => $taxonomy->label,
4✔
932
                                'showUi'        => $taxonomy->show_ui,
4✔
933
                                'singularLabel' => $taxonomy->labels->singular_name,
4✔
934
                                'postTypes'     => \array_filter(
4✔
935
                                        $taxonomy->object_type,
4✔
936
                                        static function ( $object_type ) use ( $post_type_names ) {
4✔
937
                                                return \in_array( $object_type, $post_type_names, true );
4✔
938
                                        }
4✔
939
                                ),
4✔
940
                                'isNew'         => \in_array( $taxonomy->name, $new_taxonomies, true ),
4✔
941
                        ];
4✔
942
                }
943

944
                \uasort(
4✔
945
                        $transformed,
4✔
946
                        static function ( $a, $b ) {
4✔
947
                                return \strnatcmp( $a['label'], $b['label'] );
948
                        }
4✔
949
                );
4✔
950

951
                return $transformed;
952
        }
953

954
        /**
955
         * Gets the route from a name, rewrite and rest_base.
956
         *
957
         * @param string $name      The name.
958
         * @param array  $rewrite   The rewrite data.
959
         * @param string $rest_base The rest base.
960
         *
961
         * @return string The route.
962
         */
963
        protected function get_route( $name, $rewrite, $rest_base ) {
×
964
                $route = $name;
×
965
                if ( isset( $rewrite['slug'] ) ) {
966
                        $route = $rewrite['slug'];
×
967
                }
968
                if ( ! empty( $rest_base ) ) {
969
                        $route = $rest_base;
970
                }
971
                // Always strip leading slashes.
972
                while ( \substr( $route, 0, 1 ) === '/' ) {
973
                        $route = \substr( $route, 1 );
974
                }
975

976
                return $route;
977
        }
978

979
        /**
980
         * Retrieves the fallbacks.
981
         *
982
         * @return array The fallbacks.
983
         */
984
        protected function get_fallbacks() {
×
985
                $site_logo_id = \get_option( 'site_logo' );
×
986
                if ( ! $site_logo_id ) {
987
                        $site_logo_id = \get_theme_mod( 'custom_logo' );
×
988
                }
989
                if ( ! $site_logo_id ) {
990
                        $site_logo_id = '0';
991
                }
992

993
                return [
×
994
                        'siteLogoId' => $site_logo_id,
×
995
                ];
×
996
        }
997
}
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