PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
← All changes | inc/emails/class-lp-email.php +75 -98 4.1.74.4.8 View file →
@@ -5,14 +5,18 @@
5 5 * @author ThimPress
6 6 * @category Widgets
7 7 * @package Learnpress/Email
8 8 * @since 3.0.0
9 - * @version 3.0.2
9 + * @version 3.0.4
10 10 */
11 11
12 12 /**
13 13 * Prevent loading this file directly
14 14 */
15 +
16 +use Pelago\Emogrifier\CssInliner;
17 +use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;
18 +
15 19 defined( 'ABSPATH' ) || exit();
16 20
17 21 if ( ! class_exists( 'LP_Email' ) ) {
18 22
@@ -38,9 +42,9 @@
38 42 * 'yes' if the method is enabled.
39 43 *
40 44 * @var string
41 45 */
42 - public $enabled;
46 + //public $enabled;
43 47
44 48 /**
45 49 * Description for the email.
46 50 *
@@ -76,11 +80,17 @@
76 80 */
77 81 public $recipient;
78 82
79 83 /**
80 - * For display the field to setting specific emails.
81 - * .
84 + * @var bool Enable recipients
82 85 *
86 + * @since 4.2.6.4
87 + */
88 + public $enable_recipients = false;
89 +
90 + /**
91 + * For send CC or BB email.
92 + *
83 93 * @var string
84 94 */
85 95 public $recipients = '';
86 96
@@ -95,9 +105,9 @@
95 105 * Subject for the email.
96 106 *
97 107 * @var string
98 108 */
99 - public $subject;
109 + public $subject = '';
100 110
101 111 /**
102 112 * Default heading for the email content.
103 113 *
@@ -102,9 +112,9 @@
102 112 * Default heading for the email content.
103 113 *
104 114 * @var string
105 115 */
106 - public $default_heading;
116 + public $default_heading = '';
107 117
108 118 /**
109 119 * Default subject for the email.
110 120 *
@@ -109,9 +119,9 @@
109 119 * Default subject for the email.
110 120 *
111 121 * @var string
112 122 */
113 - public $default_subject;
123 + public $default_subject = '';
114 124
115 125 /**
116 126 * Default content for the email.
117 127 *
@@ -256,13 +266,8 @@
256 266 */
257 267 public $variables = array();
258 268
259 269 /**
260 - * @var array|null
261 - */
262 - //public $basic_variables = array();
263 -
264 - /**
265 270 * @var null
266 271 */
267 272 public $general_variables = [];
268 273
@@ -301,9 +306,9 @@
301 306 */
302 307 public function __construct() {
303 308 // Set template base path to LP templates path if it is not set.
304 309 if ( empty( $this->template_base ) ) {
305 - $this->template_base = LP()->plugin_path( 'templates/' );
310 + $this->template_base = LearnPress::instance()->plugin_path( 'templates/' );
306 311 }
307 312
308 313 /**
309 314 * Set template folder if it is not set. Default is 'learnpress'
@@ -334,15 +339,15 @@
334 339 $this->heading = $this->settings->get( 'heading', $this->default_heading );
335 340 $this->subject = $this->settings->get( 'subject', $this->default_subject );
336 341 $this->enable = $this->settings->get( 'enable', 'no' ) === 'yes';
337 342
338 - if ( $this->settings->get( 'email_content.format' ) ) {
343 + /*if ( $this->settings->get( 'email_content.format' ) ) {
339 344 $this->email_format = ( $this->settings->get( 'email_content.format' ) == 'plain_text' ) ? 'plain' : 'html';
340 345 } else {
341 - if ( LP_Settings::instance()->get( 'emails_general.default_email_content' ) ) {
342 - $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' );
343 348 }
344 - }
349 + }*/
345 350
346 351 $email_formats = array( 'plain', 'html' );
347 352 if ( ! in_array( $this->email_format, $email_formats ) ) {
348 353 $this->email_format = 'html';
@@ -348,13 +353,12 @@
348 353 $this->email_format = 'html';
349 354 }
350 355
351 356 // Set type variables can click add to content of email setting.
352 - $this->support_variables = $this->general_variables = [
357 + $this->support_variables = [
353 358 '{{site_url}}',
354 359 '{{site_title}}',
355 360 '{{login_url}}',
356 - '{{email_heading}}',
357 361 '{{site_admin_email}}',
358 362 '{{site_admin_name}}',
359 363 '{{header}}',
360 364 '{{footer}}',
@@ -359,8 +363,9 @@
359 363 '{{header}}',
360 364 '{{footer}}',
361 365 '{{footer_text}}',
362 366 ];
367 + $this->general_variables = $this->support_variables;
363 368 }
364 369
365 370 /**
366 371 * @param null $value
@@ -471,17 +476,16 @@
471 476
472 477 /**
473 478 * Apply the value of variables for string
474 479 *
475 - * @param string $string
480 + * @param string $value
476 481 *
477 482 * @return string
478 483 * @editor tungnx
479 484 */
480 - public function format_string( string $string ): string {
481 - //$this->_maybe_get_object();
482 -
483 - $search = $replace = array();
485 + public function format_string( string $value ): string {
486 + $search = [];
487 + $replace = [];
484 488 if ( is_array( $this->variables ) ) {
485 489 $search = array_keys( $this->variables );
486 490 $replace = array_values( $this->variables );
487 491 }
@@ -487,9 +491,9 @@
487 491 }
488 492 $search = apply_filters( 'learn-press/email-format-string-find', $search, $this );
489 493 $replace = apply_filters( 'learn-press/email-format-string-replace', $replace, $this );
490 494
491 - return str_replace( $search, $replace, $string );
495 + return str_replace( $search, $replace, $value );
492 496 }
493 497
494 498 /**
495 499 * Get email recipient.
@@ -531,24 +535,8 @@
531 535 return wordwrap( $email_content, 70 );
532 536 }
533 537
534 538 /**
535 - * Try to get object if it is null.
536 - *
537 - * @editor tungnx
538 - * @reason comment - not use
539 - */
540 - /*protected function _maybe_get_object() {
541 - try {
542 - if ( ! $this->_object_loaded && empty( $this->object ) ) {
543 - $this->_object_loaded = true;
544 - $this->get_object();
545 - }
546 - } catch ( Exception $ex ) {
547 - }
548 - }*/
549 -
550 - /**
551 539 * Get email heading.
552 540 *
553 541 * @return string
554 542 */
@@ -561,9 +549,9 @@
561 549 *
562 550 * @return string
563 551 */
564 552 public function get_footer_text(): string {
565 - $text = LP_Settings::instance()->get( 'emails_general.footer_text', 'LearnPress' );
553 + $text = LP_Settings::instance()->get( 'emails_general.footer_text', '' );
566 554
567 555 return LP_Helper::sanitize_params_submitted( $text, 'html' );
568 556 }
569 557
@@ -609,9 +597,22 @@
609 597 *
610 598 * @return string|array
611 599 */
612 600 public function get_headers() {
613 - 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 );
614 615 }
615 616
616 617 /**
617 618 * Get email attachments.
@@ -650,21 +651,8 @@
650 651 return LP_Helper::sanitize_params_submitted( $name );
651 652 }
652 653
653 654 /**
654 - * Get image header in general settings.
655 - *
656 - * @return string
657 - * @editor tungnx
658 - * @reason comment - write new
659 - */
660 - /*public function get_image_header() {
661 - $image = LP_Emails::instance()->get_image_header();
662 -
663 - return apply_filters( 'learn-press/email-image-header-' . $this->id, $image );
664 - }*/
665 -
666 - /**
667 655 * Get WP Blog name.
668 656 *
669 657 * @return string
670 658 */
@@ -702,27 +690,25 @@
702 690 * @param string $content
703 691 *
704 692 * @return string
705 693 */
706 - public function apply_style_inline( $content ) {
707 - 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 + }
708 699
709 - // get CSS styles
700 + // Get CSS styles
710 701 ob_start();
711 702 learn_press_get_template( 'emails/email-styles.php' );
712 703 $css = apply_filters( 'learn_press_email_styles', ob_get_clean(), $this->id, $this );
713 704
714 - try {
715 - if ( ! class_exists( 'Emogrifier' ) ) {
716 - include_once LP_PLUGIN_PATH . 'inc/libraries/class-emogrifier.php';
717 - }
718 - // apply CSS styles inline for picky email clients
719 - $emogrifier = new Emogrifier( $content, $css );
720 - $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 ) {
721 710
722 - } catch ( Exception $e ) {
723 -
724 - }
725 711 }
726 712
727 713 return apply_filters( 'learn-press/email-content-inline-style', $content, $this->id );
728 714 }
@@ -777,14 +763,14 @@
777 763 * @param string|array $to
778 764 * @param string $subject
779 765 * @param string $message
780 766 * @param string|string[] $headers
781 - * @param array $attachments
767 + * @param array $attachments
782 768 *
783 769 * @editor tungnx
770 + * @return bool
784 771 * @version 1.0.1
785 772 *
786 - * @return bool
787 773 */
788 774 public function send( $to, string $subject, string $message, $headers, array $attachments ): bool {
789 775 $return = false;
790 776 $message = apply_filters( 'learn-press/email-content', $this->apply_style_inline( $message ), $this );
@@ -819,8 +805,9 @@
819 805 * Get common variables.
820 806 * Variables use for click add to content of Email
821 807 *
822 808 * @param string $format
809 + *
823 810 * @return array
824 811 * @author tungnx
825 812 * @since 4.1.1
826 813 */
@@ -831,13 +818,14 @@
831 818 $header = $heading;
832 819 $footer = $footer_text;
833 820
834 821 if ( $format != 'plain' ) {
835 - $header = $this->email_header( $heading, false );
836 - $footer = $this->email_footer( $footer_text, false );
822 + $header = $this->email_header( $heading );
823 + $footer = $this->email_footer( $footer_text );
837 824 }
838 825
839 826 $admin_user = get_user_by( 'email', get_option( 'admin_email' ) );
827 +
840 828 return apply_filters(
841 829 'email_variables_common',
842 830 [
843 831 '{{header}}' => $header,
@@ -873,9 +861,9 @@
873 861 * In case the email is not for sending to specific admin (like user who has bought course or author of course, etc..)
874 862 * So, we do not need this field.
875 863 */
876 864
877 - $enable_recipients = apply_filters( 'learn-press/enable-email-recipients', ! empty( $this->recipients ), $this );
865 + $enable_recipients = $this->enable_recipients;
878 866
879 867 $default = array_merge(
880 868 array(
881 869 array(
@@ -892,11 +880,11 @@
892 880 $enable_recipients ? array(
893 881 array(
894 882 'title' => esc_html__( 'Recipient(s)', 'learnpress' ),
895 883 'type' => 'text',
896 - 'default' => get_option( 'admin_email' ),
884 + 'default' => $this->recipients,
897 885 'id' => $this->get_field_name( 'recipients' ),
898 - 'desc' => esc_html__( 'Separate other recipients by comma.', 'learnpress' ),
886 + 'desc' => esc_html__( 'Separate other recipients with commas.', 'learnpress' ),
899 887 ),
900 888 ) : array(),
901 889 array(
902 890 array(
@@ -913,9 +901,9 @@
913 901 'id' => $this->get_field_name( 'heading' ),
914 902 'css' => 'width:400px',
915 903 ),
916 904 array(
917 - 'title' => esc_html__( 'Content type', 'learnpress' ),
905 + 'title' => esc_html__( 'Content', 'learnpress' ),
918 906 'type' => 'email-content',
919 907 'default' => '',
920 908 'id' => $this->get_field_name( 'email_content' ),
921 909 'template_base' => $this->template_base,
@@ -937,11 +925,11 @@
937 925
938 926 /**
939 927 * Get settings in admin.
940 928 *
929 + * @return bool|mixed
941 930 * @since 3.0.0
942 931 *
943 - * @return bool|mixed
944 932 */
945 933 public function get_settings() {
946 934 return apply_filters( 'learn-press/email-settings/' . $this->id . '/settings', $this->_default_settings() );
947 935 }
@@ -948,13 +936,13 @@
948 936
949 937 /**
950 938 * Get instructors to send mail.
951 939 *
952 - * @since 3.0.0
953 - *
954 940 * @param null $order_id
955 941 *
956 942 * @return array
943 + * @since 3.0.0
944 + *
957 945 */
958 946 public function get_order_instructors( $order_id ) {
959 947 if ( ! $order_id ) {
960 948 return array();
@@ -1010,13 +998,12 @@
1010 998 /**
1011 999 * Email header.
1012 1000 *
1013 1001 * @param string $heading
1014 - * @param bool $echo
1015 1002 *
1016 1003 * @return string
1017 1004 */
1018 - public function email_header( string $heading, bool $echo = true ): string {
1005 + public function email_header( string $heading ): string {
1019 1006 ob_start();
1020 1007 learn_press_get_template(
1021 1008 'emails/email-header.php',
1022 1009 [
@@ -1023,15 +1010,10 @@
1023 1010 'email_heading' => $heading,
1024 1011 'image_header' => $this->get_image_header(),
1025 1012 ]
1026 1013 );
1027 - $header = ob_get_clean();
1028 1014
1029 - if ( $echo ) {
1030 - echo wp_kses_post( $header );
1031 - }
1032 -
1033 - return $header;
1015 + return ob_get_clean();
1034 1016 }
1035 1017
1036 1018 /**
1037 1019 * Email footer.
@@ -1036,22 +1018,16 @@
1036 1018 /**
1037 1019 * Email footer.
1038 1020 *
1039 1021 * @param string $footer_text
1040 - * @param bool $echo
1041 1022 *
1042 1023 * @return string
1043 1024 */
1044 - public function email_footer( string $footer_text, bool $echo = true ): string {
1025 + public function email_footer( string $footer_text ): string {
1045 1026 ob_start();
1046 1027 learn_press_get_template( 'emails/email-footer.php', array( 'footer_text' => $footer_text ) );
1047 - $footer = ob_get_clean();
1048 1028
1049 - if ( $echo ) {
1050 - echo wp_kses_post( $footer );
1051 - }
1052 -
1053 - return $footer;
1029 + return ob_get_clean();
1054 1030 }
1055 1031
1056 1032 /**
1057 1033 * Set receive email
@@ -1063,13 +1039,14 @@
1063 1039 }
1064 1040
1065 1041 /**
1066 1042 * Method called by background on LP_Background_Single_Email
1043 + *
1044 + * @param array $params
1045 + *
1067 1046 * @see LP_Background_Single_Email::handle()
1068 1047 *
1069 - * @param array $params
1070 1048 */
1071 1049 public function handle( array $params ) {
1072 -
1073 1050 }
1074 1051 }
1075 1052 }