id. * @param string $tab The WooCommerce settings tab in the URL, or ''. */ public static function of( string $screen_id, string $tab ): string { if ( 'woocommerce_page_wc-settings' === $screen_id && 'fitzaro' === $tab ) { return self::SETTINGS; } if ( 'plugins' === $screen_id && '' === $tab ) { return self::PLUGINS; } return self::NONE; } /** * Whether the one-time setup notice is shown. * * @param string $place Result of of(). * @param bool $pending The activation flag is still set. * @param bool $setup_needed Only the owner's own setup (the AI key) is missing. */ public static function show_setup( string $place, bool $pending, bool $setup_needed ): bool { return self::PLUGINS === $place && $pending && $setup_needed; } /** * The place of the current admin screen. */ public static function current(): string { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( null === $screen ) { return self::NONE; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only reads which settings tab is shown. $tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : ''; return self::of( (string) $screen->id, $tab ); } /** * Called on activation: the next visit to the Plugins screen may show the setup notice. */ public static function arm(): void { update_option( self::SETUP_OPTION, '1', false ); } /** * The one-time "finish setting up" notice on the Plugins screen. */ public static function render_setup(): void { if ( ! current_user_can( 'manage_woocommerce' ) || self::PLUGINS !== self::current() || '1' !== get_option( self::SETUP_OPTION ) ) { return; } if ( ! SystemCheck::only_setup_left( SystemCheck::problems() ) ) { // Set up already (or a server problem, which the settings tab explains): never show it again. delete_option( self::SETUP_OPTION ); return; } $dismiss = wp_nonce_url( admin_url( 'admin-post.php?action=' . self::DISMISS_ACTION ), self::DISMISS_ACTION ); echo '
' . esc_html__( 'Finish setting up Fitzaro', 'fitzaro' ) . ' ' . esc_html__( 'Add your OpenAI API key to show the Try it on button on product pages.', 'fitzaro' ) . ' ' . esc_html__( 'Open Fitzaro settings', 'fitzaro' ) . '' . ' | ' . esc_html__( 'Dismiss', 'fitzaro' ) . '