| @@ -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,9 +62,8 @@ | ||
| 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 | 68 | // Do not send email within 15 days after updating. |
| 71 | 69 | 'last_' . self::MONTHLY => self::get_date_from_today( '-' . self::DELAY_AFTER_UPGRADE . ' days' ), |
| @@ -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,9 +167,8 @@ | ||
| 176 | 167 | } |
| 177 | 168 | |
| 178 | 169 | // Return the actual renewal date if it exists. |
| 179 | 170 | $license_info = FrmAddonsController::get_primary_license_info(); |
| 180 | - | |
| 181 | 171 | if ( ! empty( $license_info['expires'] ) ) { |
| 182 | 172 | $renewal_date = gmdate( 'Y-m-d', $license_info['expires'] ); |
| 183 | 173 | |
| 184 | 174 | $options['renewal_date'] = $renewal_date; |
| @@ -187,9 +177,8 @@ | ||
| 187 | 177 | } |
| 188 | 178 | |
| 189 | 179 | // If renewal date doesn't exist, get from the first form creation date. |
| 190 | 180 | $first_form_date = self::get_earliest_form_created_date(); |
| 191 | - | |
| 192 | 181 | if ( $first_form_date ) { |
| 193 | 182 | $renewal_date = gmdate( 'Y-m-d', strtotime( $first_form_date . '+' . self::YEARLY_PERIOD . ' days' ) ); |
| 194 | 183 | |
| 195 | 184 | // If the first form is more than 1 year in the past, set renewal date to the next 45 days. |
| @@ -208,9 +197,8 @@ | ||
| 208 | 197 | /** |
| 209 | 198 | * Gets date object. |
| 210 | 199 | * |
| 211 | 200 | * @param DateTime|string $date Date string or object. |
| 212 | - * | |
| 213 | 201 | * @return DateTime|false |
| 214 | 202 | */ |
| 215 | 203 | private static function get_date_obj( $date ) { |
| 216 | 204 | if ( $date instanceof DateTime ) { |
| @@ -224,20 +212,17 @@ | ||
| 224 | 212 | * Gets the days different between 2 dates. |
| 225 | 213 | * |
| 226 | 214 | * @param DateTime|string $date1 Date 1. |
| 227 | 215 | * @param DateTime|string $date2 Date 2. |
| 228 | - * | |
| 229 | 216 | * @return false|int |
| 230 | 217 | */ |
| 231 | 218 | private static function get_date_diff( $date1, $date2 ) { |
| 232 | 219 | $date1 = self::get_date_obj( $date1 ); |
| 233 | - | |
| 234 | 220 | if ( ! $date1 ) { |
| 235 | 221 | return false; |
| 236 | 222 | } |
| 237 | 223 | |
| 238 | 224 | $date2 = self::get_date_obj( $date2 ); |
| 239 | - | |
| 240 | 225 | if ( ! $date2 ) { |
| 241 | 226 | return false; |
| 242 | 227 | } |
| 243 | 228 | |
| @@ -247,14 +232,12 @@ | ||
| 247 | 232 | /** |
| 248 | 233 | * Gets sent date of the last monthly or yearly email. |
| 249 | 234 | * |
| 250 | 235 | * @param string $type Accepts `monthly`, `yearly`. |
| 251 | - * | |
| 252 | 236 | * @return false|string |
| 253 | 237 | */ |
| 254 | 238 | public static function get_last_sent_date( $type ) { |
| 255 | 239 | $options = self::get_options(); |
| 256 | - | |
| 257 | 240 | if ( empty( $options[ 'last_' . $type ] ) ) { |
| 258 | 241 | return false; |
| 259 | 242 | } |
| 260 | 243 | |
| @@ -265,10 +248,8 @@ | ||
| 265 | 248 | * Sets the last sent date of an email type. |
| 266 | 249 | * |
| 267 | 250 | * @param string $type Email type. |
| 268 | 251 | * @param mixed $value Set custom value. If this is null, set the current date. |
| 269 | - * | |
| 270 | - * @return void | |
| 271 | 252 | */ |
| 272 | 253 | public static function set_last_sent_date( $type, $value = null ) { |
| 273 | 254 | $options = self::get_options(); |
| 274 | 255 | |
| @@ -294,9 +275,8 @@ | ||
| 294 | 275 | * Gets payments data. |
| 295 | 276 | * |
| 296 | 277 | * @param string $from_date From date. |
| 297 | 278 | * @param string $to_date To date. |
| 298 | - * | |
| 299 | 279 | * @return array Contains `count` and `total`. |
| 300 | 280 | */ |
| 301 | 281 | public static function get_payments_data( $from_date, $to_date ) { |
| 302 | 282 | $payment = new FrmTransLitePayment(); |
| @@ -307,9 +287,8 @@ | ||
| 307 | 287 | * Gets entries count in a date range. |
| 308 | 288 | * |
| 309 | 289 | * @param string $from_date From date. |
| 310 | 290 | * @param string $to_date To date. |
| 311 | - * | |
| 312 | 291 | * @return int |
| 313 | 292 | */ |
| 314 | 293 | public static function get_entries_count( $from_date, $to_date ) { |
| 315 | 294 | return FrmDb::get_count( |
| @@ -330,9 +309,8 @@ | ||
| 330 | 309 | * |
| 331 | 310 | * @param string $from_date From date. |
| 332 | 311 | * @param string $to_date To date. |
| 333 | 312 | * @param int $limit Limit the result. Default is 5. |
| 334 | - * | |
| 335 | 313 | * @return array Contains `form_id`, `form_name`, and `items_count`. |
| 336 | 314 | */ |
| 337 | 315 | public static function get_top_forms( $from_date, $to_date, $limit = 5 ) { |
| 338 | 316 | global $wpdb; |
| @@ -360,10 +338,8 @@ | ||
| 360 | 338 | /** |
| 361 | 339 | * Shows the comparison HTML in the email. |
| 362 | 340 | * |
| 363 | 341 | * @param float $diff Percentage of difference. |
| 364 | - * | |
| 365 | - * @return void | |
| 366 | 342 | */ |
| 367 | 343 | public static function show_comparison( $diff ) { |
| 368 | 344 | if ( ! $diff ) { |
| 369 | 345 | return; |
| @@ -377,9 +353,8 @@ | ||
| 377 | 353 | $color = '#f04438'; |
| 378 | 354 | } |
| 379 | 355 | |
| 380 | 356 | $displayed_value = round( $diff * 100 ); |
| 381 | - | |
| 382 | 357 | if ( ! $displayed_value ) { |
| 383 | 358 | // Do not show 0 value. |
| 384 | 359 | $displayed_value = $diff > 0 ? 1 : -1; |
| 385 | 360 | } |
| @@ -397,9 +372,8 @@ | ||
| 397 | 372 | /** |
| 398 | 373 | * Gets section CSS in the email. |
| 399 | 374 | * |
| 400 | 375 | * @param string $border_pos Border position. Default is `top`. Set to empty if no border. |
| 401 | - * | |
| 402 | 376 | * @return string |
| 403 | 377 | */ |
| 404 | 378 | public static function get_section_style( $border_pos = 'top' ) { |
| 405 | 379 | if ( $border_pos ) { |
| @@ -421,10 +395,8 @@ | ||
| 421 | 395 | |
| 422 | 396 | /** |
| 423 | 397 | * Gets CSS for button. |
| 424 | 398 | * |
| 425 | - * @param bool $display_block Whether to display the button as block. | |
| 426 | - * | |
| 427 | 399 | * @return string |
| 428 | 400 | */ |
| 429 | 401 | public static function get_button_style( $display_block = false ) { |
| 430 | 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;'; |
| @@ -434,10 +406,8 @@ | ||
| 434 | 406 | * Shows the section heading with icon. |
| 435 | 407 | * |
| 436 | 408 | * @param string $icon Icon file name, without file path and extension. Use .png image. |
| 437 | 409 | * @param string $text Heading text. |
| 438 | - * | |
| 439 | - * @return void | |
| 440 | 410 | */ |
| 441 | 411 | public static function section_heading_with_icon( $icon, $text ) { |
| 442 | 412 | ?> |
| 443 | 413 | <h2 style="<?php echo esc_attr( self::get_heading2_style() ); ?>"> |
| @@ -451,9 +421,8 @@ | ||
| 451 | 421 | * Gets Formidable URL with tracking params. |
| 452 | 422 | * |
| 453 | 423 | * @param string $url The URL. |
| 454 | 424 | * @param array|string $args Custom tracking args if is array, or `utm_content` if is string. |
| 455 | - * | |
| 456 | 425 | * @return string |
| 457 | 426 | */ |
| 458 | 427 | public static function get_frm_url( $url, $args = array() ) { |
| 459 | 428 | if ( is_array( $args ) ) { |
| @@ -481,15 +450,13 @@ | ||
| 481 | 450 | */ |
| 482 | 451 | public static function get_latest_inbox_message() { |
| 483 | 452 | $inbox = new FrmInbox(); |
| 484 | 453 | $messages = $inbox->get_messages( 'filter' ); |
| 485 | - | |
| 486 | 454 | if ( ! $messages || ! is_array( $messages ) ) { |
| 487 | 455 | return false; |
| 488 | 456 | } |
| 489 | 457 | |
| 490 | 458 | $messages = array_reverse( $messages ); |
| 491 | - | |
| 492 | 459 | foreach ( $messages as $message ) { |
| 493 | 460 | if ( 'news' !== $message['type'] ) { |
| 494 | 461 | continue; |
| 495 | 462 | } |
| @@ -506,15 +473,13 @@ | ||
| 506 | 473 | * @return array |
| 507 | 474 | */ |
| 508 | 475 | public static function get_out_of_date_plugins() { |
| 509 | 476 | $update_data = FrmAddonsController::check_update( '' ); |
| 510 | - | |
| 511 | 477 | if ( ! $update_data || ! is_object( $update_data ) || empty( $update_data->response ) ) { |
| 512 | 478 | return array(); |
| 513 | 479 | } |
| 514 | 480 | |
| 515 | 481 | $plugins = array(); |
| 516 | - | |
| 517 | 482 | foreach ( $update_data->response as $plugin_data ) { |
| 518 | 483 | $plugins[] = $plugin_data->display_name; |
| 519 | 484 | } |
| 520 | 485 | |
| @@ -524,9 +489,8 @@ | ||
| 524 | 489 | /** |
| 525 | 490 | * Processes inbox CTA button before showing in email. |
| 526 | 491 | * |
| 527 | 492 | * @param string $button_html Button HTML. This usually contains 1 button and 1 dismiss button. |
| 528 | - * | |
| 529 | 493 | * @return string |
| 530 | 494 | */ |
| 531 | 495 | public static function process_inbox_cta_button( $button_html ) { |
| 532 | 496 | // Remove dismiss button. |
| @@ -551,9 +515,8 @@ | ||
| 551 | 515 | /** |
| 552 | 516 | * Gets the localized date with the date diff from today. |
| 553 | 517 | * |
| 554 | 518 | * @param string $date_diff Date diff string. By default, this is empty, the result will be the current date. |
| 555 | - * | |
| 556 | 519 | * @return string |
| 557 | 520 | */ |
| 558 | 521 | public static function get_date_from_today( $date_diff = '' ) { |
| 559 | 522 | if ( ! $date_diff ) { |
| @@ -567,15 +530,13 @@ | ||
| 567 | 530 | * |
| 568 | 531 | * @since 6.8 |
| 569 | 532 | * |
| 570 | 533 | * @param string $recipients Recipients. |
| 571 | - * | |
| 572 | 534 | * @return void |
| 573 | 535 | */ |
| 574 | 536 | public static function maybe_remove_recipients_from_api( &$recipients ) { |
| 575 | 537 | $api = new FrmFormApi(); |
| 576 | 538 | $addons = $api->get_api_info(); |
| 577 | - | |
| 578 | 539 | if ( empty( $addons['no_emails'] ) ) { |
| 579 | 540 | return; |
| 580 | 541 | } |
| 581 | 542 | |
| @@ -591,10 +552,8 @@ | ||
| 591 | 552 | * |
| 592 | 553 | * @since 6.8 |
| 593 | 554 | * |
| 594 | 555 | * @param string $string string. |
| 595 | - * | |
| 596 | - * @return void | |
| 597 | 556 | */ |
| 598 | 557 | public static function plain_text_echo( $string ) { |
| 599 | 558 | echo wp_strip_all_tags( $string ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 600 | 559 | } |