PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.9
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.9
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
wordpress-seo / src / integrations / admin / redirect-integration.php

redirect-integration.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.9, at src/integrations/admin/redirect-integration.php

106 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Integrations\Admin;
4
5 use Yoast\WP\SEO\Conditionals\Admin_Conditional;
6 use Yoast\WP\SEO\Helpers\Redirect_Helper;
7 use Yoast\WP\SEO\Helpers\Short_Link_Helper;
8 use Yoast\WP\SEO\Integrations\Integration_Interface;
9
10 /**
11 * Class Redirect_Integration.
12 */
13 class Redirect_Integration implements Integration_Interface {
14
15 /**
16 * The redirect helper.
17 *
18 * @var Redirect_Helper
19 */
20 private $redirect;
21
22 /**
23 * The short link helper.
24 *
25 * @var Short_Link_Helper
26 */
27 private $short_link_helper;
28
29 /**
30 * Sets the helpers.
31 *
32 * @param Redirect_Helper $redirect The redirect helper.
33 * @param Short_Link_Helper $short_link_helper The short link helper.
34 */
35 public function __construct(
36 Redirect_Helper $redirect,
37 Short_Link_Helper $short_link_helper
38 ) {
39 $this->redirect = $redirect;
40 $this->short_link_helper = $short_link_helper;
41 }
42
43 /**
44 * Returns the conditionals based in which this loadable should be active.
45 *
46 * @return array
47 */
48 public static function get_conditionals() {
49 return [ Admin_Conditional::class ];
50 }
51
52 /**
53 * Initializes the integration.
54 *
55 * This is the place to register hooks and filters.
56 *
57 * @return void
58 */
59 public function register_hooks() {
60 \add_action( 'wp_loaded', [ $this, 'settings_redirect' ] );
61 }
62
63 /**
64 * Catch all method to redirect certain pages related to redirects.
65 *
66 * @return void
67 */
68 public function settings_redirect() {
69 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
70 if ( ! isset( $_GET['page'] ) ) {
71 return;
72 }
73 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
74 $current_page = \sanitize_text_field( \wp_unslash( $_GET['page'] ) );
75
76 switch ( $current_page ) {
77 case 'wpseo_titles': // Redirect to new settings URLs. We're adding this, so that not-updated add-ons don't point to non-existent pages.
78 $this->redirect->do_safe_redirect( \admin_url( 'admin.php?page=wpseo_page_settings#/site-representation' ), 301 );
79 return;
80 case 'wpseo_redirects_tools': // Redirect to Yoast redirection page, from the respective WP tools page.
81 $this->redirect->do_safe_redirect( \admin_url( 'admin.php?page=wpseo_redirects&from_tools=1' ), 302 );
82 return;
83 case 'wpseo_brand_insights':
84 $this->redirect->do_unsafe_redirect( $this->short_link_helper->get( 'https://yoa.st/brand-insights-wp-admin' ), 302 );
85 return;
86 case 'wpseo_brand_insights_premium':
87 $this->redirect->do_unsafe_redirect( $this->short_link_helper->get( 'https://yoa.st/brand-insights-wp-admin-premium' ), 302 );
88 return;
89 default:
90 return;
91 }
92 }
93
94 /**
95 * Old method kept for backward compatibility.
96 *
97 * @deprecated 26.2
98 * @codeCoverageIgnore Because of deprecation.
99 * @return void
100 */
101 public function old_settings_redirect() {
102 \_deprecated_function( __METHOD__, 'Yoast SEO 26.2', 'Use settings_redirect() instead.' );
103 $this->settings_redirect();
104 }
105 }
106