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

Yoast / wordpress-seo / 641227ab424e929957df4533d4c1c867610a932f

27 Jun 2025 11:16AM UTC coverage: 53.857% (-0.03%) from 53.885%
641227ab424e929957df4533d4c1c867610a932f

push

github

web-flow
Merge pull request #22345 from Yoast/625-create-and-scaffold-the-new-settings-page-for-llmstxt

Create the llms.txt settings page with some first elements

8246 of 14343 branches covered (57.49%)

Branch coverage included in aggregate %.

3 of 42 new or added lines in 6 files covered. (7.14%)

1 existing line in 1 file now uncovered.

30490 of 57581 relevant lines covered (52.95%)

41466.14 hits per line

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

26.14
/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\Llms_Txt\Application\Configuration\Llms_Txt_Configuration;
31
use Yoast\WP\SEO\Promotions\Application\Promotion_Manager;
32

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

38
        public const PAGE = 'wpseo_page_settings';
39

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

192
        /**
193
         * Holds the Llms_Txt_Configuration instance.
194
         *
195
         * @var Llms_Txt_Configuration
196
         */
197
        protected $llms_txt_configuration;
198

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

249
        /**
250
         * Returns the conditionals based on which this loadable should be active.
251
         *
252
         * @return array
253
         */
254
        public static function get_conditionals() {
2✔
255
                return [ Settings_Conditional::class ];
2✔
256
        }
257

258
        /**
259
         * Initializes the integration.
260
         *
261
         * This is the place to register hooks and filters.
262
         *
263
         * @return void
264
         */
265
        public function register_hooks() {
×
266
                // Add page.
267
                \add_filter( 'wpseo_submenu_pages', [ $this, 'add_page' ] );
×
268
                \add_filter( 'admin_menu', [ $this, 'add_settings_saved_page' ] );
×
269

270
                // Are we saving the settings?
271
                if ( $this->current_page_helper->get_current_admin_page() === 'options.php' ) {
×
272
                        $post_action = '';
×
273
                        // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: We are not processing form information.
274
                        if ( isset( $_POST['action'] ) && \is_string( $_POST['action'] ) ) {
×
275
                                // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information.
276
                                $post_action = \wp_unslash( $_POST['action'] );
×
277
                        }
278
                        $option_page = '';
×
279
                        // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: We are not processing form information.
280
                        if ( isset( $_POST['option_page'] ) && \is_string( $_POST['option_page'] ) ) {
×
281
                                // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information.
282
                                $option_page = \wp_unslash( $_POST['option_page'] );
×
283
                        }
284

285
                        if ( $post_action === 'update' && $option_page === self::PAGE ) {
×
286
                                \add_action( 'admin_init', [ $this, 'register_setting' ] );
×
287
                                \add_action( 'in_admin_header', [ $this, 'remove_notices' ], \PHP_INT_MAX );
×
288
                        }
289

290
                        return;
×
291
                }
292

293
                // Are we on the settings page?
294
                if ( $this->current_page_helper->get_current_yoast_seo_page() === self::PAGE ) {
×
295
                        \add_action( 'admin_init', [ $this, 'register_setting' ] );
×
296
                        \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
×
297
                        \add_action( 'in_admin_header', [ $this, 'remove_notices' ], \PHP_INT_MAX );
×
298
                }
299
        }
300

301
        /**
302
         * Registers the different options under the setting.
303
         *
304
         * @return void
305
         */
306
        public function register_setting() {
×
307
                foreach ( WPSEO_Options::$options as $name => $instance ) {
×
308
                        if ( \in_array( $name, self::ALLOWED_OPTION_GROUPS, true ) ) {
×
309
                                \register_setting( self::PAGE, $name );
×
310
                        }
311
                }
312
                // Only register WP options when the user is allowed to manage them.
313
                if ( \current_user_can( 'manage_options' ) ) {
×
314
                        foreach ( self::WP_OPTIONS as $name ) {
×
315
                                \register_setting( self::PAGE, $name );
×
316
                        }
317
                }
318
        }
319

320
        /**
321
         * Adds the page.
322
         *
323
         * @param array $pages The pages.
324
         *
325
         * @return array The pages.
326
         */
327
        public function add_page( $pages ) {
×
328
                \array_splice(
×
329
                        $pages,
×
330
                        1,
×
331
                        0,
×
332
                        [
×
333
                                [
×
334
                                        'wpseo_dashboard',
×
335
                                        '',
×
336
                                        \__( 'Settings', 'wordpress-seo' ),
×
337
                                        'wpseo_manage_options',
×
338
                                        self::PAGE,
×
339
                                        [ $this, 'display_page' ],
×
340
                                ],
×
341
                        ]
×
342
                );
×
343

344
                return $pages;
×
345
        }
346

347
        /**
348
         * Adds a dummy page.
349
         *
350
         * Because the options route NEEDS to redirect to something.
351
         *
352
         * @param array $pages The pages.
353
         *
354
         * @return array The pages.
355
         */
356
        public function add_settings_saved_page( $pages ) {
2✔
357
                \add_submenu_page(
2✔
358
                        '',
2✔
359
                        '',
2✔
360
                        '',
2✔
361
                        'wpseo_manage_options',
2✔
362
                        self::PAGE . '_saved',
2✔
363
                        static function () {
2✔
364
                                // Add success indication to HTML response.
365
                                $success = empty( \get_settings_errors() ) ? 'true' : 'false';
×
366
                                echo \esc_html( "{{ yoast-success: $success }}" );
×
367
                        }
2✔
368
                );
2✔
369

370
                return $pages;
2✔
371
        }
372

373
        /**
374
         * Displays the page.
375
         *
376
         * @return void
377
         */
378
        public function display_page() {
×
379
                echo '<div id="yoast-seo-settings"></div>';
×
380
        }
381

382
        /**
383
         * Enqueues the assets.
384
         *
385
         * @return void
386
         */
387
        public function enqueue_assets() {
×
388
                // Remove the emoji script as it is incompatible with both React and any contenteditable fields.
389
                \remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
×
390
                \wp_enqueue_media();
×
391
                $this->asset_manager->enqueue_script( 'new-settings' );
×
392
                $this->asset_manager->enqueue_style( 'new-settings' );
×
393
                if ( \YoastSEO()->classes->get( Promotion_Manager::class )->is( 'black-friday-2024-promotion' ) ) {
×
394
                        $this->asset_manager->enqueue_style( 'black-friday-banner' );
×
395
                }
396
                $this->asset_manager->localize_script( 'new-settings', 'wpseoScriptData', $this->get_script_data() );
×
397
        }
398

399
        /**
400
         * Removes all current WP notices.
401
         *
402
         * @return void
403
         */
404
        public function remove_notices() {
×
405
                \remove_all_actions( 'admin_notices' );
×
406
                \remove_all_actions( 'user_admin_notices' );
×
407
                \remove_all_actions( 'network_admin_notices' );
×
408
                \remove_all_actions( 'all_admin_notices' );
×
409
        }
410

411
        /**
412
         * Creates the script data.
413
         *
414
         * @return array The script data.
415
         */
416
        protected function get_script_data() {
×
417
                $default_setting_values = $this->get_default_setting_values();
×
418
                $settings               = $this->get_settings( $default_setting_values );
×
419
                $post_types             = $this->post_type_helper->get_indexable_post_type_objects();
×
420
                $taxonomies             = $this->taxonomy_helper->get_indexable_taxonomy_objects();
×
421

422
                // Check if attachments are included in indexation.
423
                if ( ! \array_key_exists( 'attachment', $post_types ) ) {
×
424
                        // Always include attachments in the settings, to let the user enable them again.
425
                        $attachment_object = \get_post_type_object( 'attachment' );
×
426
                        if ( ! empty( $attachment_object ) ) {
×
427
                                $post_types['attachment'] = $attachment_object;
×
428
                        }
429
                }
430
                // Check if post formats are included in indexation.
431
                if ( ! \array_key_exists( 'post_format', $taxonomies ) ) {
×
432
                        // Always include post_format in the settings, to let the user enable them again.
433
                        $post_format_object = \get_taxonomy( 'post_format' );
×
434
                        if ( ! empty( $post_format_object ) ) {
×
435
                                $taxonomies['post_format'] = $post_format_object;
×
436
                        }
437
                }
438

439
                $transformed_post_types = $this->transform_post_types( $post_types );
×
440
                $transformed_taxonomies = $this->transform_taxonomies( $taxonomies, \array_keys( $transformed_post_types ) );
×
441

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

445
                return [
×
446
                        'settings'                       => $this->transform_settings( $settings ),
×
447
                        'defaultSettingValues'           => $default_setting_values,
×
448
                        'disabledSettings'               => $this->get_disabled_settings( $settings ),
×
449
                        'endpoint'                       => \admin_url( 'options.php' ),
×
450
                        'nonce'                          => \wp_create_nonce( self::PAGE . '-options' ),
×
451
                        'separators'                     => WPSEO_Option_Titles::get_instance()->get_separator_options_for_display(),
×
452
                        'replacementVariables'           => $this->get_replacement_variables(),
×
453
                        'schema'                         => $this->get_schema( $transformed_post_types ),
×
454
                        'preferences'                    => $this->get_preferences( $settings ),
×
455
                        'linkParams'                     => WPSEO_Shortlinker::get_query_params(),
×
456
                        'postTypes'                      => $transformed_post_types,
×
457
                        'taxonomies'                     => $transformed_taxonomies,
×
458
                        'fallbacks'                      => $this->get_fallbacks(),
×
459
                        'showNewContentTypeNotification' => $show_new_content_type_notification,
×
460
                        'currentPromotions'              => \YoastSEO()->classes->get( Promotion_Manager::class )->get_current_promotions(),
×
NEW
461
                        'llmsTxt'                        => $this->llms_txt_configuration->get_configuration(),
×
UNCOV
462
                ];
×
463
        }
464

465
        /**
466
         * Retrieves the preferences.
467
         *
468
         * @param array $settings The settings.
469
         *
470
         * @return array The preferences.
471
         */
472
        protected function get_preferences( $settings ) {
×
473
                $shop_page_id             = $this->woocommerce_helper->get_shop_page_id();
×
474
                $homepage_is_latest_posts = \get_option( 'show_on_front' ) === 'posts';
×
475
                $page_on_front            = \get_option( 'page_on_front' );
×
476
                $page_for_posts           = \get_option( 'page_for_posts' );
×
477

478
                $addon_manager          = new WPSEO_Addon_Manager();
×
479
                $woocommerce_seo_active = \is_plugin_active( $addon_manager->get_plugin_file( WPSEO_Addon_Manager::WOOCOMMERCE_SLUG ) );
×
480

481
                if ( empty( $page_on_front ) ) {
×
482
                        $page_on_front = $page_for_posts;
×
483
                }
484

485
                $business_settings_url = \get_admin_url( null, 'admin.php?page=wpseo_local' );
×
486
                if ( \defined( 'WPSEO_LOCAL_FILE' ) ) {
×
487
                        $local_options      = \get_option( 'wpseo_local' );
×
488
                        $multiple_locations = $local_options['use_multiple_locations'];
×
489
                        $same_organization  = $local_options['multiple_locations_same_organization'];
×
490
                        if ( $multiple_locations === 'on' && $same_organization !== 'on' ) {
×
491
                                $business_settings_url = \get_admin_url( null, 'edit.php?post_type=wpseo_locations' );
×
492
                        }
493
                }
494

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

535
        /**
536
         * Retrieves the currently represented person.
537
         *
538
         * @param array $settings The settings.
539
         *
540
         * @return array The currently represented person's ID and name.
541
         */
542
        protected function get_site_represents_person( $settings ) {
×
543
                $person = [
×
544
                        'id'   => false,
×
545
                        'name' => '',
×
546
                ];
×
547

548
                if ( isset( $settings['wpseo_titles']['company_or_person_user_id'] ) ) {
×
549
                        $person['id'] = $settings['wpseo_titles']['company_or_person_user_id'];
×
550
                        $user         = \get_userdata( $person['id'] );
×
551
                        if ( $user instanceof WP_User ) {
×
552
                                $person['name'] = $user->get( 'display_name' );
×
553
                        }
554
                }
555

556
                return $person;
×
557
        }
558

559
        /**
560
         * Get site policy data.
561
         *
562
         * @param array $settings The settings.
563
         *
564
         * @return array The policy data.
565
         */
566
        private function get_site_basics_policies( $settings ) {
×
567
                $policies = [];
×
568

569
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['publishing_principles_id'], 'publishing_principles_id' );
×
570
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['ownership_funding_info_id'], 'ownership_funding_info_id' );
×
571
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['actionable_feedback_policy_id'], 'actionable_feedback_policy_id' );
×
572
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['corrections_policy_id'], 'corrections_policy_id' );
×
573
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['ethics_policy_id'], 'ethics_policy_id' );
×
574
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['diversity_policy_id'], 'diversity_policy_id' );
×
575
                $policies = $this->maybe_add_policy( $policies, $settings['wpseo_titles']['diversity_staffing_report_id'], 'diversity_staffing_report_id' );
×
576

577
                return $policies;
×
578
        }
579

580
        /**
581
         * Adds policy data if it is present.
582
         *
583
         * @param array  $policies The existing policy data.
584
         * @param int    $policy   The policy id to check.
585
         * @param string $key      The option key name.
586
         *
587
         * @return array<int, string> The policy data.
588
         */
589
        private function maybe_add_policy( $policies, $policy, $key ) {
×
590
                $policy_array = [
×
591
                        'id'   => 0,
×
592
                        'name' => \__( 'None', 'wordpress-seo' ),
×
593
                ];
×
594

595
                if ( isset( $policy ) && \is_int( $policy ) ) {
×
596
                        $policy_array['id'] = $policy;
×
597
                        $post               = \get_post( $policy );
×
598
                        if ( $post instanceof WP_Post ) {
×
599
                                if ( $post->post_status !== 'publish' || $post->post_password !== '' ) {
×
600
                                        return $policies;
×
601
                                }
602
                                $policy_array['name'] = $post->post_title;
×
603
                        }
604
                }
605

606
                $policies[ $key ] = $policy_array;
×
607

608
                return $policies;
×
609
        }
610

611
        /**
612
         * Returns settings for the Call to Buy (CTB) buttons.
613
         *
614
         * @return array<string> The array of CTB settings.
615
         */
616
        public function get_upsell_settings() {
×
617
                return [
×
618
                        'actionId'     => 'load-nfd-ctb',
×
619
                        'premiumCtbId' => 'f6a84663-465f-4cb5-8ba5-f7a6d72224b2',
×
620
                ];
×
621
        }
622

623
        /**
624
         * Retrieves the default setting values.
625
         *
626
         * These default values are currently being used in the UI for dummy fields.
627
         * Dummy fields should not expose or reflect the actual data.
628
         *
629
         * @return array The default setting values.
630
         */
631
        protected function get_default_setting_values() {
×
632
                $defaults = [];
×
633

634
                // Add Yoast settings.
635
                foreach ( WPSEO_Options::$options as $option_name => $instance ) {
×
636
                        if ( \in_array( $option_name, self::ALLOWED_OPTION_GROUPS, true ) ) {
×
637
                                $option_instance          = WPSEO_Options::get_option_instance( $option_name );
×
638
                                $defaults[ $option_name ] = ( $option_instance ) ? $option_instance->get_defaults() : [];
×
639
                        }
640
                }
641
                // Add WP settings.
642
                foreach ( self::WP_OPTIONS as $option_name ) {
×
643
                        $defaults[ $option_name ] = '';
×
644
                }
645

646
                // Remove disallowed settings.
647
                foreach ( self::DISALLOWED_SETTINGS as $option_name => $disallowed_settings ) {
×
648
                        foreach ( $disallowed_settings as $disallowed_setting ) {
×
649
                                unset( $defaults[ $option_name ][ $disallowed_setting ] );
×
650
                        }
651
                }
652

653
                if ( \defined( 'WPSEO_LOCAL_FILE' ) ) {
×
654
                        $defaults = $this->get_defaults_from_local_seo( $defaults );
×
655
                }
656

657
                return $defaults;
×
658
        }
659

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

680
                if ( \wpseo_has_primary_location() ) {
8✔
681
                        $primary_location = $local_options['multiple_locations_primary_location'];
4✔
682

683
                        $location_keys = [
4✔
684
                                'org-phone'  => [
4✔
685
                                        'is_overridden' => '_wpseo_is_overridden_business_phone',
4✔
686
                                        'value'         => '_wpseo_business_phone',
4✔
687
                                ],
4✔
688
                                'org-email'  => [
4✔
689
                                        'is_overridden' => '_wpseo_is_overridden_business_email',
4✔
690
                                        'value'         => '_wpseo_business_email',
4✔
691
                                ],
4✔
692
                                'org-tax-id' => [
4✔
693
                                        'is_overridden' => '_wpseo_is_overridden_business_tax_id',
4✔
694
                                        'value'         => '_wpseo_business_tax_id',
4✔
695
                                ],
4✔
696
                                'org-vat-id' => [
4✔
697
                                        'is_overridden' => '_wpseo_is_overridden_business_vat_id',
4✔
698
                                        'value'         => '_wpseo_business_vat_id',
4✔
699
                                ],
4✔
700
                        ];
4✔
701

702
                        foreach ( $location_keys as $key => $meta_keys ) {
4✔
703
                                $is_overridden = ( $shared_info === 'on' ) ? \get_post_meta( $primary_location, $meta_keys['is_overridden'], true ) : false;
4✔
704
                                if ( $is_overridden === 'on' || $shared_info !== 'on' ) {
4✔
705
                                        $post_meta_value                  = \get_post_meta( $primary_location, $meta_keys['value'], true );
4✔
706
                                        $defaults['wpseo_titles'][ $key ] = ( $post_meta_value ) ? $post_meta_value : '';
4✔
707
                                }
708
                        }
709
                }
710

711
                return $defaults;
8✔
712
        }
713

714
        /**
715
         * Retrieves the settings and their values.
716
         *
717
         * @param array $default_setting_values The default setting values.
718
         *
719
         * @return array The settings.
720
         */
721
        protected function get_settings( $default_setting_values ) {
×
722
                $settings = [];
×
723

724
                // Add Yoast settings.
725
                foreach ( WPSEO_Options::$options as $option_name => $instance ) {
×
726
                        if ( \in_array( $option_name, self::ALLOWED_OPTION_GROUPS, true ) ) {
×
727
                                $settings[ $option_name ] = \array_merge( $default_setting_values[ $option_name ], WPSEO_Options::get_option( $option_name ) );
×
728
                        }
729
                }
730
                // Add WP settings.
731
                foreach ( self::WP_OPTIONS as $option_name ) {
×
732
                        $settings[ $option_name ] = \get_option( $option_name );
×
733
                }
734

735
                // Remove disallowed settings.
736
                foreach ( self::DISALLOWED_SETTINGS as $option_name => $disallowed_settings ) {
×
737
                        foreach ( $disallowed_settings as $disallowed_setting ) {
×
738
                                unset( $settings[ $option_name ][ $disallowed_setting ] );
×
739
                        }
740
                }
741

742
                return $settings;
×
743
        }
744

745
        /**
746
         * Transforms setting values.
747
         *
748
         * @param array $settings The settings.
749
         *
750
         * @return array The settings.
751
         */
752
        protected function transform_settings( $settings ) {
×
753
                if ( isset( $settings['wpseo_titles']['breadcrumbs-sep'] ) ) {
×
754
                        /**
755
                         * The breadcrumbs separator default value is the HTML entity `&raquo;`.
756
                         * Which does not get decoded in our JS, while it did in our Yoast form. Decode it here as an exception.
757
                         */
758
                        $settings['wpseo_titles']['breadcrumbs-sep'] = \html_entity_decode(
×
759
                                $settings['wpseo_titles']['breadcrumbs-sep'],
×
760
                                ( \ENT_NOQUOTES | \ENT_HTML5 ),
×
761
                                'UTF-8'
×
762
                        );
×
763
                }
764

765
                /**
766
                 * Decode some WP options.
767
                 */
768
                $settings['blogdescription'] = \html_entity_decode(
×
769
                        $settings['blogdescription'],
×
770
                        ( \ENT_NOQUOTES | \ENT_HTML5 ),
×
771
                        'UTF-8'
×
772
                );
×
773

774
                return $settings;
×
775
        }
776

777
        /**
778
         * Retrieves the disabled settings.
779
         *
780
         * @param array $settings The settings.
781
         *
782
         * @return array The settings.
783
         */
784
        protected function get_disabled_settings( $settings ) {
×
785
                $disabled_settings = [];
×
786
                $site_language     = $this->language_helper->get_language();
×
787

788
                foreach ( WPSEO_Options::$options as $option_name => $instance ) {
×
789
                        if ( ! \in_array( $option_name, self::ALLOWED_OPTION_GROUPS, true ) ) {
×
790
                                continue;
×
791
                        }
792

793
                        $disabled_settings[ $option_name ] = [];
×
794
                        $option_instance                   = WPSEO_Options::get_option_instance( $option_name );
×
795
                        if ( $option_instance === false ) {
×
796
                                continue;
×
797
                        }
798
                        foreach ( $settings[ $option_name ] as $setting_name => $setting_value ) {
×
799
                                if ( $option_instance->is_disabled( $setting_name ) ) {
×
800
                                        $disabled_settings[ $option_name ][ $setting_name ] = 'network';
×
801
                                }
802
                        }
803
                }
804

805
                // Remove disabled on multisite settings.
806
                if ( \is_multisite() ) {
×
807
                        foreach ( self::DISABLED_ON_MULTISITE_SETTINGS as $option_name => $disabled_ms_settings ) {
×
808
                                if ( \array_key_exists( $option_name, $disabled_settings ) ) {
×
809
                                        foreach ( $disabled_ms_settings as $disabled_ms_setting ) {
×
810
                                                $disabled_settings[ $option_name ][ $disabled_ms_setting ] = 'multisite';
×
811
                                        }
812
                                }
813
                        }
814
                }
815

816
                if ( \array_key_exists( 'wpseo', $disabled_settings ) && ! $this->language_helper->has_inclusive_language_support( $site_language ) ) {
×
817
                        $disabled_settings['wpseo']['inclusive_language_analysis_active'] = 'language';
×
818
                }
819

820
                return $disabled_settings;
×
821
        }
822

823
        /**
824
         * Retrieves the replacement variables.
825
         *
826
         * @return array The replacement variables.
827
         */
828
        protected function get_replacement_variables() {
×
829
                $recommended_replace_vars = new WPSEO_Admin_Recommended_Replace_Vars();
×
830
                $specific_replace_vars    = new WPSEO_Admin_Editor_Specific_Replace_Vars();
×
831
                $replacement_variables    = $this->replace_vars->get_replacement_variables_with_labels();
×
832

833
                return [
×
834
                        'variables'   => $replacement_variables,
×
835
                        'recommended' => $recommended_replace_vars->get_recommended_replacevars(),
×
836
                        'specific'    => $specific_replace_vars->get(),
×
837
                        'shared'      => $specific_replace_vars->get_generic( $replacement_variables ),
×
838
                ];
×
839
        }
840

841
        /**
842
         * Retrieves the schema.
843
         *
844
         * @param array $post_types The post types.
845
         *
846
         * @return array The schema.
847
         */
848
        protected function get_schema( array $post_types ) {
×
849
                $schema = [];
×
850

851
                foreach ( $this->schema_types->get_article_type_options() as $article_type ) {
×
852
                        $schema['articleTypes'][ $article_type['value'] ] = [
×
853
                                'label' => $article_type['name'],
×
854
                                'value' => $article_type['value'],
×
855
                        ];
×
856
                }
857

858
                foreach ( $this->schema_types->get_page_type_options() as $page_type ) {
×
859
                        $schema['pageTypes'][ $page_type['value'] ] = [
×
860
                                'label' => $page_type['name'],
×
861
                                'value' => $page_type['value'],
×
862
                        ];
×
863
                }
864

865
                $schema['articleTypeDefaults'] = [];
×
866
                $schema['pageTypeDefaults']    = [];
×
867
                foreach ( $post_types as $name => $post_type ) {
×
868
                        $schema['articleTypeDefaults'][ $name ] = WPSEO_Options::get_default( 'wpseo_titles', "schema-article-type-$name" );
×
869
                        $schema['pageTypeDefaults'][ $name ]    = WPSEO_Options::get_default( 'wpseo_titles', "schema-page-type-$name" );
×
870
                }
871

872
                return $schema;
×
873
        }
874

875
        /**
876
         * Transforms the post types, to represent them.
877
         *
878
         * @param WP_Post_Type[] $post_types The WP_Post_Type array to transform.
879
         *
880
         * @return array The post types.
881
         */
882
        protected function transform_post_types( $post_types ) {
4✔
883
                $transformed    = [];
4✔
884
                $new_post_types = $this->options->get( 'new_post_types', [] );
4✔
885
                foreach ( $post_types as $post_type ) {
4✔
886
                        $transformed[ $post_type->name ] = [
4✔
887
                                'name'                 => $post_type->name,
4✔
888
                                'route'                => $this->get_route( $post_type->name, $post_type->rewrite, $post_type->rest_base ),
4✔
889
                                'label'                => $post_type->label,
4✔
890
                                'singularLabel'        => $post_type->labels->singular_name,
4✔
891
                                'hasArchive'           => $this->post_type_helper->has_archive( $post_type ),
4✔
892
                                'hasSchemaArticleType' => $this->article_helper->is_article_post_type( $post_type->name ),
4✔
893
                                'menuPosition'         => $post_type->menu_position,
4✔
894
                                'isNew'                => \in_array( $post_type->name, $new_post_types, true ),
4✔
895
                        ];
4✔
896
                }
897

898
                \uasort( $transformed, [ $this, 'compare_post_types' ] );
4✔
899

900
                return $transformed;
4✔
901
        }
902

903
        /**
904
         * Compares two post types.
905
         *
906
         * @param array $a The first post type.
907
         * @param array $b The second post type.
908
         *
909
         * @return int The order.
910
         */
911
        protected function compare_post_types( $a, $b ) {
×
912
                if ( $a['menuPosition'] === null && $b['menuPosition'] !== null ) {
×
913
                        return 1;
×
914
                }
915
                if ( $a['menuPosition'] !== null && $b['menuPosition'] === null ) {
×
916
                        return -1;
×
917
                }
918

919
                if ( $a['menuPosition'] === null && $b['menuPosition'] === null ) {
×
920
                        // No position specified, order alphabetically by label.
921
                        return \strnatcmp( $a['label'], $b['label'] );
×
922
                }
923

924
                return ( ( $a['menuPosition'] < $b['menuPosition'] ) ? -1 : 1 );
×
925
        }
926

927
        /**
928
         * Transforms the taxonomies, to represent them.
929
         *
930
         * @param WP_Taxonomy[] $taxonomies      The WP_Taxonomy array to transform.
931
         * @param string[]      $post_type_names The post type names.
932
         *
933
         * @return array The taxonomies.
934
         */
935
        protected function transform_taxonomies( $taxonomies, $post_type_names ) {
4✔
936
                $transformed    = [];
4✔
937
                $new_taxonomies = $this->options->get( 'new_taxonomies', [] );
4✔
938
                foreach ( $taxonomies as $taxonomy ) {
4✔
939
                        $transformed[ $taxonomy->name ] = [
4✔
940
                                'name'          => $taxonomy->name,
4✔
941
                                'route'         => $this->get_route( $taxonomy->name, $taxonomy->rewrite, $taxonomy->rest_base ),
4✔
942
                                'label'         => $taxonomy->label,
4✔
943
                                'showUi'        => $taxonomy->show_ui,
4✔
944
                                'singularLabel' => $taxonomy->labels->singular_name,
4✔
945
                                'postTypes'     => \array_filter(
4✔
946
                                        $taxonomy->object_type,
4✔
947
                                        static function ( $object_type ) use ( $post_type_names ) {
4✔
948
                                                return \in_array( $object_type, $post_type_names, true );
4✔
949
                                        }
4✔
950
                                ),
4✔
951
                                'isNew'         => \in_array( $taxonomy->name, $new_taxonomies, true ),
4✔
952
                        ];
4✔
953
                }
954

955
                \uasort(
4✔
956
                        $transformed,
4✔
957
                        static function ( $a, $b ) {
4✔
958
                                return \strnatcmp( $a['label'], $b['label'] );
959
                        }
4✔
960
                );
4✔
961

962
                return $transformed;
963
        }
964

965
        /**
966
         * Gets the route from a name, rewrite and rest_base.
967
         *
968
         * @param string $name      The name.
969
         * @param array  $rewrite   The rewrite data.
970
         * @param string $rest_base The rest base.
971
         *
972
         * @return string The route.
973
         */
974
        protected function get_route( $name, $rewrite, $rest_base ) {
×
975
                $route = $name;
×
976
                if ( isset( $rewrite['slug'] ) ) {
977
                        $route = $rewrite['slug'];
×
978
                }
979
                if ( ! empty( $rest_base ) ) {
980
                        $route = $rest_base;
981
                }
982
                // Always strip leading slashes.
983
                while ( \substr( $route, 0, 1 ) === '/' ) {
984
                        $route = \substr( $route, 1 );
985
                }
986

987
                return $route;
988
        }
989

990
        /**
991
         * Retrieves the fallbacks.
992
         *
993
         * @return array The fallbacks.
994
         */
995
        protected function get_fallbacks() {
×
996
                $site_logo_id = \get_option( 'site_logo' );
×
997
                if ( ! $site_logo_id ) {
998
                        $site_logo_id = \get_theme_mod( 'custom_logo' );
×
999
                }
1000
                if ( ! $site_logo_id ) {
1001
                        $site_logo_id = '0';
1002
                }
1003

1004
                return [
×
1005
                        'siteLogoId' => $site_logo_id,
×
1006
                ];
×
1007
        }
1008
}
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