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

Yoast / wordpress-seo / cd4a08dd843eeb032687bda01290dd1f11c3dc46

03 Jul 2025 10:38AM UTC coverage: 53.729% (-0.1%) from 53.845%
cd4a08dd843eeb032687bda01290dd1f11c3dc46

push

github

web-flow
Merge pull request #22388 from Yoast/641-create-the-dropdowns-for-the-manual-page-selection

641 create the dropdowns for the manual page selection

8246 of 14380 branches covered (57.34%)

Branch coverage included in aggregate %.

0 of 140 new or added lines in 5 files covered. (0.0%)

8 existing lines in 3 files now uncovered.

30488 of 57711 relevant lines covered (52.83%)

41372.73 hits per line

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

24.94
/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', 'wpseo_llmstxt' ];
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(),
×
461
                        'llmsTxt'                        => $this->llms_txt_configuration->get_configuration(),
×
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 ),
×
NEW
532
                        'llmTxtPages'                   => $this->get_site_llms_txt_pages( $settings ),
×
UNCOV
533
                ];
×
534
        }
535

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

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

557
                return $person;
×
558
        }
559

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

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

578
                return $policies;
×
579
        }
580

581
        /**
582
         * Adds page if it is present.
583
         *
584
         * @param array  $pages The existing pages.
585
         * @param int    $page  The page id to check.
586
         * @param string $key   The option key name.
587
         *
588
         * @return array<int, string> The policy data.
589
         */
NEW
590
        private function maybe_add_page( $pages, $page, $key ) {
×
NEW
591
                if ( isset( $page ) && \is_int( $page ) && $page !== 0 ) {
×
NEW
592
                        $page_array = [
×
NEW
593
                                'id'   => $page,
×
NEW
594
                                'name' => \__( 'None', 'wordpress-seo' ),
×
NEW
595
                        ];
×
NEW
596
                        $post       = \get_post( $page );
×
597
                        if ( $post instanceof WP_Post ) {
×
598
                                if ( $post->post_status !== 'publish' || $post->post_password !== '' ) {
×
NEW
599
                                        return $pages;
×
600
                                }
NEW
601
                                $page_array['name'] = $post->post_title;
×
602
                        }
603

NEW
604
                        $pages[ $key ] = $page_array;
×
605
                }
606

NEW
607
                return $pages;
×
608
        }
609

610
        /**
611
         * Get site llms.txt pages.
612
         *
613
         * @param array $settings The settings.
614
         *
615
         * @return array<string, array<string, int|string>> The llms.txt pages.
616
         */
NEW
617
        private function get_site_llms_txt_pages( $settings ) {
×
NEW
618
                $llms_txt_pages = [];
×
619

NEW
620
                $llms_txt_pages = $this->maybe_add_page( $llms_txt_pages, $settings['wpseo_llmstxt']['about_us_page'], 'about_us_page' );
×
NEW
621
                $llms_txt_pages = $this->maybe_add_page( $llms_txt_pages, $settings['wpseo_llmstxt']['contact_page'], 'contact_page' );
×
NEW
622
                $llms_txt_pages = $this->maybe_add_page( $llms_txt_pages, $settings['wpseo_llmstxt']['terms_page'], 'terms_page' );
×
NEW
623
                $llms_txt_pages = $this->maybe_add_page( $llms_txt_pages, $settings['wpseo_llmstxt']['privacy_policy_page'], 'privacy_policy_page' );
×
NEW
624
                $llms_txt_pages = $this->maybe_add_page( $llms_txt_pages, $settings['wpseo_llmstxt']['shop_page'], 'shop_page' );
×
625

NEW
626
                if ( isset( $settings['wpseo_llmstxt']['other_included_pages'] ) && \is_array( $settings['wpseo_llmstxt']['other_included_pages'] ) ) {
×
NEW
627
                        foreach ( $settings['wpseo_llmstxt']['other_included_pages'] as $key => $id ) {
×
628
                                // @TODO: This needs to be using the indexables table. The next PR should fix this, that's why we are duplicating some code here.
NEW
629
                                $page = [];
×
630

NEW
631
                                $page['id'] = $id;
×
NEW
632
                                $post       = \get_post( $id );
×
NEW
633
                                if ( ! ( $post instanceof WP_Post ) || ( $post->post_status !== 'publish' || $post->post_password !== '' ) ) {
×
NEW
634
                                        continue;
×
635
                                }
636

NEW
637
                                $page['name'] = $post->post_title;
×
638

NEW
639
                                $llms_txt_pages[ 'other_included_pages-' . $key ] = $page;
×
640
                        }
641
                }
642

NEW
643
                return $llms_txt_pages;
×
644
        }
645

646
        /**
647
         * Returns settings for the Call to Buy (CTB) buttons.
648
         *
649
         * @return array<string> The array of CTB settings.
650
         */
651
        public function get_upsell_settings() {
×
652
                return [
×
653
                        'actionId'     => 'load-nfd-ctb',
×
654
                        'premiumCtbId' => 'f6a84663-465f-4cb5-8ba5-f7a6d72224b2',
×
655
                ];
×
656
        }
657

658
        /**
659
         * Retrieves the default setting values.
660
         *
661
         * These default values are currently being used in the UI for dummy fields.
662
         * Dummy fields should not expose or reflect the actual data.
663
         *
664
         * @return array The default setting values.
665
         */
666
        protected function get_default_setting_values() {
×
667
                $defaults = [];
×
668

669
                // Add Yoast settings.
670
                foreach ( WPSEO_Options::$options as $option_name => $instance ) {
×
671
                        if ( \in_array( $option_name, self::ALLOWED_OPTION_GROUPS, true ) ) {
×
672
                                $option_instance          = WPSEO_Options::get_option_instance( $option_name );
×
673
                                $defaults[ $option_name ] = ( $option_instance ) ? $option_instance->get_defaults() : [];
×
674
                        }
675
                }
676
                // Add WP settings.
677
                foreach ( self::WP_OPTIONS as $option_name ) {
×
678
                        $defaults[ $option_name ] = '';
×
679
                }
680

681
                // Remove disallowed settings.
682
                foreach ( self::DISALLOWED_SETTINGS as $option_name => $disallowed_settings ) {
×
683
                        foreach ( $disallowed_settings as $disallowed_setting ) {
×
684
                                unset( $defaults[ $option_name ][ $disallowed_setting ] );
×
685
                        }
686
                }
687

688
                if ( \defined( 'WPSEO_LOCAL_FILE' ) ) {
×
689
                        $defaults = $this->get_defaults_from_local_seo( $defaults );
×
690
                }
691

692
                return $defaults;
×
693
        }
694

695
        /**
696
         * Retrieves the organization schema values from Local SEO for defaults in Site representation fields.
697
         * Specifically for the org-vat-id, org-tax-id, org-email and org-phone options.
698
         *
699
         * @param array<string|int|bool> $defaults The settings defaults.
700
         *
701
         * @return array<string|int|bool> The settings defaults with local seo overides.
702
         */
703
        protected function get_defaults_from_local_seo( $defaults ) {
8✔
704
                $local_options      = \get_option( 'wpseo_local' );
8✔
705
                $multiple_locations = $local_options['use_multiple_locations'];
8✔
706
                $same_organization  = $local_options['multiple_locations_same_organization'];
8✔
707
                $shared_info        = $local_options['multiple_locations_shared_business_info'];
8✔
708
                if ( $multiple_locations !== 'on' || ( $multiple_locations === 'on' && $same_organization === 'on' && $shared_info === 'on' ) ) {
8✔
709
                        $defaults['wpseo_titles']['org-vat-id'] = $local_options['location_vat_id'];
6✔
710
                        $defaults['wpseo_titles']['org-tax-id'] = $local_options['location_tax_id'];
6✔
711
                        $defaults['wpseo_titles']['org-email']  = $local_options['location_email'];
6✔
712
                        $defaults['wpseo_titles']['org-phone']  = $local_options['location_phone'];
6✔
713
                }
714

715
                if ( \wpseo_has_primary_location() ) {
8✔
716
                        $primary_location = $local_options['multiple_locations_primary_location'];
4✔
717

718
                        $location_keys = [
4✔
719
                                'org-phone'  => [
4✔
720
                                        'is_overridden' => '_wpseo_is_overridden_business_phone',
4✔
721
                                        'value'         => '_wpseo_business_phone',
4✔
722
                                ],
4✔
723
                                'org-email'  => [
4✔
724
                                        'is_overridden' => '_wpseo_is_overridden_business_email',
4✔
725
                                        'value'         => '_wpseo_business_email',
4✔
726
                                ],
4✔
727
                                'org-tax-id' => [
4✔
728
                                        'is_overridden' => '_wpseo_is_overridden_business_tax_id',
4✔
729
                                        'value'         => '_wpseo_business_tax_id',
4✔
730
                                ],
4✔
731
                                'org-vat-id' => [
4✔
732
                                        'is_overridden' => '_wpseo_is_overridden_business_vat_id',
4✔
733
                                        'value'         => '_wpseo_business_vat_id',
4✔
734
                                ],
4✔
735
                        ];
4✔
736

737
                        foreach ( $location_keys as $key => $meta_keys ) {
4✔
738
                                $is_overridden = ( $shared_info === 'on' ) ? \get_post_meta( $primary_location, $meta_keys['is_overridden'], true ) : false;
4✔
739
                                if ( $is_overridden === 'on' || $shared_info !== 'on' ) {
4✔
740
                                        $post_meta_value                  = \get_post_meta( $primary_location, $meta_keys['value'], true );
4✔
741
                                        $defaults['wpseo_titles'][ $key ] = ( $post_meta_value ) ? $post_meta_value : '';
4✔
742
                                }
743
                        }
744
                }
745

746
                return $defaults;
8✔
747
        }
748

749
        /**
750
         * Retrieves the settings and their values.
751
         *
752
         * @param array $default_setting_values The default setting values.
753
         *
754
         * @return array The settings.
755
         */
756
        protected function get_settings( $default_setting_values ) {
×
757
                $settings = [];
×
758

759
                // Add Yoast settings.
760
                foreach ( WPSEO_Options::$options as $option_name => $instance ) {
×
761
                        if ( \in_array( $option_name, self::ALLOWED_OPTION_GROUPS, true ) ) {
×
762
                                $settings[ $option_name ] = \array_merge( $default_setting_values[ $option_name ], WPSEO_Options::get_option( $option_name ) );
×
763
                        }
764
                }
765
                // Add WP settings.
766
                foreach ( self::WP_OPTIONS as $option_name ) {
×
767
                        $settings[ $option_name ] = \get_option( $option_name );
×
768
                }
769

770
                // Remove disallowed settings.
771
                foreach ( self::DISALLOWED_SETTINGS as $option_name => $disallowed_settings ) {
×
772
                        foreach ( $disallowed_settings as $disallowed_setting ) {
×
773
                                unset( $settings[ $option_name ][ $disallowed_setting ] );
×
774
                        }
775
                }
776

777
                return $settings;
×
778
        }
779

780
        /**
781
         * Transforms setting values.
782
         *
783
         * @param array $settings The settings.
784
         *
785
         * @return array The settings.
786
         */
787
        protected function transform_settings( $settings ) {
×
788
                if ( isset( $settings['wpseo_titles']['breadcrumbs-sep'] ) ) {
×
789
                        /**
790
                         * The breadcrumbs separator default value is the HTML entity `&raquo;`.
791
                         * Which does not get decoded in our JS, while it did in our Yoast form. Decode it here as an exception.
792
                         */
793
                        $settings['wpseo_titles']['breadcrumbs-sep'] = \html_entity_decode(
×
794
                                $settings['wpseo_titles']['breadcrumbs-sep'],
×
795
                                ( \ENT_NOQUOTES | \ENT_HTML5 ),
×
796
                                'UTF-8'
×
797
                        );
×
798
                }
799

800
                /**
801
                 * Decode some WP options.
802
                 */
803
                $settings['blogdescription'] = \html_entity_decode(
×
804
                        $settings['blogdescription'],
×
805
                        ( \ENT_NOQUOTES | \ENT_HTML5 ),
×
806
                        'UTF-8'
×
807
                );
×
808

NEW
809
                if ( isset( $settings['wpseo_llmstxt']['other_included_pages'] ) ) {
×
810
                        // Append an empty page to the other included pages, so that we manage to show an empty field in the UI.
NEW
811
                        $settings['wpseo_llmstxt']['other_included_pages'][] = 0;
×
812
                }
813

UNCOV
814
                return $settings;
×
815
        }
816

817
        /**
818
         * Retrieves the disabled settings.
819
         *
820
         * @param array $settings The settings.
821
         *
822
         * @return array The settings.
823
         */
824
        protected function get_disabled_settings( $settings ) {
×
825
                $disabled_settings = [];
×
826
                $site_language     = $this->language_helper->get_language();
×
827

828
                foreach ( WPSEO_Options::$options as $option_name => $instance ) {
×
829
                        if ( ! \in_array( $option_name, self::ALLOWED_OPTION_GROUPS, true ) ) {
×
830
                                continue;
×
831
                        }
832

833
                        $disabled_settings[ $option_name ] = [];
×
834
                        $option_instance                   = WPSEO_Options::get_option_instance( $option_name );
×
835
                        if ( $option_instance === false ) {
×
836
                                continue;
×
837
                        }
838
                        foreach ( $settings[ $option_name ] as $setting_name => $setting_value ) {
×
839
                                if ( $option_instance->is_disabled( $setting_name ) ) {
×
840
                                        $disabled_settings[ $option_name ][ $setting_name ] = 'network';
×
841
                                }
842
                        }
843
                }
844

845
                // Remove disabled on multisite settings.
846
                if ( \is_multisite() ) {
×
847
                        foreach ( self::DISABLED_ON_MULTISITE_SETTINGS as $option_name => $disabled_ms_settings ) {
×
848
                                if ( \array_key_exists( $option_name, $disabled_settings ) ) {
×
849
                                        foreach ( $disabled_ms_settings as $disabled_ms_setting ) {
×
850
                                                $disabled_settings[ $option_name ][ $disabled_ms_setting ] = 'multisite';
×
851
                                        }
852
                                }
853
                        }
854
                }
855

856
                if ( \array_key_exists( 'wpseo', $disabled_settings ) && ! $this->language_helper->has_inclusive_language_support( $site_language ) ) {
×
857
                        $disabled_settings['wpseo']['inclusive_language_analysis_active'] = 'language';
×
858
                }
859

860
                return $disabled_settings;
×
861
        }
862

863
        /**
864
         * Retrieves the replacement variables.
865
         *
866
         * @return array The replacement variables.
867
         */
868
        protected function get_replacement_variables() {
×
869
                $recommended_replace_vars = new WPSEO_Admin_Recommended_Replace_Vars();
×
870
                $specific_replace_vars    = new WPSEO_Admin_Editor_Specific_Replace_Vars();
×
871
                $replacement_variables    = $this->replace_vars->get_replacement_variables_with_labels();
×
872

873
                return [
×
874
                        'variables'   => $replacement_variables,
×
875
                        'recommended' => $recommended_replace_vars->get_recommended_replacevars(),
×
876
                        'specific'    => $specific_replace_vars->get(),
×
877
                        'shared'      => $specific_replace_vars->get_generic( $replacement_variables ),
×
878
                ];
×
879
        }
880

881
        /**
882
         * Retrieves the schema.
883
         *
884
         * @param array $post_types The post types.
885
         *
886
         * @return array The schema.
887
         */
888
        protected function get_schema( array $post_types ) {
×
889
                $schema = [];
×
890

891
                foreach ( $this->schema_types->get_article_type_options() as $article_type ) {
×
892
                        $schema['articleTypes'][ $article_type['value'] ] = [
×
893
                                'label' => $article_type['name'],
×
894
                                'value' => $article_type['value'],
×
895
                        ];
×
896
                }
897

898
                foreach ( $this->schema_types->get_page_type_options() as $page_type ) {
×
899
                        $schema['pageTypes'][ $page_type['value'] ] = [
×
900
                                'label' => $page_type['name'],
×
901
                                'value' => $page_type['value'],
×
902
                        ];
×
903
                }
904

905
                $schema['articleTypeDefaults'] = [];
×
906
                $schema['pageTypeDefaults']    = [];
×
907
                foreach ( $post_types as $name => $post_type ) {
×
908
                        $schema['articleTypeDefaults'][ $name ] = WPSEO_Options::get_default( 'wpseo_titles', "schema-article-type-$name" );
×
909
                        $schema['pageTypeDefaults'][ $name ]    = WPSEO_Options::get_default( 'wpseo_titles', "schema-page-type-$name" );
×
910
                }
911

912
                return $schema;
×
913
        }
914

915
        /**
916
         * Transforms the post types, to represent them.
917
         *
918
         * @param WP_Post_Type[] $post_types The WP_Post_Type array to transform.
919
         *
920
         * @return array The post types.
921
         */
922
        protected function transform_post_types( $post_types ) {
4✔
923
                $transformed    = [];
4✔
924
                $new_post_types = $this->options->get( 'new_post_types', [] );
4✔
925
                foreach ( $post_types as $post_type ) {
4✔
926
                        $transformed[ $post_type->name ] = [
4✔
927
                                'name'                 => $post_type->name,
4✔
928
                                'route'                => $this->get_route( $post_type->name, $post_type->rewrite, $post_type->rest_base ),
4✔
929
                                'label'                => $post_type->label,
4✔
930
                                'singularLabel'        => $post_type->labels->singular_name,
4✔
931
                                'hasArchive'           => $this->post_type_helper->has_archive( $post_type ),
4✔
932
                                'hasSchemaArticleType' => $this->article_helper->is_article_post_type( $post_type->name ),
4✔
933
                                'menuPosition'         => $post_type->menu_position,
4✔
934
                                'isNew'                => \in_array( $post_type->name, $new_post_types, true ),
4✔
935
                        ];
4✔
936
                }
937

938
                \uasort( $transformed, [ $this, 'compare_post_types' ] );
4✔
939

940
                return $transformed;
4✔
941
        }
942

943
        /**
944
         * Compares two post types.
945
         *
946
         * @param array $a The first post type.
947
         * @param array $b The second post type.
948
         *
949
         * @return int The order.
950
         */
951
        protected function compare_post_types( $a, $b ) {
×
952
                if ( $a['menuPosition'] === null && $b['menuPosition'] !== null ) {
×
953
                        return 1;
×
954
                }
955
                if ( $a['menuPosition'] !== null && $b['menuPosition'] === null ) {
×
956
                        return -1;
×
957
                }
958

959
                if ( $a['menuPosition'] === null && $b['menuPosition'] === null ) {
×
960
                        // No position specified, order alphabetically by label.
961
                        return \strnatcmp( $a['label'], $b['label'] );
×
962
                }
963

964
                return ( ( $a['menuPosition'] < $b['menuPosition'] ) ? -1 : 1 );
×
965
        }
966

967
        /**
968
         * Transforms the taxonomies, to represent them.
969
         *
970
         * @param WP_Taxonomy[] $taxonomies      The WP_Taxonomy array to transform.
971
         * @param string[]      $post_type_names The post type names.
972
         *
973
         * @return array The taxonomies.
974
         */
975
        protected function transform_taxonomies( $taxonomies, $post_type_names ) {
4✔
976
                $transformed    = [];
4✔
977
                $new_taxonomies = $this->options->get( 'new_taxonomies', [] );
4✔
978
                foreach ( $taxonomies as $taxonomy ) {
4✔
979
                        $transformed[ $taxonomy->name ] = [
4✔
980
                                'name'          => $taxonomy->name,
4✔
981
                                'route'         => $this->get_route( $taxonomy->name, $taxonomy->rewrite, $taxonomy->rest_base ),
4✔
982
                                'label'         => $taxonomy->label,
4✔
983
                                'showUi'        => $taxonomy->show_ui,
4✔
984
                                'singularLabel' => $taxonomy->labels->singular_name,
4✔
985
                                'postTypes'     => \array_filter(
4✔
986
                                        $taxonomy->object_type,
4✔
987
                                        static function ( $object_type ) use ( $post_type_names ) {
4✔
988
                                                return \in_array( $object_type, $post_type_names, true );
4✔
989
                                        }
4✔
990
                                ),
4✔
991
                                'isNew'         => \in_array( $taxonomy->name, $new_taxonomies, true ),
4✔
992
                        ];
4✔
993
                }
994

995
                \uasort(
4✔
996
                        $transformed,
4✔
997
                        static function ( $a, $b ) {
4✔
998
                                return \strnatcmp( $a['label'], $b['label'] );
999
                        }
4✔
1000
                );
4✔
1001

1002
                return $transformed;
1003
        }
1004

1005
        /**
1006
         * Gets the route from a name, rewrite and rest_base.
1007
         *
1008
         * @param string $name      The name.
1009
         * @param array  $rewrite   The rewrite data.
1010
         * @param string $rest_base The rest base.
1011
         *
1012
         * @return string The route.
1013
         */
1014
        protected function get_route( $name, $rewrite, $rest_base ) {
×
1015
                $route = $name;
×
1016
                if ( isset( $rewrite['slug'] ) ) {
1017
                        $route = $rewrite['slug'];
×
1018
                }
1019
                if ( ! empty( $rest_base ) ) {
1020
                        $route = $rest_base;
1021
                }
1022
                // Always strip leading slashes.
1023
                while ( \substr( $route, 0, 1 ) === '/' ) {
1024
                        $route = \substr( $route, 1 );
1025
                }
1026

1027
                return $route;
1028
        }
1029

1030
        /**
1031
         * Retrieves the fallbacks.
1032
         *
1033
         * @return array The fallbacks.
1034
         */
1035
        protected function get_fallbacks() {
×
1036
                $site_logo_id = \get_option( 'site_logo' );
×
1037
                if ( ! $site_logo_id ) {
1038
                        $site_logo_id = \get_theme_mod( 'custom_logo' );
×
1039
                }
1040
                if ( ! $site_logo_id ) {
1041
                        $site_logo_id = '0';
1042
                }
1043

1044
                return [
×
1045
                        'siteLogoId' => $site_logo_id,
×
1046
                ];
×
1047
        }
1048
}
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