| 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 |
// The bulk editor moved from the Tools page to its own page. Redirect the legacy deep link, keying on the tool because wpseo_tools is still a live page. |
| 77 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. |
| 78 |
$current_tool = ( isset( $_GET['tool'] ) && \is_string( $_GET['tool'] ) ) ? \sanitize_text_field( \wp_unslash( $_GET['tool'] ) ) : ''; |
| 79 |
if ( $current_page === 'wpseo_tools' && $current_tool === 'bulk-editor' ) { |
| 80 |
$this->redirect->do_safe_redirect( \admin_url( 'admin.php?page=wpseo_page_bulk_edit' ), 301 ); |
| 81 |
return; |
| 82 |
} |
| 83 |
|
| 84 |
switch ( $current_page ) { |
| 85 |
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. |
| 86 |
$this->redirect->do_safe_redirect( \admin_url( 'admin.php?page=wpseo_page_settings#/site-representation' ), 301 ); |
| 87 |
return; |
| 88 |
case 'wpseo_redirects_tools': // Redirect to Yoast redirection page, from the respective WP tools page. |
| 89 |
$this->redirect->do_safe_redirect( \admin_url( 'admin.php?page=wpseo_redirects&from_tools=1' ), 302 ); |
| 90 |
return; |
| 91 |
case 'wpseo_brand_insights': |
| 92 |
$this->redirect->do_unsafe_redirect( $this->short_link_helper->get( 'https://yoa.st/brand-insights-wp-admin' ), 302 ); |
| 93 |
return; |
| 94 |
case 'wpseo_brand_insights_premium': |
| 95 |
$this->redirect->do_unsafe_redirect( $this->short_link_helper->get( 'https://yoa.st/brand-insights-wp-admin-premium' ), 302 ); |
| 96 |
return; |
| 97 |
default: |
| 98 |
return; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Old method kept for backward compatibility. |
| 104 |
* |
| 105 |
* @deprecated 26.2 |
| 106 |
* @codeCoverageIgnore Because of deprecation. |
| 107 |
* @return void |
| 108 |
*/ |
| 109 |
public function old_settings_redirect() { |
| 110 |
\_deprecated_function( __METHOD__, 'Yoast SEO 26.2', 'Use settings_redirect() instead.' ); |
| 111 |
$this->settings_redirect(); |
| 112 |
} |
| 113 |
} |
| 114 |
|