PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.23
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.23
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 +31 -59 6.286.23 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.
@@ -207,13 +197,16 @@
207 197 /**
208 198 * Gets date object.
209 199 *
210 200 * @param DateTime|string $date Date string or object.
211 - *
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.
@@ -219,21 +212,22 @@
219 212 * Gets the days different between 2 dates.
220 213 *
221 214 * @param DateTime|string $date1 Date 1.
222 215 * @param DateTime|string $date2 Date 2.
223 - *
224 216 * @return false|int
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 236 * @return false|string
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(
@@ -321,9 +309,8 @@
321 309 *
322 310 * @param string $from_date From date.
323 311 * @param string $to_date To date.
324 312 * @param int $limit Limit the result. Default is 5.
325 - *
326 313 * @return array Contains `form_id`, `form_name`, and `items_count`.
327 314 */
328 315 public static function get_top_forms( $from_date, $to_date, $limit = 5 ) {
329 316 global $wpdb;
@@ -351,10 +338,8 @@
351 338 /**
352 339 * Shows the comparison HTML in the email.
353 340 *
354 341 * @param float $diff Percentage of difference.
355 - *
356 - * @return void
357 342 */
358 343 public static function show_comparison( $diff ) {
359 344 if ( ! $diff ) {
360 345 return;
@@ -368,9 +353,8 @@
368 353 $color = '#f04438';
369 354 }
370 355
371 356 $displayed_value = round( $diff * 100 );
372 -
373 357 if ( ! $displayed_value ) {
374 358 // Do not show 0 value.
375 359 $displayed_value = $diff > 0 ? 1 : -1;
376 360 }
@@ -388,13 +372,16 @@
388 372 /**
389 373 * Gets section CSS in the email.
390 374 *
391 375 * @param string $border_pos Border position. Default is `top`. Set to empty if no border.
392 - *
393 376 * @return string
394 377 */
395 378 public static function get_section_style( $border_pos = 'top' ) {
396 - $border = $border_pos ? 'border-' . $border_pos . ': 1px solid #eaecf0;' : '';
379 + if ( $border_pos ) {
380 + $border = 'border-' . $border_pos . ': 1px solid #eaecf0;';
381 + } else {
382 + $border = '';
383 + }
397 384 return 'padding: 3em 4.375em;' . $border;
398 385 }
399 386
400 387 /**
@@ -408,14 +395,12 @@
408 395
409 396 /**
410 397 * Gets CSS for button.
411 398 *
412 - * @param bool $display_block Whether to display the button as block.
413 - *
414 399 * @return string
415 400 */
416 401 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
402 + 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 403 }
419 404
420 405 /**
421 406 * Shows the section heading with icon.
@@ -421,15 +406,13 @@
421 406 * Shows the section heading with icon.
422 407 *
423 408 * @param string $icon Icon file name, without file path and extension. Use .png image.
424 409 * @param string $text Heading text.
425 - *
426 - * @return void
427 410 */
428 411 public static function section_heading_with_icon( $icon, $text ) {
429 412 ?>
430 413 <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 ?>
414 + <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 415 <span style="display: inline-block; vertical-align: text-bottom;"><?php echo esc_html( $text ); ?></span>
433 416 </h2>
434 417 <?php
435 418 }
@@ -438,9 +421,8 @@
438 421 * Gets Formidable URL with tracking params.
439 422 *
440 423 * @param string $url The URL.
441 424 * @param array|string $args Custom tracking args if is array, or `utm_content` if is string.
442 - *
443 425 * @return string
444 426 */
445 427 public static function get_frm_url( $url, $args = array() ) {
446 428 if ( is_array( $args ) ) {
@@ -468,15 +450,13 @@
468 450 */
469 451 public static function get_latest_inbox_message() {
470 452 $inbox = new FrmInbox();
471 453 $messages = $inbox->get_messages( 'filter' );
472 -
473 454 if ( ! $messages || ! is_array( $messages ) ) {
474 455 return false;
475 456 }
476 457
477 458 $messages = array_reverse( $messages );
478 -
479 459 foreach ( $messages as $message ) {
480 460 if ( 'news' !== $message['type'] ) {
481 461 continue;
482 462 }
@@ -493,15 +473,13 @@
493 473 * @return array
494 474 */
495 475 public static function get_out_of_date_plugins() {
496 476 $update_data = FrmAddonsController::check_update( '' );
497 -
498 477 if ( ! $update_data || ! is_object( $update_data ) || empty( $update_data->response ) ) {
499 478 return array();
500 479 }
501 480
502 481 $plugins = array();
503 -
504 482 foreach ( $update_data->response as $plugin_data ) {
505 483 $plugins[] = $plugin_data->display_name;
506 484 }
507 485
@@ -511,9 +489,8 @@
511 489 /**
512 490 * Processes inbox CTA button before showing in email.
513 491 *
514 492 * @param string $button_html Button HTML. This usually contains 1 button and 1 dismiss button.
515 - *
516 493 * @return string
517 494 */
518 495 public static function process_inbox_cta_button( $button_html ) {
519 496 // Remove dismiss button.
@@ -521,16 +498,16 @@
521 498
522 499 // Replace link utm.
523 500 $button_html = str_replace( 'utm_medium=inbox', 'utm_medium=summary-email', $button_html );
524 501
525 - if ( str_contains( $button_html, 'style="' ) ) {
502 + if ( strpos( $button_html, 'style="' ) ) {
526 503 // Maybe this button contains inline style.
527 504 return $button_html;
528 505 }
529 506
530 507 // 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 );
508 + if ( strpos( $button_html, 'frm-button-primary' ) ) {
509 + $button_html = str_replace( '<a', '<a style="' . self::get_button_style() . '"', $button_html );
533 510 }
534 511
535 512 return $button_html;
536 513 }
@@ -538,9 +515,8 @@
538 515 /**
539 516 * Gets the localized date with the date diff from today.
540 517 *
541 518 * @param string $date_diff Date diff string. By default, this is empty, the result will be the current date.
542 - *
543 519 * @return string
544 520 */
545 521 public static function get_date_from_today( $date_diff = '' ) {
546 522 if ( ! $date_diff ) {
@@ -554,15 +530,13 @@
554 530 *
555 531 * @since 6.8
556 532 *
557 533 * @param string $recipients Recipients.
558 - *
559 534 * @return void
560 535 */
561 536 public static function maybe_remove_recipients_from_api( &$recipients ) {
562 537 $api = new FrmFormApi();
563 538 $addons = $api->get_api_info();
564 -
565 539 if ( empty( $addons['no_emails'] ) ) {
566 540 return;
567 541 }
568 542
@@ -578,10 +552,8 @@
578 552 *
579 553 * @since 6.8
580 554 *
581 555 * @param string $string string.
582 - *
583 - * @return void
584 556 */
585 557 public static function plain_text_echo( $string ) {
586 558 echo wp_strip_all_tags( $string ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
587 559 }