| @@ -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,9 +307,8 @@ | ||
| 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; |
| @@ -331,9 +316,9 @@ | ||
| 331 | 316 | $result = $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 ) |
| @@ -351,10 +336,8 @@ | ||
| 351 | 336 | /** |
| 352 | 337 | * Shows the comparison HTML in the email. |
| 353 | 338 | * |
| 354 | 339 | * @param float $diff Percentage of difference. |
| 355 | - * | |
| 356 | - * @return void | |
| 357 | 340 | */ |
| 358 | 341 | public static function show_comparison( $diff ) { |
| 359 | 342 | if ( ! $diff ) { |
| 360 | 343 | return; |
| @@ -368,9 +351,8 @@ | ||
| 368 | 351 | $color = '#f04438'; |
| 369 | 352 | } |
| 370 | 353 | |
| 371 | 354 | $displayed_value = round( $diff * 100 ); |
| 372 | - | |
| 373 | 355 | if ( ! $displayed_value ) { |
| 374 | 356 | // Do not show 0 value. |
| 375 | 357 | $displayed_value = $diff > 0 ? 1 : -1; |
| 376 | 358 | } |
| @@ -388,13 +370,16 @@ | ||
| 388 | 370 | /** |
| 389 | 371 | * Gets section CSS in the email. |
| 390 | 372 | * |
| 391 | 373 | * @param string $border_pos Border position. Default is `top`. Set to empty if no border. |
| 392 | - * | |
| 393 | 374 | * @return string |
| 394 | 375 | */ |
| 395 | 376 | public static function get_section_style( $border_pos = 'top' ) { |
| 396 | - $border = $border_pos ? 'border-' . $border_pos . ': 1px solid #eaecf0;' : ''; | |
| 377 | + if ( $border_pos ) { | |
| 378 | + $border = 'border-' . $border_pos . ': 1px solid #eaecf0;'; | |
| 379 | + } else { | |
| 380 | + $border = ''; | |
| 381 | + } | |
| 397 | 382 | return 'padding: 3em 4.375em;' . $border; |
| 398 | 383 | } |
| 399 | 384 | |
| 400 | 385 | /** |
| @@ -408,14 +393,12 @@ | ||
| 408 | 393 | |
| 409 | 394 | /** |
| 410 | 395 | * Gets CSS for button. |
| 411 | 396 | * |
| 412 | - * @param bool $display_block Whether to display the button as block. | |
| 413 | - * | |
| 414 | 397 | * @return string |
| 415 | 398 | */ |
| 416 | 399 | 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 | |
| 400 | + 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 | 401 | } |
| 419 | 402 | |
| 420 | 403 | /** |
| 421 | 404 | * Shows the section heading with icon. |
| @@ -421,15 +404,13 @@ | ||
| 421 | 404 | * Shows the section heading with icon. |
| 422 | 405 | * |
| 423 | 406 | * @param string $icon Icon file name, without file path and extension. Use .png image. |
| 424 | 407 | * @param string $text Heading text. |
| 425 | - * | |
| 426 | - * @return void | |
| 427 | 408 | */ |
| 428 | 409 | public static function section_heading_with_icon( $icon, $text ) { |
| 429 | 410 | ?> |
| 430 | 411 | <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 ?> | |
| 412 | + <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 | 413 | <span style="display: inline-block; vertical-align: text-bottom;"><?php echo esc_html( $text ); ?></span> |
| 433 | 414 | </h2> |
| 434 | 415 | <?php |
| 435 | 416 | } |
| @@ -437,10 +418,9 @@ | ||
| 437 | 418 | /** |
| 438 | 419 | * Gets Formidable URL with tracking params. |
| 439 | 420 | * |
| 440 | 421 | * @param string $url The URL. |
| 441 | - * @param array|string $args Custom tracking args if is array, or `utm_content` if is string. | |
| 442 | - * | |
| 422 | + * @param string|array $args Custom tracking args if is array, or `utm_content` if is string. | |
| 443 | 423 | * @return string |
| 444 | 424 | */ |
| 445 | 425 | public static function get_frm_url( $url, $args = array() ) { |
| 446 | 426 | if ( is_array( $args ) ) { |
| @@ -468,15 +448,13 @@ | ||
| 468 | 448 | */ |
| 469 | 449 | public static function get_latest_inbox_message() { |
| 470 | 450 | $inbox = new FrmInbox(); |
| 471 | 451 | $messages = $inbox->get_messages( 'filter' ); |
| 472 | - | |
| 473 | 452 | if ( ! $messages || ! is_array( $messages ) ) { |
| 474 | 453 | return false; |
| 475 | 454 | } |
| 476 | 455 | |
| 477 | 456 | $messages = array_reverse( $messages ); |
| 478 | - | |
| 479 | 457 | foreach ( $messages as $message ) { |
| 480 | 458 | if ( 'news' !== $message['type'] ) { |
| 481 | 459 | continue; |
| 482 | 460 | } |
| @@ -493,15 +471,13 @@ | ||
| 493 | 471 | * @return array |
| 494 | 472 | */ |
| 495 | 473 | public static function get_out_of_date_plugins() { |
| 496 | 474 | $update_data = FrmAddonsController::check_update( '' ); |
| 497 | - | |
| 498 | 475 | if ( ! $update_data || ! is_object( $update_data ) || empty( $update_data->response ) ) { |
| 499 | 476 | return array(); |
| 500 | 477 | } |
| 501 | 478 | |
| 502 | 479 | $plugins = array(); |
| 503 | - | |
| 504 | 480 | foreach ( $update_data->response as $plugin_data ) { |
| 505 | 481 | $plugins[] = $plugin_data->display_name; |
| 506 | 482 | } |
| 507 | 483 | |
| @@ -511,9 +487,8 @@ | ||
| 511 | 487 | /** |
| 512 | 488 | * Processes inbox CTA button before showing in email. |
| 513 | 489 | * |
| 514 | 490 | * @param string $button_html Button HTML. This usually contains 1 button and 1 dismiss button. |
| 515 | - * | |
| 516 | 491 | * @return string |
| 517 | 492 | */ |
| 518 | 493 | public static function process_inbox_cta_button( $button_html ) { |
| 519 | 494 | // Remove dismiss button. |
| @@ -521,16 +496,16 @@ | ||
| 521 | 496 | |
| 522 | 497 | // Replace link utm. |
| 523 | 498 | $button_html = str_replace( 'utm_medium=inbox', 'utm_medium=summary-email', $button_html ); |
| 524 | 499 | |
| 525 | - if ( str_contains( $button_html, 'style="' ) ) { | |
| 500 | + if ( strpos( $button_html, 'style="' ) ) { | |
| 526 | 501 | // Maybe this button contains inline style. |
| 527 | 502 | return $button_html; |
| 528 | 503 | } |
| 529 | 504 | |
| 530 | 505 | // 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 ); | |
| 506 | + if ( strpos( $button_html, 'frm-button-primary' ) ) { | |
| 507 | + $button_html = str_replace( '<a', '<a style="' . self::get_button_style() . '"', $button_html ); | |
| 533 | 508 | } |
| 534 | 509 | |
| 535 | 510 | return $button_html; |
| 536 | 511 | } |
| @@ -538,9 +513,8 @@ | ||
| 538 | 513 | /** |
| 539 | 514 | * Gets the localized date with the date diff from today. |
| 540 | 515 | * |
| 541 | 516 | * @param string $date_diff Date diff string. By default, this is empty, the result will be the current date. |
| 542 | - * | |
| 543 | 517 | * @return string |
| 544 | 518 | */ |
| 545 | 519 | public static function get_date_from_today( $date_diff = '' ) { |
| 546 | 520 | if ( ! $date_diff ) { |
| @@ -553,25 +527,19 @@ | ||
| 553 | 527 | * Maybe remove recipients from setting from API. |
| 554 | 528 | * |
| 555 | 529 | * @since 6.8 |
| 556 | 530 | * |
| 557 | - * @param string $recipients Recipients. | |
| 558 | - * | |
| 559 | - * @return void | |
| 531 | + * @param array $recipients Recipients. | |
| 560 | 532 | */ |
| 561 | 533 | public static function maybe_remove_recipients_from_api( &$recipients ) { |
| 562 | 534 | $api = new FrmFormApi(); |
| 563 | 535 | $addons = $api->get_api_info(); |
| 564 | - | |
| 565 | 536 | if ( empty( $addons['no_emails'] ) ) { |
| 566 | 537 | return; |
| 567 | 538 | } |
| 568 | 539 | |
| 569 | 540 | $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 ); | |
| 541 | + $recipients = array_diff( $recipients, $skip_emails ); | |
| 574 | 542 | } |
| 575 | 543 | |
| 576 | 544 | /** |
| 577 | 545 | * Echos string in plain text email. |
| @@ -578,10 +546,8 @@ | ||
| 578 | 546 | * |
| 579 | 547 | * @since 6.8 |
| 580 | 548 | * |
| 581 | 549 | * @param string $string string. |
| 582 | - * | |
| 583 | - * @return void | |
| 584 | 550 | */ |
| 585 | 551 | public static function plain_text_echo( $string ) { |
| 586 | 552 | echo wp_strip_all_tags( $string ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 587 | 553 | } |