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

Yoast / wordpress-seo / 71506449b43aef591ba916913e1e481c70e916c4

24 Sep 2024 07:41AM UTC coverage: 54.538% (+0.04%) from 54.503%
71506449b43aef591ba916913e1e481c70e916c4

push

github

YoastBot
Bump version to 23.5 on free

7511 of 13516 branches covered (55.57%)

Branch coverage included in aggregate %.

29694 of 54702 relevant lines covered (54.28%)

41754.08 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
         * @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
                if ( in_array( $page, [ Settings_Integration::PAGE, Academy_Integration::PAGE, Support_Integration::PAGE ], true ) ) {
×
54
                        // Bail, this is managed in the applicable integration.
55
                        return;
×
56
                }
57

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

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

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

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

92
                $alert_dismissal_action  = YoastSEO()->classes->get( Alert_Dismissal_Action::class );
×
93
                $dismissed_alerts        = $alert_dismissal_action->all_dismissed();
×
94
                $woocommerce_conditional = new WooCommerce_Conditional();
×
95

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

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

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

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

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

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

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

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

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

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

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