'GET', 'callback' => [ $this, 'get_settings' ], 'permission_callback' => '__return_true', ] ); } /** * Get all plugin settings. * * @return WP_REST_Response */ public function get_settings() { global $wpdb; $provider = get_option( 'ai_search_provider', 'ai_service' ); // Count posts with embeddings $embedding_count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->postmeta} WHERE meta_key = '_ai_search_embedding'" ); // Get public post types $post_types = get_post_types( [ 'public' => true ], 'names' ); unset( $post_types['attachment'] ); // Get custom fields per post type $custom_fields = []; foreach ( $post_types as $post_type ) { $fields = get_option( 'ai_search_custom_fields_' . $post_type, [] ); if ( ! empty( $fields ) ) { $custom_fields[ $post_type ] = $fields; } } $settings = [ 'plugin_version' => AI_SEARCH_VERSION, 'wordpress_version' => get_bloginfo( 'version' ), 'php_version' => phpversion(), 'woocommerce_active' => class_exists( 'WooCommerce' ), 'provider' => $provider, 'has_api_key' => ! empty( get_option( 'ai_search_api_key', '' ) ), 'has_service_token' => ! empty( get_option( 'ai_search_service_token', '' ) ), 'openai_model' => get_option( 'ai_search_openai_model', 'text-embedding-3-small' ), 'similarity_threshold' => (float) get_option( 'ai_search_similarity_threshold', 0.30 ), 'badge_public' => (bool) get_option( 'ai_search_badge_public', false ), 'setup_completed' => (bool) get_option( 'ai_search_setup_completed', false ), 'woocommerce_fields' => get_option( 'ai_search_woocommerce_fields', [] ), 'custom_fields' => $custom_fields, 'total_embeddings' => $embedding_count, 'post_types' => array_values( $post_types ), ]; return rest_ensure_response( $settings ); } }