PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/helpers/FrmEmailSummaryHelper.php +15 -101 6.26 → 6.7 View file →
@@ -2,9 +2,8 @@
2 2 /**
3 3 * In-plugin summary emails helper
4 4 *
5 5 * @since 6.7
6 - *
7 6 * @package Formidable
8 7 */
9 8
10 9 if ( ! defined( 'ABSPATH' ) ) {
@@ -63,13 +62,11 @@
63 62 * @return array
64 63 */
65 64 private static function get_options() {
66 65 $options = get_option( self::$option_name );
67 -
68 66 if ( ! $options ) {
69 67 $default_options = array(
70 - // Do not send email within 15 days after updating.
71 - 'last_' . self::MONTHLY => self::get_date_from_today( '-' . self::DELAY_AFTER_UPGRADE . ' days' ),
68 + 'last_' . self::MONTHLY => self::get_date_from_today( '-' . self::DELAY_AFTER_UPGRADE . ' days' ), // Do not send email within 15 days after updating.
72 69 'last_' . self::YEARLY => '',
73 70 'renewal_date' => '',
74 71 );
75 72
@@ -83,10 +80,8 @@
83 80 /**
84 81 * Saves summary emails options.
85 82 *
86 83 * @param array $options Options data.
87 - *
88 - * @return void
89 84 */
90 85 private static function save_options( $options ) {
91 86 update_option( self::$option_name, $options );
92 87 }
@@ -122,9 +117,8 @@
122 117 }
123 118 } else {
124 119 // If no yearly email has been sent, send it if it's less than 45 days until the renewal date.
125 120 $renewal_date = self::get_renewal_date();
126 -
127 121 if ( $renewal_date && self::BEFORE_RENEWAL_PERIOD >= self::get_date_diff( $current_date, $renewal_date ) ) {
128 122 $emails[] = self::YEARLY;
129 123 return $emails;
130 124 }
@@ -137,10 +131,8 @@
137 131 }
138 132
139 133 /**
140 134 * Sends monthly email.
141 - *
142 - * @return void
143 135 */
144 136 public static function send_monthly() {
145 137 $monthly_email = new FrmEmailMonthly();
146 138
@@ -150,10 +142,8 @@
150 142 }
151 143
152 144 /**
153 145 * Sends yearly email.
154 - *
155 - * @return void
156 146 */
157 147 public static function send_yearly() {
158 148 $yearly_email = new FrmEmailYearly();
159 149
@@ -176,9 +166,8 @@
176 166 }
177 167
178 168 // Return the actual renewal date if it exists.
179 169 $license_info = FrmAddonsController::get_primary_license_info();
180 -
181 170 if ( ! empty( $license_info['expires'] ) ) {
182 171 $renewal_date = gmdate( 'Y-m-d', $license_info['expires'] );
183 172
184 173 $options['renewal_date'] = $renewal_date;
@@ -187,9 +176,8 @@
187 176 }
188 177
189 178 // If renewal date doesn't exist, get from the first form creation date.
190 179 $first_form_date = self::get_earliest_form_created_date();
191 -
192 180 if ( $first_form_date ) {
193 181 $renewal_date = gmdate( 'Y-m-d', strtotime( $first_form_date . '+' . self::YEARLY_PERIOD . ' days' ) );
194 182
195 183 // If the first form is more than 1 year in the past, set renewal date to the next 45 days.
@@ -207,10 +195,9 @@
207 195
208 196 /**
209 197 * Gets date object.
210 198 *
211 - * @param DateTime|string $date Date string or object.
212 - *
199 + * @param string|DateTime $date Date string or object.
213 200 * @return DateTime|false
214 201 */
215 202 private static function get_date_obj( $date ) {
216 203 if ( $date instanceof DateTime ) {
@@ -222,22 +209,19 @@
222 209
223 210 /**
224 211 * Gets the days different between 2 dates.
225 212 *
226 - * @param DateTime|string $date1 Date 1.
227 - * @param DateTime|string $date2 Date 2.
228 - *
229 - * @return false|int
213 + * @param string|DateTime $date1 Date 1.
214 + * @param string|DateTime $date2 Date 2.
215 + * @return int|false
230 216 */
231 217 private static function get_date_diff( $date1, $date2 ) {
232 218 $date1 = self::get_date_obj( $date1 );
233 -
234 219 if ( ! $date1 ) {
235 220 return false;
236 221 }
237 222
238 223 $date2 = self::get_date_obj( $date2 );
239 -
240 224 if ( ! $date2 ) {
241 225 return false;
242 226 }
243 227
@@ -247,14 +231,12 @@
247 231 /**
248 232 * Gets sent date of the last monthly or yearly email.
249 233 *
250 234 * @param string $type Accepts `monthly`, `yearly`.
251 - *
252 - * @return false|string
235 + * @return string|false
253 236 */
254 237 public static function get_last_sent_date( $type ) {
255 238 $options = self::get_options();
256 -
257 239 if ( empty( $options[ 'last_' . $type ] ) ) {
258 240 return false;
259 241 }
260 242
@@ -265,10 +247,8 @@
265 247 * Sets the last sent date of an email type.
266 248 *
267 249 * @param string $type Email type.
268 250 * @param mixed $value Set custom value. If this is null, set the current date.
269 - *
270 - * @return void
271 251 */
272 252 public static function set_last_sent_date( $type, $value = null ) {
273 253 $options = self::get_options();
274 254
@@ -294,9 +274,8 @@
294 274 * Gets payments data.
295 275 *
296 276 * @param string $from_date From date.
297 277 * @param string $to_date To date.
298 - *
299 278 * @return array Contains `count` and `total`.
300 279 */
301 280 public static function get_payments_data( $from_date, $to_date ) {
302 281 $payment = new FrmTransLitePayment();
@@ -307,9 +286,8 @@
307 286 * Gets entries count in a date range.
308 287 *
309 288 * @param string $from_date From date.
310 289 * @param string $to_date To date.
311 - *
312 290 * @return int
313 291 */
314 292 public static function get_entries_count( $from_date, $to_date ) {
315 293 return FrmDb::get_count(
@@ -314,14 +292,11 @@
314 292 public static function get_entries_count( $from_date, $to_date ) {
315 293 return FrmDb::get_count(
316 294 'frm_items',
317 295 array(
318 - // The `=` is added after `>` in the query.
319 - 'created_at >' => $from_date,
320 - 'created_at <' => $to_date . ' 23:59:59',
321 - 'is_draft' => 0,
322 - // Do not count repeater entries.
323 - 'parent_item_id' => 0,
296 + 'created_at >' => $from_date, // The `=` is added after `>` in the query.
297 + 'created_at <' => $to_date . ' 23:59:59',
298 + 'is_draft' => 0,
324 299 )
325 300 );
326 301 }
327 302
@@ -330,19 +305,18 @@
330 305 *
331 306 * @param string $from_date From date.
332 307 * @param string $to_date To date.
333 308 * @param int $limit Limit the result. Default is 5.
334 - *
335 309 * @return array Contains `form_id`, `form_name`, and `items_count`.
336 310 */
337 311 public static function get_top_forms( $from_date, $to_date, $limit = 5 ) {
338 312 global $wpdb;
339 313
340 - $result = $wpdb->get_results(
314 + return $wpdb->get_results(
341 315 $wpdb->prepare(
342 316 "SELECT fr.id AS form_id, fr.name AS form_name, COUNT(*) as items_count
343 317 FROM {$wpdb->prefix}frm_items AS it INNER JOIN {$wpdb->prefix}frm_forms AS fr ON it.form_id = fr.id
344 - WHERE it.created_at BETWEEN %s AND %s AND it.is_draft = 0 AND parent_form_id = 0
318 + WHERE it.created_at BETWEEN %s AND %s AND it.is_draft = 0
345 319 GROUP BY form_id ORDER BY items_count DESC LIMIT %d",
346 320 $from_date,
347 321 $to_date . ' 23:59:59',
348 322 intval( $limit )
@@ -347,15 +321,8 @@
347 321 $to_date . ' 23:59:59',
348 322 intval( $limit )
349 323 )
350 324 );
351 -
352 - // Remove slashes from form name.
353 - foreach ( $result as &$value ) {
354 - $value->form_name = wp_unslash( $value->form_name );
355 - }
356 -
357 - return $result;
358 325 }
359 326
360 327 /**
361 328 * Shows the comparison HTML in the email.
@@ -360,10 +327,8 @@
360 327 /**
361 328 * Shows the comparison HTML in the email.
362 329 *
363 330 * @param float $diff Percentage of difference.
364 - *
365 - * @return void
366 331 */
367 332 public static function show_comparison( $diff ) {
368 333 if ( ! $diff ) {
369 334 return;
@@ -377,12 +342,10 @@
377 342 $color = '#f04438';
378 343 }
379 344
380 345 $displayed_value = round( $diff * 100 );
381 -
382 346 if ( ! $displayed_value ) {
383 - // Do not show 0 value.
384 - $displayed_value = $diff > 0 ? 1 : -1;
347 + $displayed_value = $diff > 0 ? 1 : -1; // Do not show 0 value.
385 348 }
386 349
387 350 printf(
388 351 '<span style="color: %1$s; font-size: 0.75em; font-weight: 700;">
@@ -397,9 +360,8 @@
397 360 /**
398 361 * Gets section CSS in the email.
399 362 *
400 363 * @param string $border_pos Border position. Default is `top`. Set to empty if no border.
401 - *
402 364 * @return string
403 365 */
404 366 public static function get_section_style( $border_pos = 'top' ) {
405 367 if ( $border_pos ) {
@@ -421,10 +383,8 @@
421 383
422 384 /**
423 385 * Gets CSS for button.
424 386 *
425 - * @param bool $display_block Whether to display the button as block.
426 - *
427 387 * @return string
428 388 */
429 389 public static function get_button_style( $display_block = false ) {
430 390 return 'display: ' . ( $display_block ? 'block' : 'inline-block' ) . '; font-size: 0.875em; line-height: 2.4; border-radius: 1.2em; border: 1px solid #d0d5dd; font-weight: 600; text-align: center; margin-top: 2.6em; color: #1d2939; text-decoration: none; padding-left: 1em; padding-right: 1em;';
@@ -434,15 +394,13 @@
434 394 * Shows the section heading with icon.
435 395 *
436 396 * @param string $icon Icon file name, without file path and extension. Use .png image.
437 397 * @param string $text Heading text.
438 - *
439 - * @return void
440 398 */
441 399 public static function section_heading_with_icon( $icon, $text ) {
442 400 ?>
443 401 <h2 style="<?php echo esc_attr( self::get_heading2_style() ); ?>">
444 - <img style="vertical-align: bottom; height: 24px; width: auto;" src="<?php echo esc_url( FrmAppHelper::plugin_url() . '/images/' . $icon . '.png' ); ?>" alt="<?php echo esc_attr( $icon ); ?>" />
402 + <img style="vertical-align: bottom;" src="<?php echo esc_url( FrmAppHelper::plugin_url() . '/images/' . $icon . '.png' ); ?>" alt="<?php echo esc_attr( $icon ); ?>" />
445 403 <span style="display: inline-block; vertical-align: text-bottom;"><?php echo esc_html( $text ); ?></span>
446 404 </h2>
447 405 <?php
448 406 }
@@ -449,11 +407,10 @@
449 407
450 408 /**
451 409 * Gets Formidable URL with tracking params.
452 410 *
453 - * @param string $url The URL.
454 - * @param array|string $args Custom tracking args if is array, or `utm_content` if is string.
455 - *
411 + * @param string $url The URL.
412 + * @param string|array $args Custom tracking args if is array, or `utm_content` if is string.
456 413 * @return string
457 414 */
458 415 public static function get_frm_url( $url, $args = array() ) {
459 416 if ( is_array( $args ) ) {
@@ -481,15 +438,13 @@
481 438 */
482 439 public static function get_latest_inbox_message() {
483 440 $inbox = new FrmInbox();
484 441 $messages = $inbox->get_messages( 'filter' );
485 -
486 442 if ( ! $messages || ! is_array( $messages ) ) {
487 443 return false;
488 444 }
489 445
490 446 $messages = array_reverse( $messages );
491 -
492 447 foreach ( $messages as $message ) {
493 448 if ( 'news' !== $message['type'] ) {
494 449 continue;
495 450 }
@@ -506,15 +461,13 @@
506 461 * @return array
507 462 */
508 463 public static function get_out_of_date_plugins() {
509 464 $update_data = FrmAddonsController::check_update( '' );
510 -
511 465 if ( ! $update_data || ! is_object( $update_data ) || empty( $update_data->response ) ) {
512 466 return array();
513 467 }
514 468
515 469 $plugins = array();
516 -
517 470 foreach ( $update_data->response as $plugin_data ) {
518 471 $plugins[] = $plugin_data->display_name;
519 472 }
520 473
@@ -524,9 +477,8 @@
524 477 /**
525 478 * Processes inbox CTA button before showing in email.
526 479 *
527 480 * @param string $button_html Button HTML. This usually contains 1 button and 1 dismiss button.
528 - *
529 481 * @return string
530 482 */
531 483 public static function process_inbox_cta_button( $button_html ) {
532 484 // Remove dismiss button.
@@ -551,9 +503,8 @@
551 503 /**
552 504 * Gets the localized date with the date diff from today.
553 505 *
554 506 * @param string $date_diff Date diff string. By default, this is empty, the result will be the current date.
555 - *
556 507 * @return string
557 508 */
558 509 public static function get_date_from_today( $date_diff = '' ) {
559 510 if ( ! $date_diff ) {
@@ -559,43 +510,6 @@
559 510 if ( ! $date_diff ) {
560 511 return FrmAppHelper::get_localized_date( 'Y-m-d', gmdate( 'Y-m-d H:i:s' ) );
561 512 }
562 513 return FrmAppHelper::get_localized_date( 'Y-m-d', gmdate( 'Y-m-d H:i:s', strtotime( $date_diff ) ) );
563 - }
564 -
565 - /**
566 - * Maybe remove recipients from setting from API.
567 - *
568 - * @since 6.8
569 - *
570 - * @param string $recipients Recipients.
571 - *
572 - * @return void
573 - */
574 - public static function maybe_remove_recipients_from_api( &$recipients ) {
575 - $api = new FrmFormApi();
576 - $addons = $api->get_api_info();
577 -
578 - if ( empty( $addons['no_emails'] ) ) {
579 - return;
580 - }
581 -
582 - $skip_emails = is_string( $addons['no_emails'] ) ? explode( ',', $addons['no_emails'] ) : (array) $addons['no_emails'];
583 -
584 - $recipients = array_map( 'trim', explode( ',', $recipients ) );
585 - $recipients = array_diff( $recipients, $skip_emails );
586 - $recipients = implode( ',', $recipients );
587 - }
588 -
589 - /**
590 - * Echos string in plain text email.
591 - *
592 - * @since 6.8
593 - *
594 - * @param string $string string.
595 - *
596 - * @return void
597 - */
598 - public static function plain_text_echo( $string ) {
599 - echo wp_strip_all_tags( $string ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
600 514 }
601 515 }