| @@ -15,10 +15,8 @@ | ||
| 15 | 15 | use Forge12\DoubleOptIn\Events\Integration\FormSubmissionEvent; |
| 16 | 16 | use Forge12\DoubleOptIn\Events\Lifecycle\OptInConfirmedEvent; |
| 17 | 17 | use Forge12\DoubleOptIn\Events\Lifecycle\OptInCreatedEvent; |
| 18 | 18 | use Forge12\DoubleOptIn\Files\FileStorage; |
| 19 | -use Forge12\DoubleOptIn\FollowUp\FollowUpAttempt; | |
| 20 | -use Forge12\DoubleOptIn\FollowUp\FollowUpCoordinator; | |
| 21 | 19 | use Forge12\DoubleOptIn\Frontend\ErrorNotification; |
| 22 | 20 | use Forge12\DoubleOptIn\Service\RateLimiter; |
| 23 | 21 | use forge12\contactform7\CF7DoubleOptIn\CF7DoubleOptIn; |
| 24 | 22 | use forge12\contactform7\CF7DoubleOptIn\IPHelper; |
| @@ -83,47 +81,8 @@ | ||
| 83 | 81 | * Get the validation status from the last validateOptIn() call. |
| 84 | 82 | * |
| 85 | 83 | * @return string One of: '', 'confirmed', 'already_confirmed', 'expired', 'not_found'. |
| 86 | 84 | */ |
| 87 | - /** | |
| 88 | - * Nesting depth of post-confirmation replays in this request. | |
| 89 | - * | |
| 90 | - * @var int | |
| 91 | - */ | |
| 92 | - private static $replayDepth = 0; | |
| 93 | - | |
| 94 | - /** | |
| 95 | - * True while a post-confirmation replay (re-submitting the stored | |
| 96 | - * data to the form plugin) runs in this request. Set only by server | |
| 97 | - * code via {@see runAsReplay()} — never derived from request input. | |
| 98 | - * | |
| 99 | - * @since 5.6.0 | |
| 100 | - */ | |
| 101 | - public static function isReplaying(): bool { | |
| 102 | - return self::$replayDepth > 0; | |
| 103 | - } | |
| 104 | - | |
| 105 | - /** | |
| 106 | - * Run $fn as a post-confirmation replay: form-submit hooks that fire | |
| 107 | - * inside it (wpcf7_before_send_mail, gform_after_submission, …) see | |
| 108 | - * {@see isReplaying()} and do not create a new opt-in. | |
| 109 | - * | |
| 110 | - * @template T | |
| 111 | - * @param callable():T $fn | |
| 112 | - * | |
| 113 | - * @return T | |
| 114 | - * | |
| 115 | - * @since 5.6.0 | |
| 116 | - */ | |
| 117 | - public static function runAsReplay( callable $fn ) { | |
| 118 | - self::$replayDepth++; | |
| 119 | - try { | |
| 120 | - return $fn(); | |
| 121 | - } finally { | |
| 122 | - self::$replayDepth--; | |
| 123 | - } | |
| 124 | - } | |
| 125 | - | |
| 126 | 85 | public static function getValidationStatus(): string { |
| 127 | 86 | return self::$validationStatus; |
| 128 | 87 | } |
| 129 | 88 | |
| @@ -212,19 +171,12 @@ | ||
| 212 | 171 | /** |
| 213 | 172 | * {@inheritdoc} |
| 214 | 173 | */ |
| 215 | 174 | public function isOptInEnabled( int $formId ): bool { |
| 216 | - // Disable while our own post-confirmation replay runs — the stored | |
| 217 | - // submission must be processed, not turned into a new opt-in. | |
| 218 | - // | |
| 219 | - // This used to test `isset( $_GET['optin'] )`. That flag is set by | |
| 220 | - // whoever sends the request: `…/feedback?optin=1` on the CF7 REST | |
| 221 | - // route submitted a DOI form with every mail and no confirmation. | |
| 222 | - // It also broke every replay outside the confirmation request | |
| 223 | - // (cron, admin retry), which has no `?optin` in its URL. | |
| 224 | - if ( self::isReplaying() ) { | |
| 175 | + // Disable if opt-in confirmation is in progress | |
| 176 | + if ( isset( $_GET['optin'] ) ) { | |
| 225 | 177 | $this->getLogger()->debug( |
| 226 | - 'Opt-in disabled during post-confirmation replay', | |
| 178 | + 'Opt-in disabled due to optin flag in GET request', | |
| 227 | 179 | array( |
| 228 | 180 | 'plugin' => 'double-opt-in', |
| 229 | 181 | 'class' => static::class, |
| 230 | 182 | ) |
| @@ -1079,24 +1031,8 @@ | ||
| 1079 | 1031 | self::setValidationStatus( 'already_confirmed' ); |
| 1080 | 1032 | return false; |
| 1081 | 1033 | } |
| 1082 | 1034 | |
| 1083 | - /** | |
| 1084 | - * Enable / Disable default mail. | |
| 1085 | - * | |
| 1086 | - * @param bool $status Enable (true) or disable (false) the default mail. | |
| 1087 | - * @param int $postId The ID of the Post / Form. | |
| 1088 | - * | |
| 1089 | - * @since 2.3.3 | |
| 1090 | - */ | |
| 1091 | - $sendDefaultMail = (bool) apply_filters( 'f12_cf7_doubleoptin_send_default_mail', true, $optIn->get_cf_form_id() ); | |
| 1092 | - | |
| 1093 | - // Bind the follow-up plan BEFORE the confirmation is saved, so a | |
| 1094 | - // request that dies in between leaves rows the sweep can finish. | |
| 1095 | - // False = no adapter for this integration → previous behaviour. | |
| 1096 | - $coordinator = FollowUpCoordinator::instance(); | |
| 1097 | - $managed = $coordinator !== null && $coordinator->plan( $optIn, $sendDefaultMail ); | |
| 1098 | - | |
| 1099 | 1035 | // Confirm the opt-in |
| 1100 | 1036 | do_action( 'f12_cf7_doubleoptin_before_confirm', $hash, $optIn ); |
| 1101 | 1037 | |
| 1102 | 1038 | $optIn->set_doubleoptin( 1 ); |
| @@ -1122,32 +1058,16 @@ | ||
| 1122 | 1058 | |
| 1123 | 1059 | // Dispatch event |
| 1124 | 1060 | $this->dispatchOptInConfirmedEvent( $optIn, $hash ); |
| 1125 | 1061 | |
| 1126 | - // Everything from here on re-processes the stored submission. | |
| 1127 | - self::runAsReplay( | |
| 1128 | - function () use ( $hash, $optIn, $managed, $coordinator, $sendDefaultMail ) { | |
| 1129 | - do_action( 'f12_cf7_doubleoptin_after_confirm', $hash, $optIn ); | |
| 1062 | + do_action( 'f12_cf7_doubleoptin_after_confirm', $hash, $optIn ); | |
| 1130 | 1063 | |
| 1131 | - if ( $managed ) { | |
| 1132 | - // The coordinator runs every planned action — entry and | |
| 1133 | - // mail — and records a result per action. The before/after | |
| 1134 | - // hooks keep firing for listeners that depend on them. | |
| 1135 | - if ( $sendDefaultMail ) { | |
| 1136 | - do_action( 'f12_cf7_doubleoptin_before_send_default_mail', $optIn ); | |
| 1137 | - } | |
| 1138 | - $coordinator->run( $optIn, FollowUpAttempt::TRIGGER_CONFIRM ); | |
| 1139 | - if ( $sendDefaultMail ) { | |
| 1140 | - do_action( 'f12_cf7_doubleoptin_after_send_default_mail', $optIn ); | |
| 1141 | - } | |
| 1142 | - } elseif ( $sendDefaultMail ) { | |
| 1143 | - // Send the original mail if enabled | |
| 1144 | - do_action( 'f12_cf7_doubleoptin_before_send_default_mail', $optIn ); | |
| 1145 | - $this->sendConfirmationMail( $optIn ); | |
| 1146 | - do_action( 'f12_cf7_doubleoptin_after_send_default_mail', $optIn ); | |
| 1147 | - } | |
| 1148 | - } | |
| 1149 | - ); | |
| 1064 | + // Send the original mail if enabled | |
| 1065 | + if ( apply_filters( 'f12_cf7_doubleoptin_send_default_mail', true, $optIn->get_cf_form_id() ) ) { | |
| 1066 | + do_action( 'f12_cf7_doubleoptin_before_send_default_mail', $optIn ); | |
| 1067 | + $this->sendConfirmationMail( $optIn ); | |
| 1068 | + do_action( 'f12_cf7_doubleoptin_after_send_default_mail', $optIn ); | |
| 1069 | + } | |
| 1150 | 1070 | |
| 1151 | 1071 | $this->getLogger()->info( |
| 1152 | 1072 | 'OptIn confirmed successfully', |
| 1153 | 1073 | array( |