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-admin-init.php +86 -192 19.028.5 View file →
@@ -35,8 +35,9 @@
35 35 $this->asset_manager = new WPSEO_Admin_Asset_Manager();
36 36
37 37 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_dismissible' ] );
38 38 add_action( 'admin_init', [ $this, 'unsupported_php_notice' ], 15 );
39 + add_action( 'admin_init', [ $this, 'remove_translations_notification' ], 15 );
39 40 add_action( 'admin_init', [ $this->asset_manager, 'register_assets' ] );
40 41 add_action( 'admin_init', [ $this, 'show_hook_deprecation_warnings' ] );
41 42 add_action( 'admin_init', [ 'WPSEO_Plugin_Conflict', 'hook_check_for_plugin_conflicts' ] );
42 43 add_action( 'admin_notices', [ $this, 'permalink_settings_notice' ] );
@@ -41,15 +42,8 @@
41 42 add_action( 'admin_init', [ 'WPSEO_Plugin_Conflict', 'hook_check_for_plugin_conflicts' ] );
42 43 add_action( 'admin_notices', [ $this, 'permalink_settings_notice' ] );
43 44 add_action( 'post_submitbox_misc_actions', [ $this, 'add_publish_box_section' ] );
44 45
45 - /*
46 - * The `admin_notices` hook fires on single site admin pages vs.
47 - * `network_admin_notices` which fires on multisite admin pages and
48 - * `user_admin_notices` which fires on multisite user admin pagss.
49 - */
50 - add_action( 'admin_notices', [ $this, 'search_engines_discouraged_notice' ] );
51 -
52 46 $this->load_meta_boxes();
53 47 $this->load_taxonomy_class();
54 48 $this->load_admin_page_class();
55 49 $this->load_admin_user_class();
@@ -58,8 +52,10 @@
58 52 }
59 53
60 54 /**
61 55 * Enqueue our styling for dismissible yoast notifications.
56 + *
57 + * @return void
62 58 */
63 59 public function enqueue_dismissible() {
64 60 $this->asset_manager->enqueue_style( 'dismissible' );
65 61 }
@@ -64,8 +60,18 @@
64 60 $this->asset_manager->enqueue_style( 'dismissible' );
65 61 }
66 62
67 63 /**
64 + * Removes any notification for incomplete translations.
65 + *
66 + * @return void
67 + */
68 + public function remove_translations_notification() {
69 + $notification_center = Yoast_Notification_Center::get();
70 + $notification_center->remove_notification_by_id( 'i18nModuleTranslationAssistance' );
71 + }
72 +
73 + /**
68 74 * Creates an unsupported PHP version notification in the notification center.
69 75 *
70 76 * @return void
71 77 */
@@ -102,28 +108,59 @@
102 108 *
103 109 * @return bool
104 110 */
105 111 private function on_wpseo_admin_page() {
106 - return $this->pagenow === 'admin.php' && strpos( filter_input( INPUT_GET, 'page' ), 'wpseo' ) === 0;
112 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
113 + if ( ! isset( $_GET['page'] ) || ! is_string( $_GET['page'] ) ) {
114 + return false;
115 + }
116 +
117 + if ( $this->pagenow !== 'admin.php' ) {
118 + return false;
119 + }
120 +
121 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
122 + $current_page = sanitize_text_field( wp_unslash( $_GET['page'] ) );
123 + return strpos( $current_page, 'wpseo' ) === 0;
107 124 }
108 125
109 126 /**
110 - * Determine whether we should load the meta box class and if so, load it.
127 + * Whether we should load the meta box classes.
128 + *
129 + * @return bool true if we should load the meta box classes, false otherwise.
111 130 */
112 - private function load_meta_boxes() {
113 -
114 - $is_editor = WPSEO_Metabox::is_post_overview( $this->pagenow ) || WPSEO_Metabox::is_post_edit( $this->pagenow );
115 - $is_inline_save = filter_input( INPUT_POST, 'action' ) === 'inline-save';
116 -
131 + private function should_load_meta_boxes() {
117 132 /**
118 133 * Filter: 'wpseo_always_register_metaboxes_on_admin' - Allow developers to change whether
119 134 * the WPSEO metaboxes are only registered on the typical pages (lean loading) or always
120 135 * registered when in admin.
121 136 *
122 - * @api bool Whether to always register the metaboxes or not. Defaults to false.
137 + * @param bool $register_metaboxes Whether to always register the metaboxes or not. Defaults to false.
123 138 */
124 - if ( $is_editor || $is_inline_save || apply_filters( 'wpseo_always_register_metaboxes_on_admin', false )
125 - ) {
139 + if ( apply_filters( 'wpseo_always_register_metaboxes_on_admin', false ) ) {
140 + return true;
141 + }
142 +
143 + // If we are in a post editor.
144 + if ( WPSEO_Metabox::is_post_overview( $this->pagenow ) || WPSEO_Metabox::is_post_edit( $this->pagenow ) ) {
145 + return true;
146 + }
147 +
148 + // If we are doing an inline save.
149 + if ( check_ajax_referer( 'inlineeditnonce', '_inline_edit', false ) && isset( $_POST['action'] ) && sanitize_text_field( wp_unslash( $_POST['action'] ) ) === 'inline-save' ) {
150 + return true;
151 + }
152 +
153 + return false;
154 + }
155 +
156 + /**
157 + * Determine whether we should load the meta box class and if so, load it.
158 + *
159 + * @return void
160 + */
161 + private function load_meta_boxes() {
162 + if ( $this->should_load_meta_boxes() ) {
126 163 $GLOBALS['wpseo_metabox'] = new WPSEO_Metabox();
127 164 $GLOBALS['wpseo_meta_columns'] = new WPSEO_Meta_Columns();
128 165 }
129 166 }
@@ -129,8 +166,10 @@
129 166 }
130 167
131 168 /**
132 169 * Determine if we should load our taxonomy edit class and if so, load it.
170 + *
171 + * @return void
133 172 */
134 173 private function load_taxonomy_class() {
135 174 if (
136 175 WPSEO_Taxonomy::is_term_edit( $this->pagenow )
@@ -143,8 +182,10 @@
143 182 /**
144 183 * Determine if we should load our admin pages class and if so, load it.
145 184 *
146 185 * Loads admin page class for all admin pages starting with `wpseo_`.
186 + *
187 + * @return void
147 188 */
148 189 private function load_admin_user_class() {
149 190 if ( in_array( $this->pagenow, [ 'user-edit.php', 'profile.php' ], true )
150 191 && current_user_can( 'edit_users' )
@@ -156,8 +197,10 @@
156 197 /**
157 198 * Determine if we should load our admin pages class and if so, load it.
158 199 *
159 200 * Loads admin page class for all admin pages starting with `wpseo_`.
201 + *
202 + * @return void
160 203 */
161 204 private function load_admin_page_class() {
162 205
163 206 if ( $this->on_wpseo_admin_page() ) {
@@ -163,21 +206,27 @@
163 206 if ( $this->on_wpseo_admin_page() ) {
164 207 // For backwards compatabilty, this still needs a global, for now...
165 208 $GLOBALS['wpseo_admin_pages'] = new WPSEO_Admin_Pages();
166 209
167 - $page = filter_input( INPUT_GET, 'page' );
168 - // Only register the yoast i18n when the page is a Yoast SEO page.
169 - if ( WPSEO_Utils::is_yoast_seo_free_page( $page ) ) {
170 - $this->register_i18n_promo_class();
171 - if ( $page !== 'wpseo_titles' ) {
172 - $this->register_premium_upsell_admin_block();
173 - }
210 + $page = null;
211 +
212 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
213 + if ( isset( $_GET['page'] ) && is_string( $_GET['page'] ) ) {
214 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
215 + $page = sanitize_text_field( wp_unslash( $_GET['page'] ) );
174 216 }
217 +
218 + // Only renders Yoast SEO Premium upsells when the page is a Yoast SEO page.
219 + if ( $page !== null && WPSEO_Utils::is_yoast_seo_free_page( $page ) ) {
220 + $this->register_premium_upsell_admin_block();
221 + }
175 222 }
176 223 }
177 224
178 225 /**
179 226 * Loads the plugin suggestions.
227 + *
228 + * @return void
180 229 */
181 230 private function load_plugin_suggestions() {
182 231 $suggestions = new WPSEO_Suggested_Plugins( new WPSEO_Plugin_Availability(), Yoast_Notification_Center::get() );
183 232 $suggestions->register_hooks();
@@ -195,69 +244,23 @@
195 244 }
196 245 }
197 246
198 247 /**
199 - * Registers the promotion class for our GlotPress instance, then creates a notification with the i18n promo.
248 + * See if we should start our XML Sitemaps Admin class.
200 249 *
201 - * @link https://github.com/Yoast/i18n-module
250 + * @return void
202 251 */
203 - private function register_i18n_promo_class() {
204 - // BC, because an older version of the i18n-module didn't have this class.
205 - $i18n_module = new Yoast_I18n_WordPressOrg_v3(
206 - [
207 - 'textdomain' => 'wordpress-seo',
208 - 'plugin_name' => 'Yoast SEO',
209 - 'hook' => 'wpseo_admin_promo_footer',
210 - ],
211 - false
212 - );
213 -
214 - $message = $i18n_module->get_promo_message();
215 -
216 - if ( $message !== '' ) {
217 - $message .= $i18n_module->get_dismiss_i18n_message_button();
218 - }
219 -
220 - $notification_center = Yoast_Notification_Center::get();
221 -
222 - $notification = new Yoast_Notification(
223 - $message,
224 - [
225 - 'type' => Yoast_Notification::WARNING,
226 - 'id' => 'i18nModuleTranslationAssistance',
227 - ]
228 - );
229 -
230 - if ( $message ) {
231 - $notification_center->add_notification( $notification );
232 -
233 - return;
234 - }
235 -
236 - $notification_center->remove_notification( $notification );
237 - }
238 -
239 - /**
240 - * See if we should start our XML Sitemaps Admin class.
241 - */
242 252 private function load_xml_sitemaps_admin() {
243 - if ( WPSEO_Options::get( 'enable_xml_sitemap', false ) ) {
253 + if ( WPSEO_Options::get( 'enable_xml_sitemap', false, [ 'wpseo' ] ) ) {
244 254 new WPSEO_Sitemaps_Admin();
245 255 }
246 256 }
247 257
248 258 /**
249 - * Checks whether search engines are discouraged from indexing the site.
259 + * Shows deprecation warnings to the user if a plugin has registered a filter we have deprecated.
250 260 *
251 - * @return bool Whether search engines are discouraged from indexing the site.
261 + * @return void
252 262 */
253 - private function are_search_engines_discouraged() {
254 - return (string) get_option( 'blog_public' ) === '0';
255 - }
256 -
257 - /**
258 - * Shows deprecation warnings to the user if a plugin has registered a filter we have deprecated.
259 - */
260 263 public function show_hook_deprecation_warnings() {
261 264 global $wp_filter;
262 265
263 266 if ( wp_doing_ajax() ) {
@@ -302,9 +305,9 @@
302 305
303 306 // Determine which filters have been registered.
304 307 $deprecated_notices = array_intersect(
305 308 array_keys( $deprecated_filters ),
306 - array_keys( $wp_filter )
309 + array_keys( $wp_filter ),
307 310 );
308 311
309 312 // Show notice for each deprecated filter or action that has been registered.
310 313 foreach ( $deprecated_notices as $deprecated_filter ) {
@@ -312,9 +315,9 @@
312 315 // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- Only uses the hardcoded values from above.
313 316 _deprecated_hook(
314 317 $deprecated_filter,
315 318 'WPSEO ' . $deprecation_info['version'],
316 - $deprecation_info['alternative']
319 + $deprecation_info['alternative'],
317 320 );
318 321 // phpcs:enable
319 322 }
320 323 }
@@ -329,8 +332,10 @@
329 332 }
330 333
331 334 /**
332 335 * Shows a notice on the permalink settings page.
336 + *
337 + * @return void
333 338 */
334 339 public function permalink_settings_notice() {
335 340 global $pagenow;
336 341
@@ -341,68 +346,21 @@
341 346 sprintf(
342 347 /* translators: %1$s and %2$s expand to <em> items to emphasize the word in the middle. */
343 348 esc_html__( 'Changing your permalinks settings can seriously impact your search engine visibility. It should almost %1$s never %2$s be done on a live website.', 'wordpress-seo' ),
344 349 '<em>',
345 - '</em>'
350 + '</em>',
346 351 ),
347 352 esc_url( WPSEO_Shortlinker::get( 'https://yoa.st/why-permalinks/' ) ),
348 353 // The link's content.
349 - esc_html__( 'Learn about why permalinks are important for SEO.', 'wordpress-seo' )
354 + esc_html__( 'Learn about why permalinks are important for SEO.', 'wordpress-seo' ),
350 355 );
351 356 }
352 357 }
353 358
354 359 /**
355 - * Determines whether and where the "search engines discouraged" admin notice should be displayed.
356 - *
357 - * @return bool Whether the "search engines discouraged" admin notice should be displayed.
358 - */
359 - private function should_display_search_engines_discouraged_notice() {
360 - $discouraged_pages = [
361 - 'index.php',
362 - 'plugins.php',
363 - 'update-core.php',
364 - ];
365 -
366 - return (
367 - $this->are_search_engines_discouraged()
368 - && WPSEO_Capability_Utils::current_user_can( 'manage_options' )
369 - && WPSEO_Options::get( 'ignore_search_engines_discouraged_notice', false ) === false
370 - && (
371 - $this->on_wpseo_admin_page()
372 - || in_array( $this->pagenow, $discouraged_pages, true )
373 - )
374 - );
375 - }
376 -
377 - /**
378 - * Displays an admin notice when WordPress is set to discourage search engines from indexing the site.
379 - *
380 - * @return void
381 - */
382 - public function search_engines_discouraged_notice() {
383 - if ( ! $this->should_display_search_engines_discouraged_notice() ) {
384 - return;
385 - }
386 -
387 - printf(
388 - '<div id="robotsmessage" class="notice notice-error"><p><strong>%1$s</strong> %2$s <button type="button" id="robotsmessage-dismiss-button" class="button-link hide-if-no-js" data-nonce="%3$s">%4$s</button></p></div>',
389 - esc_html__( 'Huge SEO Issue: You\'re blocking access to robots.', 'wordpress-seo' ),
390 - sprintf(
391 - /* translators: 1: Link start tag to the WordPress Reading Settings page, 2: Link closing tag. */
392 - esc_html__( 'If you want search engines to show this site in their results, you must %1$sgo to your Reading Settings%2$s and uncheck the box for Search Engine Visibility.', 'wordpress-seo' ),
393 - '<a href="' . esc_url( admin_url( 'options-reading.php' ) ) . '">',
394 - '</a>'
395 - ),
396 - esc_js( wp_create_nonce( 'wpseo-ignore' ) ),
397 - esc_html__( 'I don\'t want this site to show in the search results.', 'wordpress-seo' )
398 - );
399 - }
400 -
401 - /**
402 360 * Adds a custom Yoast section within the Classic Editor publish box.
403 361 *
404 - * @param \WP_Post $post The current post object.
362 + * @param WP_Post $post The current post object.
405 363 *
406 364 * @return void
407 365 */
408 366 public function add_publish_box_section( $post ) {
@@ -412,74 +370,10 @@
412 370 <?php
413 371 /**
414 372 * Fires after the post time/date setting in the Publish meta box.
415 373 *
416 - * @api \WP_Post The current post object.
374 + * @param WP_Post $post The current post object.
417 375 */
418 376 do_action( 'wpseo_publishbox_misc_actions', $post );
419 377 }
420 - }
421 -
422 - /* ********************* DEPRECATED METHODS ********************* */
423 -
424 - /**
425 - * Notify about the default tagline if the user hasn't changed it.
426 - *
427 - * @deprecated 13.2
428 - * @codeCoverageIgnore
429 - */
430 - public function tagline_notice() {
431 - _deprecated_function( __METHOD__, 'WPSEO 13.2' );
432 - }
433 -
434 - /**
435 - * Returns whether or not the site has the default tagline.
436 - *
437 - * @deprecated 13.2
438 - * @codeCoverageIgnore
439 - *
440 - * @return bool
441 - */
442 - public function has_default_tagline() {
443 - _deprecated_function( __METHOD__, 'WPSEO 13.2' );
444 -
445 - $blog_description = get_bloginfo( 'description' );
446 - $default_blog_description = 'Just another WordPress site';
447 -
448 - // We are using the WordPress internal translation.
449 - $translated_blog_description = __( 'Just another WordPress site', 'default' );
450 -
451 - return $translated_blog_description === $blog_description || $default_blog_description === $blog_description;
452 - }
453 -
454 - /**
455 - * Shows an alert when the permalink doesn't contain %postname%.
456 - *
457 - * @deprecated 13.2
458 - * @codeCoverageIgnore
459 - */
460 - public function permalink_notice() {
461 - _deprecated_function( __METHOD__, 'WPSEO 13.2' );
462 - }
463 -
464 - /**
465 - * Add an alert if the blog is not publicly visible.
466 - *
467 - * @deprecated 14.1
468 - * @codeCoverageIgnore
469 - */
470 - public function blog_public_notice() {
471 - _deprecated_function( __METHOD__, 'WPSEO 14.1' );
472 - }
473 -
474 - /**
475 - * Handles the notifiers for the dashboard page.
476 - *
477 - * @deprecated 14.1
478 - * @codeCoverageIgnore
479 - *
480 - * @return void
481 - */
482 - public function handle_notifications() {
483 - _deprecated_function( __METHOD__, 'WPSEO 14.1' );
484 378 }
485 379 }