label, in the order shown in the settings UI. * free_models: model slugs a Free site may pick. Empty list on a Pro-only * provider means "none on Free", which is implied anyway. * text_model: model used by Generate Prompt from Content, null when the * provider has no text endpoint. * * @return array */ public static function all() { return array( self::OPENAI => array( 'label' => 'OpenAI', 'key_option' => 'openai_api_key', 'premium' => false, 'default_model' => 'gpt-image-2', 'image_models' => array( 'gpt-image-2.6-flare' => 'GPT Image 2.6 Flare (Fast, Recommended)', 'gpt-image-2.6-sunburst' => 'GPT Image 2.6 Sunburst (Best Detail)', 'gpt-image-2' => 'GPT Image 2', ), 'free_models' => array( 'gpt-image-2' ), 'text_model' => 'gpt-6-luna', ), self::GEMINI => array( 'label' => 'Google Gemini', 'key_option' => 'gemini_api_key', 'premium' => true, 'default_model' => 'gemini-nano-banana-2.1', 'image_models' => array( 'gemini-nano-banana-2.1' => 'Nano Banana 2.1 (Gemini, fast)', 'gemini-3.1-flash-image' => 'Nano Banana 2 (Gemini 3.1 Flash, deprecated by Google)', 'gemini-3-pro-image' => 'Nano Banana Pro (Gemini 3 Pro)', 'gemini-3.1-flash-lite-image' => 'Nano Banana 2 Lite (fastest, lowest cost, 1K)', ), 'free_models' => array(), 'text_model' => 'gemini-3.6-flash', ), self::GROK => array( 'label' => 'Grok / xAI', 'key_option' => 'grok_api_key', 'premium' => false, 'default_model' => 'grok-imagine-image', 'image_models' => array( 'grok-imagine-image-2.0' => 'Grok Imagine Image 2.0 ($0.04/image)', 'grok-imagine-image' => 'Grok Imagine Image ($0.02/image)', ), 'free_models' => array( 'grok-imagine-image' ), 'text_model' => 'grok-4.7', ), self::MUSE => array( 'label' => 'Meta Muse', 'key_option' => 'muse_api_key', 'premium' => true, 'beta' => true, 'default_model' => 'muse-image-1.0', 'image_models' => array( 'muse-image-1.0' => 'Muse Image 1.0', ), 'free_models' => array(), 'text_model' => 'muse-spark-1.3', ), ); } /** * Whether this site can run Pro code. * * Needs both a Pro build (the Free zip has the Pro code stripped out) and * a license that allows Pro code. A Free zip with an active license is not * enough, since the Pro provider calls are missing from that build. * * @return bool */ public static function can_use_premium() { return function_exists( 'afig_fs' ) && afig_fs()->is__premium_only() && afig_fs()->can_use_premium_code(); } /** * @return string[] All provider slugs. */ public static function slugs() { return array_keys( self::all() ); } /** * Slugs this site may select: every Free provider, plus Pro ones on a Pro site. * * @return string[] */ public static function available_slugs() { return array_values( array_filter( self::slugs(), array( __CLASS__, 'is_available' ) ) ); } /** * @param string $slug Provider slug. * @return bool */ public static function is_registered( $slug ) { $all = self::all(); return is_string( $slug ) && isset( $all[ $slug ] ); } /** * @param string $slug Provider slug. * @return bool */ public static function is_premium( $slug ) { $all = self::all(); return isset( $all[ $slug ] ) && ! empty( $all[ $slug ]['premium'] ); } /** * Whether a provider is marked beta: offered, but not yet tried against a live key. * * @param string $slug Provider slug. * @return bool */ public static function is_beta( $slug ) { $all = self::all(); return isset( $all[ $slug ] ) && ! empty( $all[ $slug ]['beta'] ); } /** * Registered and not locked behind Pro on this site. * * @param string $slug Provider slug. * @return bool */ public static function is_available( $slug ) { if ( ! self::is_registered( $slug ) ) { return false; } return ! self::is_premium( $slug ) || self::can_use_premium(); } /** * Human label, falling back to the slug for anything unknown. * * @param string $slug Provider slug. * @return string */ public static function label( $slug ) { switch ( $slug ) { case self::OPENAI: return __( 'OpenAI', 'ai-featured-image-generator' ); case self::GEMINI: return __( 'Google Gemini', 'ai-featured-image-generator' ); case self::GROK: return __( 'Grok / xAI', 'ai-featured-image-generator' ); case self::MUSE: return __( 'Meta Muse', 'ai-featured-image-generator' ); } return (string) $slug; } /** * Settings key that holds this provider's API key. * * @param string $slug Provider slug. * @return string */ public static function key_option( $slug ) { $all = self::all(); return isset( $all[ $slug ] ) ? $all[ $slug ]['key_option'] : 'openai_api_key'; } /** * API key for a provider, honouring the legacy `api_key` value that older * installs still carry for OpenAI. * * @param array $settings Plugin settings. * @param string $slug Provider slug. * @return string Empty string when no key is stored. */ public static function get_api_key( $settings, $slug ) { $option = self::key_option( $slug ); if ( ! empty( $settings[ $option ] ) ) { return (string) $settings[ $option ]; } if ( $slug === self::OPENAI && ! empty( $settings['api_key'] ) ) { return (string) $settings['api_key']; } return ''; } /** * @param array $settings Plugin settings. * @param string $slug Provider slug. * @return bool */ public static function has_api_key( $settings, $slug ) { return self::get_api_key( $settings, $slug ) !== ''; } /** * Whether at least one usable provider has a key on this site. * * @param array $settings Plugin settings. * @return bool */ public static function has_any_api_key( $settings ) { foreach ( self::available_slugs() as $slug ) { if ( self::has_api_key( $settings, $slug ) ) { return true; } } return false; } /** * Image models for a provider as slug => label. * * @param string $slug Provider slug. * @param bool $free_only Limit to the models a Free site may use. * @return array */ public static function image_models( $slug, $free_only = false ) { $all = self::all(); if ( ! isset( $all[ $slug ] ) ) { return array(); } $models = $all[ $slug ]['image_models']; if ( $free_only ) { $models = array_intersect_key( $models, array_flip( $all[ $slug ]['free_models'] ) ); } return $models; } /** * Whether a model may be used with a provider on this site. * * @param string $slug Provider slug. * @param string $model Model slug. * @return bool */ public static function is_model_available( $slug, $model ) { if ( ! self::is_available( $slug ) ) { return false; } $models = self::image_models( $slug, ! self::can_use_premium() ); return is_string( $model ) && isset( $models[ $model ] ); } /** * @param string $slug Provider slug. * @return string */ public static function default_model( $slug ) { $all = self::all(); return isset( $all[ $slug ] ) ? $all[ $slug ]['default_model'] : 'gpt-image-2'; } /** * @param string $slug Provider slug. * @return string|null */ public static function text_model( $slug ) { $all = self::all(); return isset( $all[ $slug ] ) ? $all[ $slug ]['text_model'] : null; } }