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

Yoast / wordpress-seo / 5177496912

pending completion
5177496912

push

github

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

31 of 36 new or added lines in 3 files covered. (86.11%)

513 existing lines in 3 files now uncovered.

9613 of 24021 relevant lines covered (40.02%)

3.33 hits per line

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

0.0
/admin/class-config.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Admin
6
 */
7

8
use Yoast\WP\SEO\Integrations\Academy_Integration;
9
use Yoast\WP\SEO\Integrations\Settings_Integration;
10
use Yoast\WP\SEO\Integrations\Support_Integration;
11

12
/**
13
 * Class WPSEO_Admin_Pages.
14
 *
15
 * Class with functionality for the Yoast SEO admin pages.
16
 */
17
class WPSEO_Admin_Pages {
18

19
        /**
20
         * The option in use for the current admin page.
21
         *
22
         * @var string
23
         */
24
        public $currentoption = 'wpseo';
25

26
        /**
27
         * Holds the asset manager.
28
         *
29
         * @var WPSEO_Admin_Asset_Manager
30
         */
31
        private $asset_manager;
32

33
        /**
34
         * Class constructor, which basically only hooks the init function on the init hook.
35
         */
36
        public function __construct() {
37
                add_action( 'init', [ $this, 'init' ], 20 );
×
38
                $this->asset_manager = new WPSEO_Admin_Asset_Manager();
×
39
        }
40

41
        /**
42
         * Make sure the needed scripts are loaded for admin pages.
43
         */
44
        public function init() {
45
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
46
                $page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
×
NEW
47
                if ( \in_array( $page, [ Settings_Integration::PAGE, Academy_Integration::PAGE, Support_Integration::PAGE ], true ) ) {
×
48
                        // Bail, this is managed in the applicable integration.
UNCOV
49
                        return;
×
50
                }
51

52
                add_action( 'admin_enqueue_scripts', [ $this, 'config_page_scripts' ] );
×
53
                add_action( 'admin_enqueue_scripts', [ $this, 'config_page_styles' ] );
×
54
        }
55

56
        /**
57
         * Loads the required styles for the config page.
58
         */
59
        public function config_page_styles() {
60
                wp_enqueue_style( 'dashboard' );
×
61
                wp_enqueue_style( 'thickbox' );
×
62
                wp_enqueue_style( 'global' );
×
63
                wp_enqueue_style( 'wp-admin' );
×
64
                $this->asset_manager->enqueue_style( 'admin-css' );
×
65
                $this->asset_manager->enqueue_style( 'monorepo' );
×
66

67
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
68
                $page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
×
69
                if ( $page === 'wpseo_licenses' ) {
×
70
                        $this->asset_manager->enqueue_style( 'tailwind' );
×
71
                }
72
        }
73

74
        /**
75
         * Loads the required scripts for the config page.
76
         */
77
        public function config_page_scripts() {
78
                $this->asset_manager->enqueue_script( 'settings' );
×
79
                wp_enqueue_script( 'dashboard' );
×
80
                wp_enqueue_script( 'thickbox' );
×
81

82
                $alert_dismissal_action = YoastSEO()->classes->get( \Yoast\WP\SEO\Actions\Alert_Dismissal_Action::class );
×
83
                $dismissed_alerts       = $alert_dismissal_action->all_dismissed();
×
84

85
                $script_data = [
×
86
                        'userLanguageCode'               => WPSEO_Language_Utils::get_language( \get_user_locale() ),
×
87
                        'dismissedAlerts'                => $dismissed_alerts,
×
88
                        'isRtl'                          => is_rtl(),
×
89
                        'isPremium'                      => YoastSEO()->helpers->product->is_premium(),
×
90
                        'webinarIntroSettingsUrl'        => WPSEO_Shortlinker::get( 'https://yoa.st/webinar-intro-settings' ),
×
91
                        'webinarIntroFirstTimeConfigUrl' => $this->get_webinar_shortlink(),
×
92
                ];
×
93

94
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
95
                $page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
×
96

97
                if ( in_array( $page, [ WPSEO_Admin::PAGE_IDENTIFIER, 'wpseo_workouts' ], true ) ) {
×
98
                        wp_enqueue_media();
×
99

100
                        $script_data['media'] = [
×
101
                                'choose_image' => __( 'Use Image', 'wordpress-seo' ),
×
102
                        ];
×
103

104
                        $script_data['userEditUrl'] = add_query_arg( 'user_id', '{user_id}', admin_url( 'user-edit.php' ) );
×
105
                }
106

107
                if ( $page === 'wpseo_tools' ) {
×
108
                        $this->enqueue_tools_scripts();
×
109
                }
110

111
                $this->asset_manager->localize_script( 'settings', 'wpseoScriptData', $script_data );
×
112
                $this->asset_manager->enqueue_user_language_script();
×
113
        }
114

115
        /**
116
         * Retrieves some variables that are needed for replacing variables in JS.
117
         *
118
         * @deprecated 20.3
119
         * @codeCoverageIgnore
120
         *
121
         * @return array The replacement and recommended replacement variables.
122
         */
123
        public function get_replace_vars_script_data() {
124
                _deprecated_function( __METHOD__, 'Yoast SEO 20.3' );
125
                $replace_vars                 = new WPSEO_Replace_Vars();
126
                $recommended_replace_vars     = new WPSEO_Admin_Recommended_Replace_Vars();
127
                $editor_specific_replace_vars = new WPSEO_Admin_Editor_Specific_Replace_Vars();
128
                $replace_vars_list            = $replace_vars->get_replacement_variables_list();
129

130
                return [
131
                        'replace_vars'                 => $replace_vars_list,
132
                        'recommended_replace_vars'     => $recommended_replace_vars->get_recommended_replacevars(),
133
                        'editor_specific_replace_vars' => $editor_specific_replace_vars->get(),
134
                        'shared_replace_vars'          => $editor_specific_replace_vars->get_generic( $replace_vars_list ),
135
                        'hidden_replace_vars'          => $replace_vars->get_hidden_replace_vars(),
136
                ];
137
        }
138

139
        /**
140
         * Enqueues and handles all the tool dependencies.
141
         */
142
        private function enqueue_tools_scripts() {
143
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
144
                $tool = isset( $_GET['tool'] ) && is_string( $_GET['tool'] ) ? sanitize_text_field( wp_unslash( $_GET['tool'] ) ) : '';
×
145

146
                if ( empty( $tool ) ) {
×
147
                        $this->asset_manager->enqueue_script( 'yoast-seo' );
×
148
                }
149

150
                if ( $tool === 'bulk-editor' ) {
×
151
                        $this->asset_manager->enqueue_script( 'bulk-editor' );
×
152
                }
153
        }
154

155
        /**
156
         * Returns the appropriate shortlink for the Webinar.
157
         *
158
         * @return string The shortlink for the Webinar.
159
         */
160
        private function get_webinar_shortlink() {
161
                if ( YoastSEO()->helpers->product->is_premium() ) {
×
162
                        return WPSEO_Shortlinker::get( 'https://yoa.st/webinar-intro-first-time-config-premium' );
×
163
                }
164

165
                return WPSEO_Shortlinker::get( 'https://yoa.st/webinar-intro-first-time-config' );
×
166
        }
167
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc