PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.15
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.15
6.2.15 6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 All 197 releases
← All changes | app/Services/Scheduler/Scheduler.php +114 -23 3.6.40 → 6.2.15 View file →
@@ -1,10 +1,12 @@
1 1 <?php
2 2
3 3 namespace FluentForm\App\Services\Scheduler;
4 4
5 +use FluentForm\App\Models\FormAnalytics;
6 +use FluentForm\App\Models\Submission;
7 +use FluentForm\App\Modules\Payments\PaymentHelper;
5 8 use FluentForm\App\Services\Emogrifier\Emogrifier;
6 -use FluentForm\View;
7 9
8 10 class Scheduler
9 11 {
10 12 public static function processEmailReport()
@@ -21,8 +23,10 @@
21 23 $settings = wp_parse_args($settings, $defaults);
22 24 } else {
23 25 $settings = $defaults;
24 26 }
27 + $settings = apply_filters('fluentform/email_summary_settings', $settings);
28 +
25 29 if($settings['status'] == 'no') {
26 30 return;
27 31 }
28 32
@@ -27,13 +31,23 @@
27 31 }
28 32
29 33 $currentDay = date('D');
30 34 $reportingDay = $settings['sending_day'];
35 +
36 + $config = apply_filters_deprecated(
37 + 'fluentform_email_summary_config',
38 + [
39 + [
40 + 'status' => $currentDay == $reportingDay,
41 + 'days' => 7
42 + ]
43 + ],
44 + FLUENTFORM_FRAMEWORK_UPGRADE,
45 + 'fluentform/email_summary_config',
46 + 'Use fluentform/email_summary_config instead of fluentform_email_summary_config.'
47 + );
31 48
32 - $config = apply_filters('fluentform_email_summary_config', [
33 - 'status' => $currentDay == $reportingDay,
34 - 'days' => 7
35 - ]);
49 + $config = apply_filters('fluentform/email_summary_config', $config);
36 50
37 51 if (!$config['status']) {
38 52 return;
39 53 }
@@ -66,10 +80,9 @@
66 80 $days = 7;
67 81 }
68 82
69 83 $reportDateFrom = date('Y-m-d', time() - $days * 86400); // 7 days
70 - $submissionCounts = wpFluent()->table('fluentform_submissions')
71 - ->select([
84 + $submissionCounts = Submission::select([
72 85 wpFluent()->raw("COUNT({$wpdb->prefix}fluentform_submissions.id) as total"),
73 86 'fluentform_submissions.form_id',
74 87 'fluentform_forms.title'
75 88 ])
@@ -82,17 +95,15 @@
82 95
83 96 foreach ($submissionCounts as $submissionCount) {
84 97 $submissionCount->permalink = admin_url('admin.php?page=fluent_forms&route=entries&form_id='.$submissionCount->form_id);
85 98 }
86 -
87 - if(!$submissionCounts) {
99 + if(!$submissionCounts || count($submissionCounts) === 0) {
88 100 return; // Nothing found
89 101 }
90 102
91 103 $paymentCounts = [];
92 - if(defined('FLUENTFORMPRO') && get_option('__fluentform_payment_module_settings')) {
93 - $paymentCounts = wpFluent()->table('fluentform_transactions')
94 - ->select([
104 + if(PaymentHelper::hasPaymentSettings()) {
105 + $paymentCounts = \FluentForm\App\Models\Transaction::select([
95 106 wpFluent()->raw("SUM({$wpdb->prefix}fluentform_transactions.payment_total) as total_amount"),
96 107 'fluentform_transactions.form_id',
97 108 'fluentform_transactions.currency',
98 109 'fluentform_forms.title'
@@ -108,14 +119,28 @@
108 119 $paymentCount->readable_amount = $paymentCount->currency.' '.number_format($paymentCount->total_amount / 100);
109 120 }
110 121 }
111 122
112 - $emailBody = View::make('email.report.body', array(
123 + $data = array(
113 124 'submissions' => $submissionCounts,
114 125 'payments' => $paymentCounts,
115 126 'days' => $days
116 - ));
127 + );
128 + $emailBody = wpFluentForm('view')->make('email.report.body', $data);
129 +
130 + $emailBody = apply_filters_deprecated(
131 + 'fluentform_email_summary_body',
132 + [
133 + $emailBody,
134 + $data
135 + ],
136 + FLUENTFORM_FRAMEWORK_UPGRADE,
137 + 'fluentform/email_summary_body',
138 + 'Use fluentform/email_summary_body instead of fluentform_email_summary_body.'
139 + );
117 140
141 + $emailBody = apply_filters('fluentform/email_summary_body', $emailBody, $data);
142 +
118 143 $originalEmailBody = $emailBody;
119 144
120 145 ob_start();
121 146 try {
@@ -133,19 +158,66 @@
133 158
134 159 $headers = [
135 160 'Content-Type: text/html; charset=utf-8'
136 161 ];
162 + /* translators: %s is the Number Email Summary Days */
163 + $emailSubject = sprintf(esc_html__('Email Summary of Your Forms (Last %d Days)', 'fluentform'), $days);
137 164
138 - $emailSubject = sprintf( esc_html__( 'Email Summary of Your Forms (Last %d Days)', 'my-text-domain' ), $days );
165 + if (isset($settings['subject']) && $settings['subject']) {
166 + $emailSubject = $settings['subject'];
167 + }
168 +
169 + $emailSubject = apply_filters_deprecated(
170 + 'fluentform_email_summary_subject',
171 + [
172 + $emailSubject
173 + ],
174 + FLUENTFORM_FRAMEWORK_UPGRADE,
175 + 'fluentform/email_summary_subject',
176 + 'Use fluentform/email_summary_subject instead of fluentform_email_summary_subject'
177 + );
178 + $emailSubject = apply_filters('fluentform/email_summary_subject', $emailSubject);
139 179
140 - $emailSubject = apply_filters('fluentform_email_summary_subject', $emailSubject);
180 + $emailResult = wp_mail($recipients, $emailSubject, $emailBody, $headers);
141 181
142 - return wp_mail($recipients, $emailSubject, $emailBody, $headers);
182 + do_action_deprecated(
183 + 'fluentform_email_summary_details',
184 + [
185 + [
186 + 'recipients' => $recipients,
187 + 'email_subject' => $emailSubject,
188 + 'email_body' => $emailBody
189 + ],
190 + $data,
191 + $emailResult
192 + ],
193 + FLUENTFORM_FRAMEWORK_UPGRADE,
194 + 'fluentform/email_summary_details',
195 + 'Use fluentform/email_summary_details instead of fluentform_email_summary_details.'
196 + );
197 +
198 + do_action('fluentform/email_summary_details', [
199 + 'recipients' => $recipients,
200 + 'email_subject' => $emailSubject,
201 + 'email_body' => $emailBody
202 + ], $data, $emailResult);
203 +
204 + return $emailResult;
143 205 }
144 206
145 207 private static function cleanUpOldData()
146 208 {
147 - $deleteDaysCount = apply_filters('fluentform_cleanup_days_count', 60);
209 + $days = 60;
210 + $days = apply_filters_deprecated(
211 + 'fluentform_cleanup_days_count',
212 + [
213 + $days
214 + ],
215 + FLUENTFORM_FRAMEWORK_UPGRADE,
216 + 'fluentform/cleanup_days_count',
217 + 'Use fluentform/cleanup_days_count instead of fluentform_cleanup_days_count.'
218 + );
219 + $deleteDaysCount = apply_filters('fluentform/cleanup_days_count', $days);
148 220 if(!$deleteDaysCount) {
149 221 return;
150 222 }
151 223 $seconds = $deleteDaysCount * 86400;
@@ -150,15 +222,34 @@
150 222 }
151 223 $seconds = $deleteDaysCount * 86400;
152 224 $deleteTo = date('Y-m-d H:i:s', time() - $seconds);
153 225 // delete 60 days old analytics data
154 - wpFluent()->table('fluentform_form_analytics')
155 - ->where('created_at', '<', $deleteTo)
226 + FormAnalytics::where('created_at', '<', $deleteTo)
156 227 ->delete();
157 228
158 229 // delete 60 days old scheduled_actions data
159 - wpFluent()->table('ff_scheduled_actions')
160 - ->where('created_at', '<', $deleteTo)
230 + \FluentForm\App\Models\Scheduler::where('created_at', '<', $deleteTo)
161 231 ->delete();
162 232
233 + // Clean temp uploads. Default threshold is 2 days. Honors the
234 + // fluentform/temp_file_delete_time filter so multi-step and
235 + // save-and-resume users can extend the window — same filter
236 + // Pro's Uploader::removeOldTempFiles() already respects. Without
237 + // this, the Scheduler cleanup would wipe temp files at 2 days
238 + // regardless of the filter, breaking multi-step uploads.
239 + if (defined('FLUENTFORM_UPLOAD_DIR')) {
240 + $tempDir = wp_upload_dir()['basedir'] . FLUENTFORM_UPLOAD_DIR . '/temp/';
241 + if (is_dir($tempDir)) {
242 + $files = glob($tempDir . '*');
243 + if (!empty($files)) {
244 + $maxFileAge = apply_filters('fluentform/temp_file_delete_time', 172800);
245 + $cutoff = time() - $maxFileAge;
246 + foreach ($files as $file) {
247 + if (is_file($file) && basename($file) !== 'index.php' && filemtime($file) < $cutoff) {
248 + wp_delete_file($file);
249 + }
250 + }
251 + }
252 + }
253 + }
163 254 }
164 -}
255 +}