current_page_helper = $current_page_helper; $this->redirect_helper = $redirect_helper; $this->site_kit_configuration = $site_kit_configuration; } /** * The conditions for this integration to load. * * @return string[] The conditionals. */ public static function get_conditionals() { return [ Admin_Conditional::class ]; } /** * Registers the interceptor code to the admin_init function. * * @return void */ public function register_hooks() { \add_filter( 'admin_menu', [ $this, 'add_redirect_page' ] ); \add_action( 'admin_init', [ $this, 'intercept_site_kit_setup_url_redirect' ], 1 ); } /** * Adds a dummy page. * * We need to register this in between page. * * @param array> $pages The pages. * * @return array> The pages. */ public function add_redirect_page( $pages ) { \add_submenu_page( 'options.php', '', '', 'wpseo_manage_options', self::PAGE, ); return $pages; } /** * Checks if we are trying to reach a site kit setup url and sets the needed transient in between. * * @return void */ public function intercept_site_kit_setup_url_redirect() { $allowed_setup_links = [ $this->site_kit_configuration->get_install_url(), $this->site_kit_configuration->get_activate_url(), $this->site_kit_configuration->get_setup_url(), $this->site_kit_configuration->get_update_url(), ]; // Are we on the in-between page? if ( $this->current_page_helper->get_current_yoast_seo_page() === self::PAGE ) { // Check if parameter is there and is valid. // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['redirect_setup_url'] ) && \in_array( \wp_unslash( $_GET['redirect_setup_url'] ), $allowed_setup_links, true ) ) { // We overwrite the transient for each time this redirect is hit to keep refreshing the time. \set_transient( self::SITE_KIT_SETUP_TRANSIENT, 1, ( \MINUTE_IN_SECONDS * 15 ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: Only allowed pre verified links can end up here. $redirect_url = \wp_unslash( $_GET['redirect_setup_url'] ); $this->redirect_helper->do_safe_redirect( $redirect_url, 302, 'Yoast SEO' ); } else { $this->redirect_helper->do_safe_redirect( \self_admin_url( 'admin.php?page=wpseo_dashboard' ), 302, 'Yoast SEO' ); } } } }