PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7.2
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 +42 -112 6.28 → 6.7.2 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,22 +62,21 @@
63 62 * @return array
64 63 */
65 64 private static function get_options() {
66 65 $options = get_option( self::$option_name );
66 + if ( ! $options ) {
67 + $default_options = array(
68 + // Do not send email within 15 days after updating.
69 + 'last_' . self::MONTHLY => self::get_date_from_today( '-' . self::DELAY_AFTER_UPGRADE . ' days' ),
70 + 'last_' . self::YEARLY => '',
71 + 'renewal_date' => '',
72 + );
67 73
68 - if ( $options ) {
69 - return $options;
74 + self::save_options( $default_options );
75 + return $default_options;
70 76 }
71 77
72 - $default_options = array(
73 - // Do not send email within 15 days after updating.
74 - 'last_' . self::MONTHLY => self::get_date_from_today( '-' . self::DELAY_AFTER_UPGRADE . ' days' ),
75 - 'last_' . self::YEARLY => '',
76 - 'renewal_date' => '',
77 - );
78 -
79 - self::save_options( $default_options );
80 - return $default_options;
78 + return $options;
81 79 }
82 80
83 81 /**
84 82 * Saves summary emails options.
@@ -83,10 +81,8 @@
83 81 /**
84 82 * Saves summary emails options.
85 83 *
86 84 * @param array $options Options data.
87 - *
88 - * @return void
89 85 */
90 86 private static function save_options( $options ) {
91 87 update_option( self::$option_name, $options );
92 88 }
@@ -122,9 +118,8 @@
122 118 }
123 119 } else {
124 120 // If no yearly email has been sent, send it if it's less than 45 days until the renewal date.
125 121 $renewal_date = self::get_renewal_date();
126 -
127 122 if ( $renewal_date && self::BEFORE_RENEWAL_PERIOD >= self::get_date_diff( $current_date, $renewal_date ) ) {
128 123 $emails[] = self::YEARLY;
129 124 return $emails;
130 125 }
@@ -137,10 +132,8 @@
137 132 }
138 133
139 134 /**
140 135 * Sends monthly email.
141 - *
142 - * @return void
143 136 */
144 137 public static function send_monthly() {
145 138 $monthly_email = new FrmEmailMonthly();
146 139
@@ -150,10 +143,8 @@
150 143 }
151 144
152 145 /**
153 146 * Sends yearly email.
154 - *
155 - * @return void
156 147 */
157 148 public static function send_yearly() {
158 149 $yearly_email = new FrmEmailYearly();
159 150
@@ -176,11 +167,11 @@
176 167 }
177 168
178 169 // Return the actual renewal date if it exists.
179 170 $license_info = FrmAddonsController::get_primary_license_info();
171 + if ( ! empty( $license_info['expires'] ) ) {
172 + $renewal_date = gmdate( 'Y-m-d', $license_info['expires'] );
180 173
181 - if ( ! empty( $license_info['expires'] ) ) {
182 - $renewal_date = gmdate( 'Y-m-d', $license_info['expires'] );
183 174 $options['renewal_date'] = $renewal_date;
184 175 self::save_options( $options );
185 176 return $renewal_date;
186 177 }
@@ -186,9 +177,8 @@
186 177 }
187 178
188 179 // If renewal date doesn't exist, get from the first form creation date.
189 180 $first_form_date = self::get_earliest_form_created_date();
190 -
191 181 if ( $first_form_date ) {
192 182 $renewal_date = gmdate( 'Y-m-d', strtotime( $first_form_date . '+' . self::YEARLY_PERIOD . ' days' ) );
193 183
194 184 // If the first form is more than 1 year in the past, set renewal date to the next 45 days.
@@ -206,34 +196,38 @@
206 196
207 197 /**
208 198 * Gets date object.
209 199 *
210 - * @param DateTime|string $date Date string or object.
211 - *
200 + * @param string|DateTime $date Date string or object.
212 201 * @return DateTime|false
213 202 */
214 203 private static function get_date_obj( $date ) {
215 - return $date instanceof DateTime ? $date : date_create( $date );
204 + if ( $date instanceof DateTime ) {
205 + return $date;
206 + }
207 +
208 + return date_create( $date );
216 209 }
217 210
218 211 /**
219 212 * Gets the days different between 2 dates.
220 213 *
221 - * @param DateTime|string $date1 Date 1.
222 - * @param DateTime|string $date2 Date 2.
223 - *
224 - * @return false|int
214 + * @param string|DateTime $date1 Date 1.
215 + * @param string|DateTime $date2 Date 2.
216 + * @return int|false
225 217 */
226 218 private static function get_date_diff( $date1, $date2 ) {
227 219 $date1 = self::get_date_obj( $date1 );
228 -
229 220 if ( ! $date1 ) {
230 221 return false;
231 222 }
232 223
233 224 $date2 = self::get_date_obj( $date2 );
225 + if ( ! $date2 ) {
226 + return false;
227 + }
234 228
235 - return $date2 ? date_diff( $date1, $date2 )->days : false;
229 + return date_diff( $date1, $date2 )->days;
236 230 }
237 231
238 232 /**
239 233 * Gets sent date of the last monthly or yearly email.
@@ -238,14 +232,12 @@
238 232 /**
239 233 * Gets sent date of the last monthly or yearly email.
240 234 *
241 235 * @param string $type Accepts `monthly`, `yearly`.
242 - *
243 - * @return false|string
236 + * @return string|false
244 237 */
245 238 public static function get_last_sent_date( $type ) {
246 239 $options = self::get_options();
247 -
248 240 if ( empty( $options[ 'last_' . $type ] ) ) {
249 241 return false;
250 242 }
251 243
@@ -256,10 +248,8 @@
256 248 * Sets the last sent date of an email type.
257 249 *
258 250 * @param string $type Email type.
259 251 * @param mixed $value Set custom value. If this is null, set the current date.
260 - *
261 - * @return void
262 252 */
263 253 public static function set_last_sent_date( $type, $value = null ) {
264 254 $options = self::get_options();
265 255
@@ -285,9 +275,8 @@
285 275 * Gets payments data.
286 276 *
287 277 * @param string $from_date From date.
288 278 * @param string $to_date To date.
289 - *
290 279 * @return array Contains `count` and `total`.
291 280 */
292 281 public static function get_payments_data( $from_date, $to_date ) {
293 282 $payment = new FrmTransLitePayment();
@@ -298,9 +287,8 @@
298 287 * Gets entries count in a date range.
299 288 *
300 289 * @param string $from_date From date.
301 290 * @param string $to_date To date.
302 - *
303 291 * @return int
304 292 */
305 293 public static function get_entries_count( $from_date, $to_date ) {
306 294 return FrmDb::get_count(
@@ -306,13 +294,11 @@
306 294 return FrmDb::get_count(
307 295 'frm_items',
308 296 array(
309 297 // The `=` is added after `>` in the query.
310 - 'created_at >' => $from_date,
311 - 'created_at <' => $to_date . ' 23:59:59',
312 - 'is_draft' => 0,
313 - // Do not count repeater entries.
314 - 'parent_item_id' => 0,
298 + 'created_at >' => $from_date,
299 + 'created_at <' => $to_date . ' 23:59:59',
300 + 'is_draft' => 0,
315 301 )
316 302 );
317 303 }
318 304
@@ -321,19 +307,18 @@
321 307 *
322 308 * @param string $from_date From date.
323 309 * @param string $to_date To date.
324 310 * @param int $limit Limit the result. Default is 5.
325 - *
326 311 * @return array Contains `form_id`, `form_name`, and `items_count`.
327 312 */
328 313 public static function get_top_forms( $from_date, $to_date, $limit = 5 ) {
329 314 global $wpdb;
330 315
331 - $result = $wpdb->get_results(
316 + return $wpdb->get_results(
332 317 $wpdb->prepare(
333 318 "SELECT fr.id AS form_id, fr.name AS form_name, COUNT(*) as items_count
334 319 FROM {$wpdb->prefix}frm_items AS it INNER JOIN {$wpdb->prefix}frm_forms AS fr ON it.form_id = fr.id
335 - WHERE it.created_at BETWEEN %s AND %s AND it.is_draft = 0 AND parent_form_id = 0
320 + WHERE it.created_at BETWEEN %s AND %s AND it.is_draft = 0
336 321 GROUP BY form_id ORDER BY items_count DESC LIMIT %d",
337 322 $from_date,
338 323 $to_date . ' 23:59:59',
339 324 intval( $limit )
@@ -338,15 +323,8 @@
338 323 $to_date . ' 23:59:59',
339 324 intval( $limit )
340 325 )
341 326 );
342 -
343 - // Remove slashes from form name.
344 - foreach ( $result as &$value ) {
345 - $value->form_name = wp_unslash( $value->form_name );
346 - }
347 -
348 - return $result;
349 327 }
350 328
351 329 /**
352 330 * Shows the comparison HTML in the email.
@@ -351,10 +329,8 @@
351 329 /**
352 330 * Shows the comparison HTML in the email.
353 331 *
354 332 * @param float $diff Percentage of difference.
355 - *
356 - * @return void
357 333 */
358 334 public static function show_comparison( $diff ) {
359 335 if ( ! $diff ) {
360 336 return;
@@ -368,9 +344,8 @@
368 344 $color = '#f04438';
369 345 }
370 346
371 347 $displayed_value = round( $diff * 100 );
372 -
373 348 if ( ! $displayed_value ) {
374 349 // Do not show 0 value.
375 350 $displayed_value = $diff > 0 ? 1 : -1;
376 351 }
@@ -388,13 +363,16 @@
388 363 /**
389 364 * Gets section CSS in the email.
390 365 *
391 366 * @param string $border_pos Border position. Default is `top`. Set to empty if no border.
392 - *
393 367 * @return string
394 368 */
395 369 public static function get_section_style( $border_pos = 'top' ) {
396 - $border = $border_pos ? 'border-' . $border_pos . ': 1px solid #eaecf0;' : '';
370 + if ( $border_pos ) {
371 + $border = 'border-' . $border_pos . ': 1px solid #eaecf0;';
372 + } else {
373 + $border = '';
374 + }
397 375 return 'padding: 3em 4.375em;' . $border;
398 376 }
399 377
400 378 /**
@@ -408,14 +386,12 @@
408 386
409 387 /**
410 388 * Gets CSS for button.
411 389 *
412 - * @param bool $display_block Whether to display the button as block.
413 - *
414 390 * @return string
415 391 */
416 392 public static function get_button_style( $display_block = false ) {
417 - 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;'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
393 + 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;';
418 394 }
419 395
420 396 /**
421 397 * Shows the section heading with icon.
@@ -421,15 +397,13 @@
421 397 * Shows the section heading with icon.
422 398 *
423 399 * @param string $icon Icon file name, without file path and extension. Use .png image.
424 400 * @param string $text Heading text.
425 - *
426 - * @return void
427 401 */
428 402 public static function section_heading_with_icon( $icon, $text ) {
429 403 ?>
430 404 <h2 style="<?php echo esc_attr( self::get_heading2_style() ); ?>">
431 - <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 ); ?>" /><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
405 + <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 ); ?>" />
432 406 <span style="display: inline-block; vertical-align: text-bottom;"><?php echo esc_html( $text ); ?></span>
433 407 </h2>
434 408 <?php
435 409 }
@@ -437,10 +411,9 @@
437 411 /**
438 412 * Gets Formidable URL with tracking params.
439 413 *
440 414 * @param string $url The URL.
441 - * @param array|string $args Custom tracking args if is array, or `utm_content` if is string.
442 - *
415 + * @param string|array $args Custom tracking args if is array, or `utm_content` if is string.
443 416 * @return string
444 417 */
445 418 public static function get_frm_url( $url, $args = array() ) {
446 419 if ( is_array( $args ) ) {
@@ -468,15 +441,13 @@
468 441 */
469 442 public static function get_latest_inbox_message() {
470 443 $inbox = new FrmInbox();
471 444 $messages = $inbox->get_messages( 'filter' );
472 -
473 445 if ( ! $messages || ! is_array( $messages ) ) {
474 446 return false;
475 447 }
476 448
477 449 $messages = array_reverse( $messages );
478 -
479 450 foreach ( $messages as $message ) {
480 451 if ( 'news' !== $message['type'] ) {
481 452 continue;
482 453 }
@@ -493,15 +464,13 @@
493 464 * @return array
494 465 */
495 466 public static function get_out_of_date_plugins() {
496 467 $update_data = FrmAddonsController::check_update( '' );
497 -
498 468 if ( ! $update_data || ! is_object( $update_data ) || empty( $update_data->response ) ) {
499 469 return array();
500 470 }
501 471
502 472 $plugins = array();
503 -
504 473 foreach ( $update_data->response as $plugin_data ) {
505 474 $plugins[] = $plugin_data->display_name;
506 475 }
507 476
@@ -511,9 +480,8 @@
511 480 /**
512 481 * Processes inbox CTA button before showing in email.
513 482 *
514 483 * @param string $button_html Button HTML. This usually contains 1 button and 1 dismiss button.
515 - *
516 484 * @return string
517 485 */
518 486 public static function process_inbox_cta_button( $button_html ) {
519 487 // Remove dismiss button.
@@ -521,16 +489,16 @@
521 489
522 490 // Replace link utm.
523 491 $button_html = str_replace( 'utm_medium=inbox', 'utm_medium=summary-email', $button_html );
524 492
525 - if ( str_contains( $button_html, 'style="' ) ) {
493 + if ( strpos( $button_html, 'style="' ) ) {
526 494 // Maybe this button contains inline style.
527 495 return $button_html;
528 496 }
529 497
530 498 // Add inline CSS for specific button types.
531 - if ( str_contains( $button_html, 'frm-button-primary' ) ) {
532 - return str_replace( '<a', '<a style="' . self::get_button_style() . '"', $button_html );
499 + if ( strpos( $button_html, 'frm-button-primary' ) ) {
500 + $button_html = str_replace( '<a', '<a style="' . self::get_button_style() . '"', $button_html );
533 501 }
534 502
535 503 return $button_html;
536 504 }
@@ -538,9 +506,8 @@
538 506 /**
539 507 * Gets the localized date with the date diff from today.
540 508 *
541 509 * @param string $date_diff Date diff string. By default, this is empty, the result will be the current date.
542 - *
543 510 * @return string
544 511 */
545 512 public static function get_date_from_today( $date_diff = '' ) {
546 513 if ( ! $date_diff ) {
@@ -546,43 +513,6 @@
546 513 if ( ! $date_diff ) {
547 514 return FrmAppHelper::get_localized_date( 'Y-m-d', gmdate( 'Y-m-d H:i:s' ) );
548 515 }
549 516 return FrmAppHelper::get_localized_date( 'Y-m-d', gmdate( 'Y-m-d H:i:s', strtotime( $date_diff ) ) );
550 - }
551 -
552 - /**
553 - * Maybe remove recipients from setting from API.
554 - *
555 - * @since 6.8
556 - *
557 - * @param string $recipients Recipients.
558 - *
559 - * @return void
560 - */
561 - public static function maybe_remove_recipients_from_api( &$recipients ) {
562 - $api = new FrmFormApi();
563 - $addons = $api->get_api_info();
564 -
565 - if ( empty( $addons['no_emails'] ) ) {
566 - return;
567 - }
568 -
569 - $skip_emails = is_string( $addons['no_emails'] ) ? explode( ',', $addons['no_emails'] ) : (array) $addons['no_emails'];
570 -
571 - $recipients = array_map( 'trim', explode( ',', $recipients ) );
572 - $recipients = array_diff( $recipients, $skip_emails );
573 - $recipients = implode( ',', $recipients );
574 - }
575 -
576 - /**
577 - * Echos string in plain text email.
578 - *
579 - * @since 6.8
580 - *
581 - * @param string $string string.
582 - *
583 - * @return void
584 - */
585 - public static function plain_text_echo( $string ) {
586 - echo wp_strip_all_tags( $string ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
587 517 }
588 518 }