has_sdk = $has_sdk ?? static fn (): bool => function_exists( 'adaf_fs' ); } /** * Hook registration. After AdminPage's default priority, so the parent * menu exists. */ public function register(): void { add_action( 'admin_menu', array( $this, 'register_menu' ), 20 ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_new_tab_script' ) ); } /** * Add the Upgrade item, unless Freemius provides its own. */ public function register_menu(): void { if ( ( $this->has_sdk )() ) { return; } // Last, after the sections (AdminPage, default priority): the first // of them is the parent's own page, so the top-level link stays home. $upgrade = __( 'Upgrade', 'agentic-daisy-ai-agent-firewall' ); add_submenu_page( AdminPage::SLUG, $upgrade, $upgrade . ' ' . esc_html__( '(opens in a new tab)', 'agentic-daisy-ai-agent-firewall' ) . '', 'manage_options', self::PRICING_URL ); } /** * Open the Upgrade item in a new tab. WordPress gives a menu item no * target, so a few lines of script set one, on every admin screen the * menu appears on: the link leaves wp-admin for the pricing page, and * taking over the tab would drop the admin out of their dashboard. * Without the SDK only; Freemius's own item stays inside wp-admin. */ public function enqueue_new_tab_script(): void { if ( ( $this->has_sdk )() ) { return; } wp_register_script( self::SCRIPT_HANDLE, false, array(), ADAF_VERSION, true ); wp_enqueue_script( self::SCRIPT_HANDLE ); wp_add_inline_script( self::SCRIPT_HANDLE, sprintf( 'document.querySelectorAll( "#adminmenu a[href=\\"" + %s + "\\"]" ).forEach( function ( link ) { link.target = "_blank"; link.rel = "noopener noreferrer"; } );', (string) wp_json_encode( self::PRICING_URL ) ) ); } }