registry = $registry; } /** * Renders the widget content. * * Determines whether to show the getting-started checklist or * the full status view based on setup completion. * * @since 0.8.0 */ public function render(): void { $has_credentials = has_ai_credentials(); $feature_setting_enabled = $this->has_any_enabled_feature_setting(); if ( $has_credentials && $feature_setting_enabled ) { $this->render_status(); } else { $this->render_getting_started( $has_credentials, $feature_setting_enabled ); } } /** * Renders the getting-started checklist. * * @since 0.8.0 * * @param bool $has_credentials Whether any AI provider credentials are configured. * @param bool $feature_setting_enabled Whether at least one feature setting is enabled. */ private function render_getting_started( bool $has_credentials, bool $feature_setting_enabled ): void { $steps = array( array( 'done' => $has_credentials, 'label' => __( 'Configure an AI provider', 'ai' ), 'url' => admin_url( 'options-connectors.php' ), ), array( 'done' => $feature_setting_enabled, 'label' => __( 'Enable a feature or experiment', 'ai' ), 'url' => admin_url( 'options-general.php?page=ai-wp-admin' ), ), ); ?>

get_ai_connectors(); $stable_features = $this->registry->get_features_by_stability( 'stable' ); $experimental_features = $this->registry->get_features_by_stability( 'experimental' ); ?>

    render_feature_status_list( $stable_features, 'feature' ); ?>

    render_feature_status_list( $experimental_features, 'experiment' ); ?>
$features Registered features. * @param string $type Feature type, either 'feature' or 'experiment'. */ private function render_feature_status_list( array $features, string $type ): void { $enabled_features = array(); $disabled_features = array(); foreach ( $features as $feature ) { if ( $feature->is_enabled() ) { $enabled_features[] = $feature; } else { $disabled_features[] = $feature; } } $enabled_count = count( $enabled_features ); $disabled_count = count( $disabled_features ); if ( 'feature' === $type ) { /* translators: %d: Number of enabled features. */ $enabled_summary = _n( '%d feature enabled', '%d features enabled', $enabled_count, 'ai' ); /* translators: %d: Number of features that are not enabled. */ $disabled_summary = _n( '%d feature not enabled', '%d features not enabled', $disabled_count, 'ai' ); } else { /* translators: %d: Number of enabled experiments. */ $enabled_summary = _n( '%d experiment enabled', '%d experiments enabled', $enabled_count, 'ai' ); /* translators: %d: Number of experiments that are not enabled. */ $disabled_summary = _n( '%d experiment not enabled', '%d experiments not enabled', $disabled_count, 'ai' ); } if ( $enabled_count > 0 && $enabled_count <= 5 ) { foreach ( $enabled_features as $feature ) : ?>
  • get_label() ); ?>
  • 5 ) { ?>
  • Connector info. */ private function get_ai_connectors(): array { $connectors = array(); foreach ( get_ai_connectors() as $slug => $connector_data ) { $auth = $connector_data['authentication']; $configured = 'api_key' === $auth['method'] && is_connector_configured( $slug ); /** * Filters whether an AI connector is configured. * * Allows third-party plugins to declare credential availability for * connectors that do not rely on API key settings. * * The dynamic portion of the hook name, `$slug`, refers to the connector slug. * For example, if the connector slug is 'openai', the hook name * will be 'wpai_is_openai_connector_configured'. * * @since 0.9.0 * * @param bool $configured Whether the connector is configured. * @param array $connector_data The connector data. */ $configured = (bool) apply_filters( "wpai_is_{$slug}_connector_configured", $configured, $connector_data ); $connectors[] = array( 'name' => $connector_data['name'] ?? $slug, 'configured' => $configured, ); } return $connectors; } /** * Checks whether any registered feature has its individual setting enabled. * * @since 0.8.0 * * @return bool True if at least one feature setting is enabled. */ private function has_any_enabled_feature_setting(): bool { foreach ( $this->registry->get_all_features() as $feature ) { if ( $feature->is_individually_enabled() ) { return true; } } return false; } }