is_pro_active() ) { return; } // Determine menu label based on sale status. $menu_label = __( 'Upgrade to Pro', 'accessibility-checker' ); if ( $this->is_sale_time() ) { $menu_label = __( 'Upgrade Sale Now', 'accessibility-checker' ); } add_submenu_page( 'accessibility_checker', '', $menu_label, $required_capability, 'accessibility_checker_upgrade', [ $this, 'dummy_page_callback' ] ); } /** * Dummy page callback (redirect happens in admin_init). * * @since 1.27.0 * * @return void */ public function dummy_page_callback(): void { // This should never be reached due to redirect in admin_init. wp_die( esc_html__( 'Unable to redirect to upgrade page.', 'accessibility-checker' ) ); } /** * Check if we should handle redirect and do it early. * * @since 1.27.0 * * @return void */ public function maybe_handle_redirect(): void { // Check if we're on the upgrade page. if ( ! isset( $_GET['page'] ) || 'accessibility_checker_upgrade' !== $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This is a simple page check for redirect, no form processing. return; } $required_capability = apply_filters( 'edac_filter_settings_capability', 'manage_options' ); // Only redirect if user has capability and pro is not active. if ( ! current_user_can( $required_capability ) || $this->is_pro_active() ) { return; } $upgrade_url = edac_link_wrapper( self::UPGRADE_URL, 'admin-menu-promotion', 'menu-upgrade-to-pro', false ); // Add the domain to allowed hosts before redirecting. add_filter( 'allowed_redirect_hosts', [ $this, 'allow_redirect_host' ] ); if ( wp_safe_redirect( $upgrade_url ) ) { exit; } } /** * Allow redirects to the Equalize Digital domain. * * @since 1.27.0 * * @param array $hosts Array of allowed hosts. * @return array Modified array of allowed hosts. */ public function allow_redirect_host( array $hosts ): array { $hosts[] = 'equalizedigital.com'; return $hosts; } /** * Add CSS styling to make the upgrade menu item stand out. * * @since 1.27.0 * * @return void */ public function add_menu_styling(): void { // Only add styling on accessibility checker admin pages. $screen = get_current_screen(); if ( ! $screen || false === strpos( $screen->id, 'accessibility_checker' ) ) { return; } $required_capability = apply_filters( 'edac_filter_settings_capability', 'manage_options' ); // Only add styling if user can see the menu and pro is not active. if ( ! current_user_can( $required_capability ) ) { return; } if ( $this->is_pro_active() ) { return; } ?>