email_queue ) && wpfval( $_POST, 'wpforo_email_queue_action' ) && wp_verify_nonce( wpfval( $_POST, '_wpnonce' ), 'wpforo_email_queue' ) ) { $action = sanitize_text_field( $_POST['wpforo_email_queue_action'] ); $ids = isset( $_POST['email_ids'] ) ? array_map( 'intval', (array) $_POST['email_ids'] ) : []; switch( $action ) { case 'retry': if( ! empty( $ids ) ) { $count = WPF()->email_queue->retry_failed( $ids ); WPF()->notice->add( sprintf( __( '%d email(s) queued for retry', 'wpforo' ), $count ), 'success' ); } break; case 'delete': if( ! empty( $ids ) ) { $count = WPF()->email_queue->delete_items( $ids ); WPF()->notice->add( sprintf( __( '%d email(s) deleted', 'wpforo' ), $count ), 'success' ); } break; case 'process_now': $processed = WPF()->email_queue->process_batch(); WPF()->notice->add( sprintf( __( '%d email(s) processed', 'wpforo' ), $processed ), 'success' ); break; case 'clear_history': $deleted = WPF()->email_queue->clear_sent_history(); WPF()->notice->add( sprintf( __( '%d sent email(s) cleared from history', 'wpforo' ), $deleted ), 'success' ); break; case 'retry_all': $failed_items = WPF()->email_queue->get_queue_items( 'failed', 1, 1000 ); if( ! empty( $failed_items['items'] ) ) { $ids = wp_list_pluck( $failed_items['items'], 'id' ); $count = WPF()->email_queue->retry_failed( $ids ); WPF()->notice->add( sprintf( __( '%d failed email(s) queued for retry', 'wpforo' ), $count ), 'success' ); } break; } } // Self-heal check - process stalled queue if needed $self_healed = 0; if( isset( WPF()->email_queue ) ) { $self_healed = WPF()->email_queue->maybe_process_stalled_queue(); if( $self_healed > 0 ) { WPF()->notice->add( sprintf( __( 'Self-healed: processed %d stalled email(s)', 'wpforo' ), $self_healed ), 'success' ); } } // Get current data $stats = isset( WPF()->email_queue ) ? WPF()->email_queue->get_stats() : []; $view = sanitize_text_field( wpfval( $_GET, 'view' ) ?: 'pending' ); $page = max( 1, intval( wpfval( $_GET, 'paged' ) ?: 1 ) ); $per_page = 20; $queue_data = isset( WPF()->email_queue ) ? WPF()->email_queue->get_queue_items( $view, $page, $per_page ) : [ 'items' => [], 'total' => 0, 'total_pages' => 0 ]; $cron_status = $stats['cron'] ?? []; ?>