| @@ -737,8 +737,18 @@ | ||
| 737 | 737 | $where[] = 'cf_form_id = %d'; |
| 738 | 738 | $params[] = (int) $formId; |
| 739 | 739 | } |
| 740 | 740 | |
| 741 | + // Confirmed opt-ins whose follow-up actions failed or have an | |
| 742 | + // unknown outcome — the admin's "needs attention" list. | |
| 743 | + if ( sanitize_text_field( (string) ( $request->get_param( 'follow_up' ) ?? '' ) ) === 'problem' ) { | |
| 744 | + $followUpTable = $wpdb->prefix . \Forge12\DoubleOptIn\Repository\FollowUpSchema::TABLE_NAME; | |
| 745 | + $problems = \Forge12\DoubleOptIn\FollowUp\FollowUpStatus::problematic(); | |
| 746 | + $where[] = "EXISTS (SELECT 1 FROM {$followUpTable} fu WHERE fu.optin_id = {$table}.id AND fu.status IN (" | |
| 747 | + . implode( ', ', array_fill( 0, count( $problems ), '%s' ) ) . '))'; | |
| 748 | + $params = array_merge( $params, $problems ); | |
| 749 | + } | |
| 750 | + | |
| 741 | 751 | $whereClause = implode( ' AND ', $where ); |
| 742 | 752 | |
| 743 | 753 | // Count |
| 744 | 754 | $countQuery = "SELECT COUNT(*) FROM {$table} WHERE {$whereClause}"; |