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