PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
← All changes | admin/class-config.php +62 -91 18.328.5 View file →
@@ -4,9 +4,16 @@
4 4 *
5 5 * @package WPSEO\Admin
6 6 */
7 7
8 -use Yoast\WP\SEO\Config\Schema_Types;
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\Admin\Redirects_Page_Integration;
12 +use Yoast\WP\SEO\Integrations\Settings_Integration;
13 +use Yoast\WP\SEO\Integrations\Support_Integration;
14 +use Yoast\WP\SEO\Plans\User_Interface\Plans_Page_Integration;
15 +use Yoast\WP\SEO\Promotions\Application\Promotion_Manager;
9 16
10 17 /**
11 18 * Class WPSEO_Admin_Pages.
12 19 *
@@ -32,19 +39,38 @@
32 39 * Class constructor, which basically only hooks the init function on the init hook.
33 40 */
34 41 public function __construct() {
35 42 add_action( 'init', [ $this, 'init' ], 20 );
43 +
36 44 $this->asset_manager = new WPSEO_Admin_Asset_Manager();
37 45 }
38 46
39 47 /**
40 48 * Make sure the needed scripts are loaded for admin pages.
49 + *
50 + * @return void
41 51 */
42 52 public function init() {
43 - if ( filter_input( INPUT_GET, 'wpseo_reset_defaults' ) && wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ), 'wpseo_reset_defaults' ) && current_user_can( 'manage_options' ) ) {
44 - WPSEO_Options::reset();
53 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
54 + $page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
55 +
56 + // Don't load the scripts for the following pages.
57 + $page_exceptions = in_array(
58 + $page,
59 + [
60 + Settings_Integration::PAGE,
61 + Academy_Integration::PAGE,
62 + Support_Integration::PAGE,
63 + Plans_Page_Integration::PAGE,
64 + Redirects_Page_Integration::PAGE,
65 + ],
66 + true,
67 + );
68 + $new_dashboard_page = ( $page === General_Page_Integration::PAGE && ! is_network_admin() );
69 + if ( $page_exceptions || $new_dashboard_page ) {
70 + // Bail, this is managed in the applicable integration.
71 + return;
45 72 }
46 -
47 73 add_action( 'admin_enqueue_scripts', [ $this, 'config_page_scripts' ] );
48 74 add_action( 'admin_enqueue_scripts', [ $this, 'config_page_styles' ] );
49 75 }
50 76
@@ -49,8 +75,10 @@
49 75 }
50 76
51 77 /**
52 78 * Loads the required styles for the config page.
79 + *
80 + * @return void
53 81 */
54 82 public function config_page_styles() {
55 83 wp_enqueue_style( 'dashboard' );
56 84 wp_enqueue_style( 'thickbox' );
@@ -55,23 +83,16 @@
55 83 wp_enqueue_style( 'dashboard' );
56 84 wp_enqueue_style( 'thickbox' );
57 85 wp_enqueue_style( 'global' );
58 86 wp_enqueue_style( 'wp-admin' );
59 - $this->asset_manager->enqueue_style( 'select2' );
60 87 $this->asset_manager->enqueue_style( 'admin-css' );
61 -
62 - $page = filter_input( INPUT_GET, 'page' );
63 - if ( $page === 'wpseo_titles' ) {
64 - $this->asset_manager->enqueue_style( 'search-appearance' );
65 - }
66 -
67 - if ( $page === 'wpseo_social' || $page === 'wpseo_licenses' ) {
68 - $this->asset_manager->enqueue_style( 'monorepo' );
69 - }
88 + $this->asset_manager->enqueue_style( 'monorepo' );
70 89 }
71 90
72 91 /**
73 92 * Loads the required scripts for the config page.
93 + *
94 + * @return void
74 95 */
75 96 public function config_page_scripts() {
76 97 $this->asset_manager->enqueue_script( 'settings' );
77 98 wp_enqueue_script( 'dashboard' );
@@ -76,52 +97,29 @@
76 97 $this->asset_manager->enqueue_script( 'settings' );
77 98 wp_enqueue_script( 'dashboard' );
78 99 wp_enqueue_script( 'thickbox' );
79 100
80 - $alert_dismissal_action = YoastSEO()->classes->get( \Yoast\WP\SEO\Actions\Alert_Dismissal_Action::class );
101 + $alert_dismissal_action = YoastSEO()->classes->get( Alert_Dismissal_Action::class );
81 102 $dismissed_alerts = $alert_dismissal_action->all_dismissed();
82 103
83 104 $script_data = [
84 - 'userLanguageCode' => WPSEO_Language_Utils::get_language( \get_user_locale() ),
85 - 'dismissedAlerts' => $dismissed_alerts,
105 + 'dismissedAlerts' => $dismissed_alerts,
106 + 'isRtl' => is_rtl(),
107 + 'isPremium' => YoastSEO()->helpers->product->is_premium(),
108 + 'currentPromotions' => YoastSEO()->classes->get( Promotion_Manager::class )
109 + ->get_current_promotions(),
110 + 'webinarIntroFirstTimeConfigUrl' => $this->get_webinar_shortlink(),
111 + 'linkParams' => WPSEO_Shortlinker::get_query_params(),
112 + 'pluginUrl' => plugins_url( '', WPSEO_FILE ),
86 113 ];
87 114
88 - $page = filter_input( INPUT_GET, 'page' );
115 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
116 + $page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
89 117
90 - if ( $page === 'wpseo_titles' ) {
91 - $script_data['analysis'] = [
92 - 'plugins' => [
93 - 'replaceVars' => $this->get_replace_vars_script_data(),
94 - ],
95 - ];
96 -
97 - $schema_types = new Schema_Types();
98 - $script_data['searchAppearance'] = [
99 - 'isRtl' => is_rtl(),
100 - 'userEditUrl' => add_query_arg( 'user_id', '{user_id}', admin_url( 'user-edit.php' ) ),
101 - 'brushstrokeBackgroundURL' => plugins_url( 'images/brushstroke_background.svg', WPSEO_FILE ),
102 - 'showLocalSEOUpsell' => $this->should_show_local_seo_upsell(),
103 - 'localSEOUpsellURL' => WPSEO_Shortlinker::get( 'https://yoa.st/3mp' ),
104 - 'knowledgeGraphCompanyInfoMissing' => WPSEO_Language_Utils::get_knowledge_graph_company_info_missing_l10n(),
105 - 'schema' => [
106 - 'pageTypeOptions' => $schema_types->get_page_type_options(),
107 - 'articleTypeOptions' => $schema_types->get_article_type_options(),
108 - ],
109 - ];
110 -
111 - /**
112 - * Remove the emoji script as it is incompatible with both React and any
113 - * contenteditable fields.
114 - */
115 - remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
116 - }
117 -
118 - if ( in_array( $page, [ 'wpseo_social', WPSEO_Admin::PAGE_IDENTIFIER, 'wpseo_titles', 'wpseo_workouts' ], true ) ) {
118 + if ( in_array( $page, [ WPSEO_Admin::PAGE_IDENTIFIER, 'wpseo_workouts' ], true ) ) {
119 119 wp_enqueue_media();
120 120
121 - $script_data['media'] = [
122 - 'choose_image' => __( 'Use Image', 'wordpress-seo' ),
123 - ];
121 + $script_data['userEditUrl'] = add_query_arg( 'user_id', '{user_id}', admin_url( 'user-edit.php' ) );
124 122 }
125 123
126 124 if ( $page === 'wpseo_tools' ) {
127 125 $this->enqueue_tools_scripts();
@@ -126,61 +124,34 @@
126 124 if ( $page === 'wpseo_tools' ) {
127 125 $this->enqueue_tools_scripts();
128 126 }
129 127
130 - if ( $page === 'wpseo_social' ) {
131 - $script_data['social'] = true;
132 - }
133 -
134 128 $this->asset_manager->localize_script( 'settings', 'wpseoScriptData', $script_data );
135 - $this->asset_manager->enqueue_user_language_script();
136 129 }
137 130
138 131 /**
139 - * Retrieves some variables that are needed for replacing variables in JS.
132 + * Enqueues and handles all the tool dependencies.
140 133 *
141 - * @return array The replacement and recommended replacement variables.
134 + * @return void
142 135 */
143 - public function get_replace_vars_script_data() {
144 - $replace_vars = new WPSEO_Replace_Vars();
145 - $recommended_replace_vars = new WPSEO_Admin_Recommended_Replace_Vars();
146 - $editor_specific_replace_vars = new WPSEO_Admin_Editor_Specific_Replace_Vars();
147 - $replace_vars_list = $replace_vars->get_replacement_variables_list();
136 + private function enqueue_tools_scripts() {
137 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
138 + $tool = isset( $_GET['tool'] ) && is_string( $_GET['tool'] ) ? sanitize_text_field( wp_unslash( $_GET['tool'] ) ) : '';
148 139
149 - return [
150 - 'replace_vars' => $replace_vars_list,
151 - 'recommended_replace_vars' => $recommended_replace_vars->get_recommended_replacevars(),
152 - 'editor_specific_replace_vars' => $editor_specific_replace_vars->get(),
153 - 'shared_replace_vars' => $editor_specific_replace_vars->get_generic( $replace_vars_list ),
154 - 'hidden_replace_vars' => $replace_vars->get_hidden_replace_vars(),
155 - ];
140 + if ( empty( $tool ) ) {
141 + $this->asset_manager->enqueue_script( 'yoast-seo' );
142 + }
156 143 }
157 144
158 145 /**
159 - * Determines whether the Local SEO upsell should be shown.
146 + * Returns the appropriate shortlink for the Webinar.
160 147 *
161 - * The Local SEO upsell should:
162 - * - Only be shown in Free, not when Premium is active.
163 - * - Not be shown when Local SEO is active.
164 - *
165 - * @return bool Whether the Local SEO upsell should be shown.
148 + * @return string The shortlink for the Webinar.
166 149 */
167 - private function should_show_local_seo_upsell() {
168 - return ! YoastSEO()->helpers->product->is_premium()
169 - && ! ( defined( 'WPSEO_LOCAL_FILE' ) );
170 - }
171 -
172 - /**
173 - * Enqueues and handles all the tool dependencies.
174 - */
175 - private function enqueue_tools_scripts() {
176 - $tool = filter_input( INPUT_GET, 'tool' );
177 -
178 - if ( empty( $tool ) ) {
179 - $this->asset_manager->enqueue_script( 'yoast-seo' );
150 + private function get_webinar_shortlink() {
151 + if ( YoastSEO()->helpers->product->is_premium() ) {
152 + return WPSEO_Shortlinker::get( 'https://yoa.st/webinar-intro-first-time-config-premium' );
180 153 }
181 154
182 - if ( $tool === 'bulk-editor' ) {
183 - $this->asset_manager->enqueue_script( 'bulk-editor' );
184 - }
155 + return WPSEO_Shortlinker::get( 'https://yoa.st/webinar-intro-first-time-config' );
185 156 }
186 157 }