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

Yoast / wordpress-seo / 5794075026

pending completion
5794075026

Pull #20546

github

web-flow
Merge 6c13efa36 into b0de79e54
Pull Request #20546: Introduce the Introductions functionality

135 of 148 new or added lines in 20 files covered. (91.22%)

681 existing lines in 5 files now uncovered.

12419 of 26427 relevant lines covered (46.99%)

3.46 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'] ) ) : '';
×
47
                if ( \in_array( $page, [ Settings_Integration::PAGE, Academy_Integration::PAGE, Support_Integration::PAGE ], true ) ) {
×
48
                        // Bail, this is managed in the applicable integration.
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(),
×
NEW
92
                        'pluginUrl'                      => \plugins_url( '', \WPSEO_FILE ),
×
UNCOV
93
                ];
×
94

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

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

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

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

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

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

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

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

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

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

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

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

166
                return WPSEO_Shortlinker::get( 'https://yoa.st/webinar-intro-first-time-config' );
×
167
        }
168
}
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