| @@ -1,17 +1,22 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Base class of LearnPress shortcodes and helper functions. | |
| 3 | + * Class Email. | |
| 4 | 4 | * |
| 5 | 5 | * @author ThimPress |
| 6 | 6 | * @category Widgets |
| 7 | - * @package Learnpress/Shortcodes | |
| 8 | - * @version 3.0.0 | |
| 7 | + * @package Learnpress/Email | |
| 8 | + * @since 3.0.0 | |
| 9 | + * @version 3.0.4 | |
| 9 | 10 | */ |
| 10 | 11 | |
| 11 | 12 | /** |
| 12 | 13 | * Prevent loading this file directly |
| 13 | 14 | */ |
| 15 | + | |
| 16 | +use Pelago\Emogrifier\CssInliner; | |
| 17 | +use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles; | |
| 18 | + | |
| 14 | 19 | defined( 'ABSPATH' ) || exit(); |
| 15 | 20 | |
| 16 | 21 | if ( ! class_exists( 'LP_Email' ) ) { |
| 17 | 22 | |
| @@ -37,9 +42,9 @@ | ||
| 37 | 42 | * 'yes' if the method is enabled. |
| 38 | 43 | * |
| 39 | 44 | * @var string |
| 40 | 45 | */ |
| 41 | - public $enabled; | |
| 46 | + //public $enabled; | |
| 42 | 47 | |
| 43 | 48 | /** |
| 44 | 49 | * Description for the email. |
| 45 | 50 | * |
| @@ -75,11 +80,17 @@ | ||
| 75 | 80 | */ |
| 76 | 81 | public $recipient; |
| 77 | 82 | |
| 78 | 83 | /** |
| 79 | - * For display the field to setting specific emails. | |
| 80 | - * . | |
| 84 | + * @var bool Enable recipients | |
| 81 | 85 | * |
| 86 | + * @since 4.2.6.4 | |
| 87 | + */ | |
| 88 | + public $enable_recipients = false; | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * For send CC or BB email. | |
| 92 | + * | |
| 82 | 93 | * @var string |
| 83 | 94 | */ |
| 84 | 95 | public $recipients = ''; |
| 85 | 96 | |
| @@ -94,9 +105,9 @@ | ||
| 94 | 105 | * Subject for the email. |
| 95 | 106 | * |
| 96 | 107 | * @var string |
| 97 | 108 | */ |
| 98 | - public $subject; | |
| 109 | + public $subject = ''; | |
| 99 | 110 | |
| 100 | 111 | /** |
| 101 | 112 | * Default heading for the email content. |
| 102 | 113 | * |
| @@ -101,9 +112,9 @@ | ||
| 101 | 112 | * Default heading for the email content. |
| 102 | 113 | * |
| 103 | 114 | * @var string |
| 104 | 115 | */ |
| 105 | - public $default_heading; | |
| 116 | + public $default_heading = ''; | |
| 106 | 117 | |
| 107 | 118 | /** |
| 108 | 119 | * Default subject for the email. |
| 109 | 120 | * |
| @@ -108,9 +119,9 @@ | ||
| 108 | 119 | * Default subject for the email. |
| 109 | 120 | * |
| 110 | 121 | * @var string |
| 111 | 122 | */ |
| 112 | - public $default_subject; | |
| 123 | + public $default_subject = ''; | |
| 113 | 124 | |
| 114 | 125 | /** |
| 115 | 126 | * Default content for the email. |
| 116 | 127 | * |
| @@ -255,13 +266,8 @@ | ||
| 255 | 266 | */ |
| 256 | 267 | public $variables = array(); |
| 257 | 268 | |
| 258 | 269 | /** |
| 259 | - * @var array|null | |
| 260 | - */ | |
| 261 | - //public $basic_variables = array(); | |
| 262 | - | |
| 263 | - /** | |
| 264 | 270 | * @var null |
| 265 | 271 | */ |
| 266 | 272 | public $general_variables = []; |
| 267 | 273 | |
| @@ -300,9 +306,9 @@ | ||
| 300 | 306 | */ |
| 301 | 307 | public function __construct() { |
| 302 | 308 | // Set template base path to LP templates path if it is not set. |
| 303 | 309 | if ( empty( $this->template_base ) ) { |
| 304 | - $this->template_base = LP()->plugin_path( 'templates/' ); | |
| 310 | + $this->template_base = LearnPress::instance()->plugin_path( 'templates/' ); | |
| 305 | 311 | } |
| 306 | 312 | |
| 307 | 313 | /** |
| 308 | 314 | * Set template folder if it is not set. Default is 'learnpress' |
| @@ -333,15 +339,15 @@ | ||
| 333 | 339 | $this->heading = $this->settings->get( 'heading', $this->default_heading ); |
| 334 | 340 | $this->subject = $this->settings->get( 'subject', $this->default_subject ); |
| 335 | 341 | $this->enable = $this->settings->get( 'enable', 'no' ) === 'yes'; |
| 336 | 342 | |
| 337 | - if ( $this->settings->get( 'email_content.format' ) ) { | |
| 343 | + /*if ( $this->settings->get( 'email_content.format' ) ) { | |
| 338 | 344 | $this->email_format = ( $this->settings->get( 'email_content.format' ) == 'plain_text' ) ? 'plain' : 'html'; |
| 339 | 345 | } else { |
| 340 | - if ( LP_Settings::instance()->get( 'emails_general.default_email_content' ) ) { | |
| 341 | - $this->email_format = LP_Settings::instance()->get( 'emails_general.default_email_content' ); | |
| 346 | + if ( LP_Settings::instance()->get( 'emails_general.default_email_content', 'html' ) ) { | |
| 347 | + $this->email_format = LP_Settings::instance()->get( 'emails_general.default_email_content', 'html' ); | |
| 342 | 348 | } |
| 343 | - } | |
| 349 | + }*/ | |
| 344 | 350 | |
| 345 | 351 | $email_formats = array( 'plain', 'html' ); |
| 346 | 352 | if ( ! in_array( $this->email_format, $email_formats ) ) { |
| 347 | 353 | $this->email_format = 'html'; |
| @@ -347,13 +353,12 @@ | ||
| 347 | 353 | $this->email_format = 'html'; |
| 348 | 354 | } |
| 349 | 355 | |
| 350 | 356 | // Set type variables can click add to content of email setting. |
| 351 | - $this->support_variables = $this->general_variables = [ | |
| 357 | + $this->support_variables = [ | |
| 352 | 358 | '{{site_url}}', |
| 353 | 359 | '{{site_title}}', |
| 354 | 360 | '{{login_url}}', |
| 355 | - '{{email_heading}}', | |
| 356 | 361 | '{{site_admin_email}}', |
| 357 | 362 | '{{site_admin_name}}', |
| 358 | 363 | '{{header}}', |
| 359 | 364 | '{{footer}}', |
| @@ -358,8 +363,9 @@ | ||
| 358 | 363 | '{{header}}', |
| 359 | 364 | '{{footer}}', |
| 360 | 365 | '{{footer_text}}', |
| 361 | 366 | ]; |
| 367 | + $this->general_variables = $this->support_variables; | |
| 362 | 368 | } |
| 363 | 369 | |
| 364 | 370 | /** |
| 365 | 371 | * @param null $value |
| @@ -410,40 +416,8 @@ | ||
| 410 | 416 | return LP_Settings::instance()->get( $this->_option_id ); |
| 411 | 417 | } |
| 412 | 418 | |
| 413 | 419 | /** |
| 414 | - * @return array|null | |
| 415 | - * | |
| 416 | - * @editor tungnx | |
| 417 | - * @model 4.1.4 comment - not use | |
| 418 | - */ | |
| 419 | - /*public function get_variable() { | |
| 420 | - $this->variables = $this->data_to_variables( $this->object ); | |
| 421 | - | |
| 422 | - return $this->variables; | |
| 423 | - }*/ | |
| 424 | - | |
| 425 | - /** | |
| 426 | - * @param null $object_id | |
| 427 | - * @param array $more | |
| 428 | - * | |
| 429 | - * @return array|object | |
| 430 | - * @editor tungnx | |
| 431 | - * @model 4.1.4 comment - not use | |
| 432 | - */ | |
| 433 | - /*public function get_object( $object_id = null, $more = array() ) { | |
| 434 | - $this->object = $this->get_common_template_data( | |
| 435 | - $this->email_format | |
| 436 | - ); | |
| 437 | - | |
| 438 | - if ( is_array( $more ) ) { | |
| 439 | - $this->object = array_merge( $this->object, $more ); | |
| 440 | - } | |
| 441 | - | |
| 442 | - return $this->object; | |
| 443 | - }*/ | |
| 444 | - | |
| 445 | - /** | |
| 446 | 420 | * Get variables support in mail. |
| 447 | 421 | * |
| 448 | 422 | * @return mixed |
| 449 | 423 | */ |
| @@ -502,17 +476,16 @@ | ||
| 502 | 476 | |
| 503 | 477 | /** |
| 504 | 478 | * Apply the value of variables for string |
| 505 | 479 | * |
| 506 | - * @param string $string | |
| 480 | + * @param string $value | |
| 507 | 481 | * |
| 508 | 482 | * @return string |
| 509 | 483 | * @editor tungnx |
| 510 | 484 | */ |
| 511 | - public function format_string( string $string ): string { | |
| 512 | - //$this->_maybe_get_object(); | |
| 513 | - | |
| 514 | - $search = $replace = array(); | |
| 485 | + public function format_string( string $value ): string { | |
| 486 | + $search = []; | |
| 487 | + $replace = []; | |
| 515 | 488 | if ( is_array( $this->variables ) ) { |
| 516 | 489 | $search = array_keys( $this->variables ); |
| 517 | 490 | $replace = array_values( $this->variables ); |
| 518 | 491 | } |
| @@ -518,9 +491,9 @@ | ||
| 518 | 491 | } |
| 519 | 492 | $search = apply_filters( 'learn-press/email-format-string-find', $search, $this ); |
| 520 | 493 | $replace = apply_filters( 'learn-press/email-format-string-replace', $replace, $this ); |
| 521 | 494 | |
| 522 | - return str_replace( $search, $replace, $string ); | |
| 495 | + return str_replace( $search, $replace, $value ); | |
| 523 | 496 | } |
| 524 | 497 | |
| 525 | 498 | /** |
| 526 | 499 | * Get email recipient. |
| @@ -562,24 +535,8 @@ | ||
| 562 | 535 | return wordwrap( $email_content, 70 ); |
| 563 | 536 | } |
| 564 | 537 | |
| 565 | 538 | /** |
| 566 | - * Try to get object if it is null. | |
| 567 | - * | |
| 568 | - * @editor tungnx | |
| 569 | - * @reason comment - not use | |
| 570 | - */ | |
| 571 | - /*protected function _maybe_get_object() { | |
| 572 | - try { | |
| 573 | - if ( ! $this->_object_loaded && empty( $this->object ) ) { | |
| 574 | - $this->_object_loaded = true; | |
| 575 | - $this->get_object(); | |
| 576 | - } | |
| 577 | - } catch ( Exception $ex ) { | |
| 578 | - } | |
| 579 | - }*/ | |
| 580 | - | |
| 581 | - /** | |
| 582 | 539 | * Get email heading. |
| 583 | 540 | * |
| 584 | 541 | * @return string |
| 585 | 542 | */ |
| @@ -592,9 +549,9 @@ | ||
| 592 | 549 | * |
| 593 | 550 | * @return string |
| 594 | 551 | */ |
| 595 | 552 | public function get_footer_text(): string { |
| 596 | - $text = LP_Settings::instance()->get( 'emails_general.footer_text', 'LearnPress' ); | |
| 553 | + $text = LP_Settings::instance()->get( 'emails_general.footer_text', '' ); | |
| 597 | 554 | |
| 598 | 555 | return LP_Helper::sanitize_params_submitted( $text, 'html' ); |
| 599 | 556 | } |
| 600 | 557 | |
| @@ -640,9 +597,22 @@ | ||
| 640 | 597 | * |
| 641 | 598 | * @return string|array |
| 642 | 599 | */ |
| 643 | 600 | public function get_headers() { |
| 644 | - return apply_filters( 'learn-press/email-headers', 'Content-Type: ' . $this->get_content_format() . "\r\n", $this->id, $this->object ); | |
| 601 | + $headers = [ | |
| 602 | + 'Content-Type: ' . $this->get_content_format() . "\r\n", | |
| 603 | + ]; | |
| 604 | + | |
| 605 | + $recipients = $this->settings->get( 'recipients', $this->recipients ); | |
| 606 | + | |
| 607 | + if ( ! empty( $recipients ) ) { | |
| 608 | + $cc_emails = explode( ',', $recipients ); | |
| 609 | + foreach ( $cc_emails as $cc_email ) { | |
| 610 | + $headers[] = 'Cc: ' . $cc_email; | |
| 611 | + } | |
| 612 | + } | |
| 613 | + | |
| 614 | + return apply_filters( 'learn-press/email-headers', $headers, $this ); | |
| 645 | 615 | } |
| 646 | 616 | |
| 647 | 617 | /** |
| 648 | 618 | * Get email attachments. |
| @@ -681,21 +651,8 @@ | ||
| 681 | 651 | return LP_Helper::sanitize_params_submitted( $name ); |
| 682 | 652 | } |
| 683 | 653 | |
| 684 | 654 | /** |
| 685 | - * Get image header in general settings. | |
| 686 | - * | |
| 687 | - * @return string | |
| 688 | - * @editor tungnx | |
| 689 | - * @reason comment - write new | |
| 690 | - */ | |
| 691 | - /*public function get_image_header() { | |
| 692 | - $image = LP_Emails::instance()->get_image_header(); | |
| 693 | - | |
| 694 | - return apply_filters( 'learn-press/email-image-header-' . $this->id, $image ); | |
| 695 | - }*/ | |
| 696 | - | |
| 697 | - /** | |
| 698 | 655 | * Get WP Blog name. |
| 699 | 656 | * |
| 700 | 657 | * @return string |
| 701 | 658 | */ |
| @@ -733,27 +690,25 @@ | ||
| 733 | 690 | * @param string $content |
| 734 | 691 | * |
| 735 | 692 | * @return string |
| 736 | 693 | */ |
| 737 | - public function apply_style_inline( $content ) { | |
| 738 | - if ( in_array( $this->get_content_format(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) { | |
| 694 | + public function apply_style_inline( $content ): string { | |
| 695 | + try { | |
| 696 | + if ( ! in_array( $this->get_content_format(), array( 'text/html', 'multipart/alternative' ) ) ) { | |
| 697 | + return $content; | |
| 698 | + } | |
| 739 | 699 | |
| 740 | - // get CSS styles | |
| 700 | + // Get CSS styles | |
| 741 | 701 | ob_start(); |
| 742 | 702 | learn_press_get_template( 'emails/email-styles.php' ); |
| 743 | 703 | $css = apply_filters( 'learn_press_email_styles', ob_get_clean(), $this->id, $this ); |
| 744 | 704 | |
| 745 | - try { | |
| 746 | - if ( ! class_exists( 'Emogrifier' ) ) { | |
| 747 | - include_once LP_PLUGIN_PATH . 'inc/libraries/class-emogrifier.php'; | |
| 748 | - } | |
| 749 | - // apply CSS styles inline for picky email clients | |
| 750 | - $emogrifier = new Emogrifier( $content, $css ); | |
| 751 | - $content = $emogrifier->emogrify(); | |
| 705 | + // Apply CSS styles inline for picky email clients | |
| 706 | + //$content = CssInliner::fromHtml( $content )->inlineCss( $css )->render(); | |
| 707 | + $cssToInlineStyles = new CssToInlineStyles(); | |
| 708 | + $content = $cssToInlineStyles->convert( $content, $css ); | |
| 709 | + } catch ( Exception $e ) { | |
| 752 | 710 | |
| 753 | - } catch ( Exception $e ) { | |
| 754 | - | |
| 755 | - } | |
| 756 | 711 | } |
| 757 | 712 | |
| 758 | 713 | return apply_filters( 'learn-press/email-content-inline-style', $content, $this->id ); |
| 759 | 714 | } |
| @@ -808,14 +763,14 @@ | ||
| 808 | 763 | * @param string|array $to |
| 809 | 764 | * @param string $subject |
| 810 | 765 | * @param string $message |
| 811 | 766 | * @param string|string[] $headers |
| 812 | - * @param array $attachments | |
| 767 | + * @param array $attachments | |
| 813 | 768 | * |
| 814 | 769 | * @editor tungnx |
| 770 | + * @return bool | |
| 815 | 771 | * @version 1.0.1 |
| 816 | 772 | * |
| 817 | - * @return bool | |
| 818 | 773 | */ |
| 819 | 774 | public function send( $to, string $subject, string $message, $headers, array $attachments ): bool { |
| 820 | 775 | $return = false; |
| 821 | 776 | $message = apply_filters( 'learn-press/email-content', $this->apply_style_inline( $message ), $this ); |
| @@ -839,90 +794,20 @@ | ||
| 839 | 794 | * @author tungnx |
| 840 | 795 | * @since 4.1.3 |
| 841 | 796 | */ |
| 842 | 797 | public function send_email(): bool { |
| 843 | - // Hooks WP | |
| 844 | 798 | add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) ); |
| 845 | 799 | add_filter( 'wp_mail_content_type', array( $this, 'get_content_format' ) ); |
| 846 | - // End hooks | |
| 847 | 800 | |
| 848 | 801 | return $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); |
| 849 | 802 | } |
| 850 | 803 | |
| 851 | 804 | /** |
| 852 | - * Get format of email template content. | |
| 853 | - * | |
| 854 | - * @param string $format | |
| 855 | - * | |
| 856 | - * @return array | |
| 857 | - */ | |
| 858 | - public function get_template_data( $format = 'plain' ) { | |
| 859 | - | |
| 860 | - return $this->object; | |
| 861 | - // return array( 'plain_text' => $format == 'plain' ); | |
| 862 | - } | |
| 863 | - | |
| 864 | - /** | |
| 865 | - * Get common template data variables. | |
| 866 | - * | |
| 867 | - * @param string $format | |
| 868 | - * | |
| 869 | - * @editor tungnx | |
| 870 | - * @reason move to use method "get_common_variables" | |
| 871 | - * @return array | |
| 872 | - * @deprecated 4.1.3 | |
| 873 | - * @modify 4.1.4 comment - not use | |
| 874 | - */ | |
| 875 | - /*public function get_common_template_data( $format = 'plain' ) { | |
| 876 | - _deprecated_function( __FUNCTION__, '4.1.3', 'get_common_variables' ); | |
| 877 | - $emails = LP_Emails::instance(); | |
| 878 | - $emails->set_current( $this ); | |
| 879 | - | |
| 880 | - $heading = strip_tags( $this->get_heading() ); | |
| 881 | - $footer_text = strip_tags( $this->get_footer_text() ); | |
| 882 | - | |
| 883 | - if ( $format != 'plain' ) { | |
| 884 | - $header = $this->email_header( $heading, false ); | |
| 885 | - $footer = $this->email_footer( $footer_text, false ); | |
| 886 | - } else { | |
| 887 | - $header = $heading; | |
| 888 | - $footer = $footer_text; | |
| 889 | - } | |
| 890 | - | |
| 891 | - $admin_user = get_user_by( 'email', get_option( 'admin_email' ) ); | |
| 892 | - $common = array( | |
| 893 | - 'header' => $header, | |
| 894 | - 'footer' => $footer, | |
| 895 | - 'email_heading' => $heading, | |
| 896 | - 'footer_text' => $footer_text, | |
| 897 | - 'site_url' => get_home_url(), | |
| 898 | - 'site_title' => $this->get_blogname(), | |
| 899 | - 'site_admin_email' => get_option( 'admin_email' ), | |
| 900 | - 'site_admin_name' => learn_press_get_profile_display_name( $admin_user ), | |
| 901 | - 'login_url' => learn_press_get_login_url(), | |
| 902 | - 'plain_text' => $format == 'plain', | |
| 903 | - ); | |
| 904 | - | |
| 905 | - $num = func_num_args(); | |
| 906 | - if ( $num > 1 ) { | |
| 907 | - for ( $i = 1; $i < $num; $i ++ ) { | |
| 908 | - $a = func_get_arg( $i ); | |
| 909 | - if ( is_array( $a ) ) { | |
| 910 | - $common = array_merge( $common, $a ); | |
| 911 | - } | |
| 912 | - } | |
| 913 | - } | |
| 914 | - | |
| 915 | - $emails->reset_current(); | |
| 916 | - | |
| 917 | - return $common; | |
| 918 | - }*/ | |
| 919 | - | |
| 920 | - /** | |
| 921 | 805 | * Get common variables. |
| 922 | 806 | * Variables use for click add to content of Email |
| 923 | 807 | * |
| 924 | 808 | * @param string $format |
| 809 | + * | |
| 925 | 810 | * @return array |
| 926 | 811 | * @author tungnx |
| 927 | 812 | * @since 4.1.1 |
| 928 | 813 | */ |
| @@ -933,13 +818,14 @@ | ||
| 933 | 818 | $header = $heading; |
| 934 | 819 | $footer = $footer_text; |
| 935 | 820 | |
| 936 | 821 | if ( $format != 'plain' ) { |
| 937 | - $header = $this->email_header( $heading, false ); | |
| 938 | - $footer = $this->email_footer( $footer_text, false ); | |
| 822 | + $header = $this->email_header( $heading ); | |
| 823 | + $footer = $this->email_footer( $footer_text ); | |
| 939 | 824 | } |
| 940 | 825 | |
| 941 | 826 | $admin_user = get_user_by( 'email', get_option( 'admin_email' ) ); |
| 827 | + | |
| 942 | 828 | return apply_filters( |
| 943 | 829 | 'email_variables_common', |
| 944 | 830 | [ |
| 945 | 831 | '{{header}}' => $header, |
| @@ -955,51 +841,8 @@ | ||
| 955 | 841 | ); |
| 956 | 842 | } |
| 957 | 843 | |
| 958 | 844 | /** |
| 959 | - * Build list of template variables from an array. | |
| 960 | - * | |
| 961 | - * @param array $data | |
| 962 | - * @editor tungnx | |
| 963 | - * @reason move to use method "map_data_to_variables" | |
| 964 | - * @deprecated 4.1.3 | |
| 965 | - * @return array | |
| 966 | - * @modify 4.1.4 comment - not use | |
| 967 | - */ | |
| 968 | - /*public function data_to_variables( $data = null ) { | |
| 969 | - _deprecated_function( __FUNCTION__, '4.1.3', 'map_data_to_variables' ); | |
| 970 | - if ( ! $data ) { | |
| 971 | - $data = $this->get_common_template_data(); | |
| 972 | - } | |
| 973 | - $variables = array(); | |
| 974 | - if ( is_array( $data ) ) { | |
| 975 | - foreach ( $data as $k => $v ) { | |
| 976 | - $variables[ '{{' . $k . '}}' ] = $v; | |
| 977 | - } | |
| 978 | - } | |
| 979 | - | |
| 980 | - return $variables; | |
| 981 | - }*/ | |
| 982 | - | |
| 983 | - /** | |
| 984 | - * Build list of template variables from an array. | |
| 985 | - * Convert {{name_variable}} to value | |
| 986 | - * | |
| 987 | - * @param array $data | |
| 988 | - */ | |
| 989 | - public function map_data_to_variables( array $data = [] ) { | |
| 990 | - $variables = array(); | |
| 991 | - | |
| 992 | - if ( is_array( $data ) ) { | |
| 993 | - foreach ( $data as $k => $v ) { | |
| 994 | - $variables[ '{{' . $k . '}}' ] = $v; | |
| 995 | - } | |
| 996 | - } | |
| 997 | - | |
| 998 | - $this->variables = $variables; | |
| 999 | - } | |
| 1000 | - | |
| 1001 | - /** | |
| 1002 | 845 | * @param string $name |
| 1003 | 846 | * |
| 1004 | 847 | * @return string |
| 1005 | 848 | */ |
| @@ -1018,9 +861,9 @@ | ||
| 1018 | 861 | * In case the email is not for sending to specific admin (like user who has bought course or author of course, etc..) |
| 1019 | 862 | * So, we do not need this field. |
| 1020 | 863 | */ |
| 1021 | 864 | |
| 1022 | - $enable_recipients = apply_filters( 'learn-press/enable-email-recipients', ! empty( $this->recipients ), $this ); | |
| 865 | + $enable_recipients = $this->enable_recipients; | |
| 1023 | 866 | |
| 1024 | 867 | $default = array_merge( |
| 1025 | 868 | array( |
| 1026 | 869 | array( |
| @@ -1037,11 +880,11 @@ | ||
| 1037 | 880 | $enable_recipients ? array( |
| 1038 | 881 | array( |
| 1039 | 882 | 'title' => esc_html__( 'Recipient(s)', 'learnpress' ), |
| 1040 | 883 | 'type' => 'text', |
| 1041 | - 'default' => get_option( 'admin_email' ), | |
| 884 | + 'default' => $this->recipients, | |
| 1042 | 885 | 'id' => $this->get_field_name( 'recipients' ), |
| 1043 | - 'desc' => esc_html__( 'Separate other recipients by comma.', 'learnpress' ), | |
| 886 | + 'desc' => esc_html__( 'Separate other recipients with commas.', 'learnpress' ), | |
| 1044 | 887 | ), |
| 1045 | 888 | ) : array(), |
| 1046 | 889 | array( |
| 1047 | 890 | array( |
| @@ -1058,9 +901,9 @@ | ||
| 1058 | 901 | 'id' => $this->get_field_name( 'heading' ), |
| 1059 | 902 | 'css' => 'width:400px', |
| 1060 | 903 | ), |
| 1061 | 904 | array( |
| 1062 | - 'title' => esc_html__( 'Content type', 'learnpress' ), | |
| 905 | + 'title' => esc_html__( 'Content', 'learnpress' ), | |
| 1063 | 906 | 'type' => 'email-content', |
| 1064 | 907 | 'default' => '', |
| 1065 | 908 | 'id' => $this->get_field_name( 'email_content' ), |
| 1066 | 909 | 'template_base' => $this->template_base, |
| @@ -1082,11 +925,11 @@ | ||
| 1082 | 925 | |
| 1083 | 926 | /** |
| 1084 | 927 | * Get settings in admin. |
| 1085 | 928 | * |
| 929 | + * @return bool|mixed | |
| 1086 | 930 | * @since 3.0.0 |
| 1087 | 931 | * |
| 1088 | - * @return bool|mixed | |
| 1089 | 932 | */ |
| 1090 | 933 | public function get_settings() { |
| 1091 | 934 | return apply_filters( 'learn-press/email-settings/' . $this->id . '/settings', $this->_default_settings() ); |
| 1092 | 935 | } |
| @@ -1093,13 +936,13 @@ | ||
| 1093 | 936 | |
| 1094 | 937 | /** |
| 1095 | 938 | * Get instructors to send mail. |
| 1096 | 939 | * |
| 1097 | - * @since 3.0.0 | |
| 1098 | - * | |
| 1099 | 940 | * @param null $order_id |
| 1100 | 941 | * |
| 1101 | 942 | * @return array |
| 943 | + * @since 3.0.0 | |
| 944 | + * | |
| 1102 | 945 | */ |
| 1103 | 946 | public function get_order_instructors( $order_id ) { |
| 1104 | 947 | if ( ! $order_id ) { |
| 1105 | 948 | return array(); |
| @@ -1155,13 +998,12 @@ | ||
| 1155 | 998 | /** |
| 1156 | 999 | * Email header. |
| 1157 | 1000 | * |
| 1158 | 1001 | * @param string $heading |
| 1159 | - * @param bool $echo | |
| 1160 | 1002 | * |
| 1161 | 1003 | * @return string |
| 1162 | 1004 | */ |
| 1163 | - public function email_header( string $heading, bool $echo = true ): string { | |
| 1005 | + public function email_header( string $heading ): string { | |
| 1164 | 1006 | ob_start(); |
| 1165 | 1007 | learn_press_get_template( |
| 1166 | 1008 | 'emails/email-header.php', |
| 1167 | 1009 | [ |
| @@ -1168,15 +1010,10 @@ | ||
| 1168 | 1010 | 'email_heading' => $heading, |
| 1169 | 1011 | 'image_header' => $this->get_image_header(), |
| 1170 | 1012 | ] |
| 1171 | 1013 | ); |
| 1172 | - $header = ob_get_clean(); | |
| 1173 | 1014 | |
| 1174 | - if ( $echo ) { | |
| 1175 | - echo wp_kses_post( $header ); | |
| 1176 | - } | |
| 1177 | - | |
| 1178 | - return $header; | |
| 1015 | + return ob_get_clean(); | |
| 1179 | 1016 | } |
| 1180 | 1017 | |
| 1181 | 1018 | /** |
| 1182 | 1019 | * Email footer. |
| @@ -1181,22 +1018,16 @@ | ||
| 1181 | 1018 | /** |
| 1182 | 1019 | * Email footer. |
| 1183 | 1020 | * |
| 1184 | 1021 | * @param string $footer_text |
| 1185 | - * @param bool $echo | |
| 1186 | 1022 | * |
| 1187 | 1023 | * @return string |
| 1188 | 1024 | */ |
| 1189 | - public function email_footer( string $footer_text, bool $echo = true ): string { | |
| 1025 | + public function email_footer( string $footer_text ): string { | |
| 1190 | 1026 | ob_start(); |
| 1191 | 1027 | learn_press_get_template( 'emails/email-footer.php', array( 'footer_text' => $footer_text ) ); |
| 1192 | - $footer = ob_get_clean(); | |
| 1193 | 1028 | |
| 1194 | - if ( $echo ) { | |
| 1195 | - echo wp_kses_post( $footer ); | |
| 1196 | - } | |
| 1197 | - | |
| 1198 | - return $footer; | |
| 1029 | + return ob_get_clean(); | |
| 1199 | 1030 | } |
| 1200 | 1031 | |
| 1201 | 1032 | /** |
| 1202 | 1033 | * Set receive email |
| @@ -1208,13 +1039,14 @@ | ||
| 1208 | 1039 | } |
| 1209 | 1040 | |
| 1210 | 1041 | /** |
| 1211 | 1042 | * Method called by background on LP_Background_Single_Email |
| 1043 | + * | |
| 1044 | + * @param array $params | |
| 1045 | + * | |
| 1212 | 1046 | * @see LP_Background_Single_Email::handle() |
| 1213 | 1047 | * |
| 1214 | - * @param array $params | |
| 1215 | 1048 | */ |
| 1216 | 1049 | public function handle( array $params ) { |
| 1217 | - | |
| 1218 | 1050 | } |
| 1219 | 1051 | } |
| 1220 | 1052 | } |