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

Yoast / wordpress-seo / 23a72bf1994dab30060181382d0556bd26d909a7

21 Oct 2024 12:22PM UTC coverage: 54.571% (+0.002%) from 54.569%
23a72bf1994dab30060181382d0556bd26d909a7

Pull #21691

github

web-flow
Merge 6fe61e5b5 into 8a4aceaf1
Pull Request #21691: Remove conditional and rename dashboard to general page.

7549 of 13564 branches covered (55.65%)

Branch coverage included in aggregate %.

14 of 35 new or added lines in 17 files covered. (40.0%)

538 existing lines in 3 files now uncovered.

29672 of 54642 relevant lines covered (54.3%)

41714.17 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\General\User_Interface\General_Page_Integration;
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
         * @return void
49
         */
50
        public function init() {
×
51
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
52
                $page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
×
53

54
                // Don't load the scripts for the following pages.
NEW
55
                $page_exceptions    = in_array( $page, [ Settings_Integration::PAGE, Academy_Integration::PAGE, Support_Integration::PAGE ], true );
×
NEW
56
                $new_dashboard_page = ( $page === General_Page_Integration::PAGE && ! is_network_admin() );
×
UNCOV
57
                if ( $page_exceptions || $new_dashboard_page ) {
×
58
                        // Bail, this is managed in the applicable integration.
59
                        return;
×
60
                }
61
                add_action( 'admin_enqueue_scripts', [ $this, 'config_page_scripts' ] );
×
62
                add_action( 'admin_enqueue_scripts', [ $this, 'config_page_styles' ] );
×
63
        }
64

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

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

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

95
                $alert_dismissal_action = YoastSEO()->classes->get( Alert_Dismissal_Action::class );
×
96
                $dismissed_alerts       = $alert_dismissal_action->all_dismissed();
×
97

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

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

111
                if ( in_array( $page, [ WPSEO_Admin::PAGE_IDENTIFIER, 'wpseo_workouts' ], true ) ) {
×
112
                        wp_enqueue_media();
×
113

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

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

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

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

134
                if ( empty( $tool ) ) {
×
135
                        $this->asset_manager->enqueue_script( 'yoast-seo' );
×
136
                }
137

138
                if ( $tool === 'bulk-editor' ) {
×
139
                        $this->asset_manager->enqueue_script( 'bulk-editor' );
×
140
                }
141
        }
142

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

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