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

Yoast / wordpress-seo / 7255789135

19 Dec 2023 12:48AM UTC coverage: 49.39%. Remained the same
7255789135

push

github

web-flow
Merge pull request #20975 from Yoast/JRF/QA/no-fqn-in-non-namespaced-files

CS/QA: don't use fully qualified global functions and constants in non-namespaced files

12 of 126 new or added lines in 27 files covered. (9.52%)

2 existing lines in 1 file now uncovered.

15426 of 31233 relevant lines covered (49.39%)

4.07 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\Actions\Alert_Dismissal_Action;
9
use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional;
10
use Yoast\WP\SEO\Integrations\Academy_Integration;
11
use Yoast\WP\SEO\Integrations\Settings_Integration;
12
use Yoast\WP\SEO\Integrations\Support_Integration;
13
use Yoast\WP\SEO\Promotions\Application\Promotion_Manager;
14

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

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

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

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

42
                $this->asset_manager = new WPSEO_Admin_Asset_Manager();
×
43
        }
44

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

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

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

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

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

86
                $alert_dismissal_action  = YoastSEO()->classes->get( Alert_Dismissal_Action::class );
×
87
                $dismissed_alerts        = $alert_dismissal_action->all_dismissed();
×
88
                $woocommerce_conditional = new WooCommerce_Conditional();
×
89

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

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

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

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

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

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

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

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

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

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

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

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

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

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