PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 5.5.0
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v5.5.0
5.12.0 5.13.0 5.13.1 5.11.0 5.10.0 5.9.0 5.8.0 5.8.1 5.7.0 5.6.2 5.6.3 5.6.1 5.6.0 5.5.0 5.4.0 5.3.2 5.3.1 5.1.6 5.1.5 trunk 2.1.5 2.11 2.12 2.13 2.15 All 47 releases
← All changes | src/Admin/ResendController.php +62 -26 5.8.1 → 5.5.0 View file →
@@ -8,10 +8,9 @@
8 8
9 9 namespace Forge12\DoubleOptIn\Admin;
10 10
11 11 use Forge12\DoubleOptIn\Container\Container;
12 -use Forge12\DoubleOptIn\Service\ConfirmationMailResender;
13 -use Forge12\DoubleOptIn\Service\ResendResult;
12 +use Forge12\DoubleOptIn\Repository\OptInRepositoryInterface;
14 13 use Forge12\Shared\LoggerInterface;
15 14
16 15 if ( ! defined( 'ABSPATH' ) ) {
17 16 exit;
@@ -40,12 +39,12 @@
40 39 *
41 40 * @return void
42 41 */
43 42 public function renderResendButton( $optin ): void {
44 - // Free since 5.8, like the resend in the SPA: no licence check.
43 + $is_pro = apply_filters( 'f12_doi_is_pro_active', false );
45 44 $is_confirmed = $optin->is_confirmed();
46 45 $has_mail = ! empty( $optin->get_mail_optin() );
47 - $disabled = $is_confirmed || ! $has_mail;
46 + $disabled = ! $is_pro || $is_confirmed || ! $has_mail;
48 47
49 48 $nonce = wp_create_nonce( 'doi_resend_mail' );
50 49 $id = $optin->get_id();
51 50
@@ -50,9 +49,11 @@
50 49 $id = $optin->get_id();
51 50
52 51 // Build tooltip explaining why the button is disabled
53 52 $title = '';
54 - if ( $is_confirmed ) {
53 + if ( ! $is_pro ) {
54 + $title = __( 'This feature is available in the Pro version.', 'double-opt-in' );
55 + } elseif ( $is_confirmed ) {
55 56 $title = __( 'This Opt-In has already been confirmed.', 'double-opt-in' );
56 57 } elseif ( ! $has_mail ) {
57 58 $title = __( 'No mail body stored for this Opt-In.', 'double-opt-in' );
58 59 }
@@ -68,8 +69,14 @@
68 69 <?php
69 70 _e( 'Resend Confirmation Mail', 'double-opt-in' );
70 71 ?>
71 72 </button>
73 + <?php
74 + if ( ! $is_pro ) :
75 + ?>
76 + <span style="display:inline-block;background:linear-gradient(135deg,#e6a817,#d4941a);color:#fff;font-size:10px;font-weight:700;line-height:1;padding:3px 6px;border-radius:3px;letter-spacing:.5px;text-transform:uppercase;"
77 + title="<?php esc_attr_e( 'This feature is available in the Pro version.', 'double-opt-in' ); ?>">PRO</span>
78 + <?php endif; ?>
72 79 <span class="doi-tooltip">
73 80 <span class="dashicons dashicons-info-outline"></span>
74 81 <span class="doi-tooltip-text">
75 82 <?php
@@ -77,9 +84,9 @@
77 84 ?>
78 85 </span>
79 86 </span>
80 87 <span id="doi-resend-feedback" style="font-size:13px;"></span>
81 - <?php if ( ! $disabled ) : ?>
88 + <?php if ( $is_pro && ! $disabled ) : ?>
82 89 <script>
83 90 (function() {
84 91 var btn = document.getElementById('doi-resend-btn');
85 92 var feedback = document.getElementById('doi-resend-feedback');
@@ -130,8 +137,12 @@
130 137 *
131 138 * @return void
132 139 */
133 140 public function handleResend(): void {
141 + if ( ! apply_filters( 'f12_doi_is_pro_active', false ) ) {
142 + wp_send_json_error( array( 'message' => __( 'This feature requires the Pro version.', 'double-opt-in' ) ), 403 );
143 + }
144 +
134 145 if ( ! current_user_can( 'manage_options' ) ) {
135 146 wp_send_json_error( array( 'message' => __( 'You do not have permission to perform this action.', 'double-opt-in' ) ), 403 );
136 147 }
137 148
@@ -145,9 +156,11 @@
145 156 wp_send_json_error( array( 'message' => __( 'Invalid Opt-In ID.', 'double-opt-in' ) ) );
146 157 }
147 158
148 159 try {
149 - $outcome = Container::getInstance()->get( ConfirmationMailResender::class )->resend( $optinId );
160 + $container = Container::getInstance();
161 + $repository = $container->get( OptInRepositoryInterface::class );
162 + $entity = $repository->findById( $optinId );
150 163 } catch ( \Exception $e ) {
151 164 $this->logger->error(
152 165 'Failed to load OptIn for resend',
153 166 array(
@@ -158,41 +171,64 @@
158 171 );
159 172 wp_send_json_error( array( 'message' => __( 'Failed to load Opt-In.', 'double-opt-in' ) ) );
160 173 }
161 174
162 - if ( $outcome->isSent() ) {
175 + if ( ! $entity ) {
176 + wp_send_json_error( array( 'message' => __( 'Opt-In not found.', 'double-opt-in' ) ) );
177 + }
178 +
179 + if ( $entity->isConfirmed() ) {
180 + wp_send_json_error( array( 'message' => __( 'This Opt-In is already confirmed.', 'double-opt-in' ) ) );
181 + }
182 +
183 + $body = $entity->getMailOptIn();
184 + if ( empty( $body ) ) {
185 + wp_send_json_error( array( 'message' => __( 'No mail body stored for this Opt-In.', 'double-opt-in' ) ) );
186 + }
187 +
188 + $email = $entity->getEmail();
189 + if ( empty( $email ) ) {
190 + wp_send_json_error( array( 'message' => __( 'No recipient email found.', 'double-opt-in' ) ) );
191 + }
192 +
193 + // Load subject from form settings with fallback
194 + $formId = $entity->getFormId();
195 + $formParameter = \forge12\contactform7\CF7DoubleOptIn\CF7DoubleOptIn::getInstance()->getParameter( $formId );
196 + $subject = ! empty( $formParameter['subject'] )
197 + ? $formParameter['subject']
198 + : __( 'Please confirm your opt-in', 'double-opt-in' );
199 +
200 + $headers = array( 'Content-Type: text/html; charset=UTF-8' );
201 +
202 + if ( ! empty( $formParameter['sender'] ) ) {
203 + if ( ! empty( $formParameter['sender_name'] ) ) {
204 + $headers[] = 'From: ' . $formParameter['sender_name'] . ' <' . $formParameter['sender'] . '>';
205 + } else {
206 + $headers[] = 'From: ' . $formParameter['sender'];
207 + }
208 + }
209 +
210 + $sent = wp_mail( $email, $subject, $body, $headers );
211 +
212 + if ( $sent ) {
163 213 $this->logger->info(
164 214 'Confirmation mail resent',
165 215 array(
166 216 'plugin' => 'double-opt-in',
167 217 'optin_id' => $optinId,
218 + 'email' => $email,
168 219 )
169 220 );
170 221 wp_send_json_success( array( 'message' => __( 'Confirmation mail has been resent.', 'double-opt-in' ) ) );
171 - }
172 -
173 - $messages = array(
174 - ResendResult::NOT_FOUND => __( 'Opt-In not found.', 'double-opt-in' ),
175 - ResendResult::CONFIRMED => __( 'This Opt-In is already confirmed.', 'double-opt-in' ),
176 - ResendResult::OPTED_OUT => __( 'This contact has opted out. The confirmation email is not sent again.', 'double-opt-in' ),
177 - ResendResult::NO_BODY => __( 'No mail body stored for this Opt-In.', 'double-opt-in' ),
178 - ResendResult::NO_RECIPIENT => __( 'No recipient email found.', 'double-opt-in' ),
179 - );
180 -
181 - if ( $outcome->getReason() === ResendResult::SEND_FAILED ) {
222 + } else {
182 223 $this->logger->error(
183 224 'Failed to resend confirmation mail',
184 225 array(
185 226 'plugin' => 'double-opt-in',
186 227 'optin_id' => $optinId,
228 + 'email' => $email,
187 229 )
188 230 );
231 + wp_send_json_error( array( 'message' => __( 'Failed to send mail. Please check your mail configuration.', 'double-opt-in' ) ) );
189 232 }
190 -
191 - wp_send_json_error(
192 - array(
193 - 'message' => $messages[ $outcome->getReason() ]
194 - ?? __( 'Failed to send mail. Please check your mail configuration.', 'double-opt-in' ),
195 - )
196 - );
197 233 }
198 234 }