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

Yoast / wordpress-seo / 4c5f9780cef7c22b7f9bfbace943d71badc638ed

08 Oct 2024 09:39AM UTC coverage: 54.494% (-0.04%) from 54.538%
4c5f9780cef7c22b7f9bfbace943d71badc638ed

push

github

YoastBot
Bump version to 23.6 on free

7502 of 13498 branches covered (55.58%)

Branch coverage included in aggregate %.

29530 of 54458 relevant lines covered (54.23%)

41951.32 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\New_Dashboard_Ui_Conditional;
10
use Yoast\WP\SEO\Dashboard\User_Interface\New_Dashboard_Page_Integration;
11
use Yoast\WP\SEO\Integrations\Academy_Integration;
12
use Yoast\WP\SEO\Integrations\Settings_Integration;
13
use Yoast\WP\SEO\Integrations\Support_Integration;
14
use Yoast\WP\SEO\Promotions\Application\Promotion_Manager;
15

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

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

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

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

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

46
        /**
47
         * Make sure the needed scripts are loaded for admin pages.
48
         *
49
         * @return void
50
         */
51
        public function init() {
×
52
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
53
                $page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
×
54

55
                // Don't load the scripts for the following pages.
56
                $page_exceptions = in_array( $page, [ Settings_Integration::PAGE, Academy_Integration::PAGE, Support_Integration::PAGE ], true );
×
57
                // Don't load the scripts for the new dashboard page, but only if the feature flag is enabled.
58
                $new_dashboard_conditional = new New_Dashboard_Ui_Conditional();
×
59
                $new_dashboard_page        = ( $page === New_Dashboard_Page_Integration::PAGE && $new_dashboard_conditional->is_met() );
×
60

61
                if ( $page_exceptions || $new_dashboard_page ) {
×
62
                        // Bail, this is managed in the applicable integration.
63
                        return;
×
64
                }
65
                add_action( 'admin_enqueue_scripts', [ $this, 'config_page_scripts' ] );
×
66
                add_action( 'admin_enqueue_scripts', [ $this, 'config_page_styles' ] );
×
67
        }
68

69
        /**
70
         * Loads the required styles for the config page.
71
         *
72
         * @return void
73
         */
74
        public function config_page_styles() {
×
75
                wp_enqueue_style( 'dashboard' );
×
76
                wp_enqueue_style( 'thickbox' );
×
77
                wp_enqueue_style( 'global' );
×
78
                wp_enqueue_style( 'wp-admin' );
×
79
                $this->asset_manager->enqueue_style( 'admin-css' );
×
80
                $this->asset_manager->enqueue_style( 'monorepo' );
×
81

82
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
83
                $page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
×
84
                if ( $page === 'wpseo_licenses' ) {
×
85
                        $this->asset_manager->enqueue_style( 'tailwind' );
×
86
                }
87
        }
88

89
        /**
90
         * Loads the required scripts for the config page.
91
         *
92
         * @return void
93
         */
94
        public function config_page_scripts() {
×
95
                $this->asset_manager->enqueue_script( 'settings' );
×
96
                wp_enqueue_script( 'dashboard' );
×
97
                wp_enqueue_script( 'thickbox' );
×
98

99
                $alert_dismissal_action = YoastSEO()->classes->get( Alert_Dismissal_Action::class );
×
100
                $dismissed_alerts       = $alert_dismissal_action->all_dismissed();
×
101

102
                $script_data = [
×
103
                        'dismissedAlerts'                => $dismissed_alerts,
×
104
                        'isRtl'                          => is_rtl(),
×
105
                        'isPremium'                      => YoastSEO()->helpers->product->is_premium(),
×
106
                        'currentPromotions'              => YoastSEO()->classes->get( Promotion_Manager::class )->get_current_promotions(),
×
107
                        'webinarIntroFirstTimeConfigUrl' => $this->get_webinar_shortlink(),
×
108
                        'linkParams'                     => WPSEO_Shortlinker::get_query_params(),
×
109
                        'pluginUrl'                      => plugins_url( '', WPSEO_FILE ),
×
110
                ];
×
111

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

115
                if ( in_array( $page, [ WPSEO_Admin::PAGE_IDENTIFIER, 'wpseo_workouts' ], true ) ) {
×
116
                        wp_enqueue_media();
×
117

118
                        $script_data['userEditUrl'] = add_query_arg( 'user_id', '{user_id}', admin_url( 'user-edit.php' ) );
×
119
                }
120

121
                if ( $page === 'wpseo_tools' ) {
×
122
                        $this->enqueue_tools_scripts();
×
123
                }
124

125
                $this->asset_manager->localize_script( 'settings', 'wpseoScriptData', $script_data );
×
126
                $this->asset_manager->enqueue_user_language_script();
×
127
        }
128

129
        /**
130
         * Enqueues and handles all the tool dependencies.
131
         *
132
         * @return void
133
         */
134
        private function enqueue_tools_scripts() {
×
135
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
136
                $tool = isset( $_GET['tool'] ) && is_string( $_GET['tool'] ) ? sanitize_text_field( wp_unslash( $_GET['tool'] ) ) : '';
×
137

138
                if ( empty( $tool ) ) {
×
139
                        $this->asset_manager->enqueue_script( 'yoast-seo' );
×
140
                }
141

142
                if ( $tool === 'bulk-editor' ) {
×
143
                        $this->asset_manager->enqueue_script( 'bulk-editor' );
×
144
                }
145
        }
146

147
        /**
148
         * Returns the appropriate shortlink for the Webinar.
149
         *
150
         * @return string The shortlink for the Webinar.
151
         */
152
        private function get_webinar_shortlink() {
×
153
                if ( YoastSEO()->helpers->product->is_premium() ) {
×
154
                        return WPSEO_Shortlinker::get( 'https://yoa.st/webinar-intro-first-time-config-premium' );
×
155
                }
156

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