settings->is_enabled() ) { return; } $threshold = (int) $this->settings->get( 'alert_threshold_pct', 80 ); $messages = array(); // Check global daily. $daily_pct = $this->usage_tracker->global_daily_pct(); if ( $daily_pct >= 100 ) { $messages[] = sprintf( /* translators: %s: percentage */ __( 'AI Valve: Global daily token budget exceeded (%s%% used). New AI requests are being blocked.', 'ai-valve' ), number_format_i18n( (int) $daily_pct ) ); $this->maybe_send_email( 'daily', $daily_pct ); } elseif ( $daily_pct >= $threshold ) { $messages[] = sprintf( /* translators: %s: percentage */ __( 'AI Valve: Global daily token usage at %s%% of budget.', 'ai-valve' ), number_format_i18n( (int) $daily_pct ) ); } // Check global monthly. $monthly_pct = $this->usage_tracker->global_monthly_pct(); if ( $monthly_pct >= 100 ) { $messages[] = sprintf( /* translators: %s: percentage */ __( 'AI Valve: Global monthly token budget exceeded (%s%% used). New AI requests are being blocked.', 'ai-valve' ), number_format_i18n( (int) $monthly_pct ) ); $this->maybe_send_email( 'monthly', $monthly_pct ); } elseif ( $monthly_pct >= $threshold ) { $messages[] = sprintf( /* translators: %s: percentage */ __( 'AI Valve: Global monthly token usage at %s%% of budget.', 'ai-valve' ), number_format_i18n( (int) $monthly_pct ) ); } // Check per-plugin budgets. $plugin_budgets = (array) $this->settings->get( 'plugin_budgets', array() ); foreach ( $plugin_budgets as $slug => $limits ) { $slug = (string) $slug; $p_daily_pct = $this->usage_tracker->plugin_daily_pct( $slug ); if ( $p_daily_pct >= 100 ) { $messages[] = sprintf( /* translators: 1: plugin slug 2: percentage */ __( 'AI Valve: %1$s daily token budget exceeded (%2$s%% used).', 'ai-valve' ), '' . esc_html( $slug ) . '', number_format_i18n( (int) $p_daily_pct ) ); } elseif ( $p_daily_pct >= $threshold ) { $messages[] = sprintf( /* translators: 1: plugin slug 2: percentage */ __( 'AI Valve: %1$s daily token usage at %2$s%% of budget.', 'ai-valve' ), '' . esc_html( $slug ) . '', number_format_i18n( (int) $p_daily_pct ) ); } $p_monthly_pct = $this->usage_tracker->plugin_monthly_pct( $slug ); if ( $p_monthly_pct >= 100 ) { $messages[] = sprintf( /* translators: 1: plugin slug 2: percentage */ __( 'AI Valve: %1$s monthly token budget exceeded (%2$s%% used).', 'ai-valve' ), '' . esc_html( $slug ) . '', number_format_i18n( (int) $p_monthly_pct ) ); } elseif ( $p_monthly_pct >= $threshold ) { $messages[] = sprintf( /* translators: 1: plugin slug 2: percentage */ __( 'AI Valve: %1$s monthly token usage at %2$s%% of budget.', 'ai-valve' ), '' . esc_html( $slug ) . '', number_format_i18n( (int) $p_monthly_pct ) ); } } foreach ( $messages as $msg ) { $type = str_contains( $msg, 'exceeded' ) ? 'error' : 'warning'; printf( '
%s
| ' . esc_html__( 'Today', 'ai-valve' ) . ' | '; echo esc_html( number_format_i18n( $daily ) ); if ( $daily_limit > 0 ) { echo ' / ' . esc_html( number_format_i18n( $daily_limit ) ); $this->render_progress_bar( $daily, $daily_limit ); } echo ' |
|---|---|
| ' . esc_html__( 'This month', 'ai-valve' ) . ' | '; echo esc_html( number_format_i18n( $monthly ) ); if ( $monthly_limit > 0 ) { echo ' / ' . esc_html( number_format_i18n( $monthly_limit ) ); $this->render_progress_bar( $monthly, $monthly_limit ); } echo ' |