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

Yoast / wordpress-seo / 6638054992

25 Oct 2023 08:55AM UTC coverage: 49.106%. First build
6638054992

Pull #20653

github

vraja-pro
Merge remote-tracking branch 'origin/feature/upgrade-react-and-tests' into feature/upgrade-react-and-tests
Pull Request #20653: Feature/upgrade react and tests

64 of 157 new or added lines in 34 files covered. (40.76%)

13135 of 26748 relevant lines covered (49.11%)

3.96 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
use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional;
12

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

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

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

34
        /**
35
         * Class constructor, which basically only hooks the init function on the init hook.
36
         */
37
        public function __construct() {
38
                add_action( 'init', [ $this, 'init' ], 20 );
×
39

40
                $this->asset_manager = new WPSEO_Admin_Asset_Manager();
×
41
        }
42

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

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

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

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

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

84
                $alert_dismissal_action  = YoastSEO()->classes->get( \Yoast\WP\SEO\Actions\Alert_Dismissal_Action::class );
×
85
                $dismissed_alerts        = $alert_dismissal_action->all_dismissed();
×
86
                $woocommerce_conditional = new WooCommerce_Conditional();
×
87

88
                $script_data = [
×
89
                        'userLanguageCode'               => WPSEO_Language_Utils::get_language( \get_user_locale() ),
×
90
                        'dismissedAlerts'                => $dismissed_alerts,
×
91
                        'isRtl'                          => is_rtl(),
×
92
                        'isPremium'                      => YoastSEO()->helpers->product->is_premium(),
×
93
                        'isWooCommerceActive'            => $woocommerce_conditional->is_met(),
×
NEW
94
                        'currentPromotions'              => YoastSEO()->classes->get( Yoast\WP\SEO\Promotions\Application\Promotion_Manager::class )->get_current_promotions(),
×
95
                        'webinarIntroSettingsUrl'        => WPSEO_Shortlinker::get( 'https://yoa.st/webinar-intro-settings' ),
×
96
                        'webinarIntroFirstTimeConfigUrl' => $this->get_webinar_shortlink(),
×
NEW
97
                        'linkParams'                     => WPSEO_Shortlinker::get_query_params(),
×
98
                        'pluginUrl'                      => \plugins_url( '', \WPSEO_FILE ),
×
99
                ];
×
100

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

104
                if ( in_array( $page, [ WPSEO_Admin::PAGE_IDENTIFIER, 'wpseo_workouts' ], true ) ) {
×
105
                        wp_enqueue_media();
×
106

107
                        $script_data['media'] = [
×
108
                                'choose_image' => __( 'Use Image', 'wordpress-seo' ),
×
109
                        ];
×
110

111
                        $script_data['userEditUrl'] = add_query_arg( 'user_id', '{user_id}', admin_url( 'user-edit.php' ) );
×
112
                }
113

114
                if ( $page === 'wpseo_tools' ) {
×
115
                        $this->enqueue_tools_scripts();
×
116
                }
117

118
                $this->asset_manager->localize_script( 'settings', 'wpseoScriptData', $script_data );
×
119
                $this->asset_manager->enqueue_user_language_script();
×
120
        }
121

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

137
                return [
138
                        'replace_vars'                 => $replace_vars_list,
139
                        'recommended_replace_vars'     => $recommended_replace_vars->get_recommended_replacevars(),
140
                        'editor_specific_replace_vars' => $editor_specific_replace_vars->get(),
141
                        'shared_replace_vars'          => $editor_specific_replace_vars->get_generic( $replace_vars_list ),
142
                        'hidden_replace_vars'          => $replace_vars->get_hidden_replace_vars(),
143
                ];
144
        }
145

146
        /**
147
         * Enqueues and handles all the tool dependencies.
148
         */
149
        private function enqueue_tools_scripts() {
150
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
151
                $tool = isset( $_GET['tool'] ) && is_string( $_GET['tool'] ) ? sanitize_text_field( wp_unslash( $_GET['tool'] ) ) : '';
×
152

153
                if ( empty( $tool ) ) {
×
154
                        $this->asset_manager->enqueue_script( 'yoast-seo' );
×
155
                }
156

157
                if ( $tool === 'bulk-editor' ) {
×
158
                        $this->asset_manager->enqueue_script( 'bulk-editor' );
×
159
                }
160
        }
161

162
        /**
163
         * Returns the appropriate shortlink for the Webinar.
164
         *
165
         * @return string The shortlink for the Webinar.
166
         */
167
        private function get_webinar_shortlink() {
168
                if ( YoastSEO()->helpers->product->is_premium() ) {
×
169
                        return WPSEO_Shortlinker::get( 'https://yoa.st/webinar-intro-first-time-config-premium' );
×
170
                }
171

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