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 +73 -67 4.2.04.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
@@ -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.
@@ -545,9 +549,9 @@
545 549 *
546 550 * @return string
547 551 */
548 552 public function get_footer_text(): string {
549 - $text = LP_Settings::instance()->get( 'emails_general.footer_text', 'LearnPress' );
553 + $text = LP_Settings::instance()->get( 'emails_general.footer_text', '' );
550 554
551 555 return LP_Helper::sanitize_params_submitted( $text, 'html' );
552 556 }
553 557
@@ -593,9 +597,22 @@
593 597 *
594 598 * @return string|array
595 599 */
596 600 public function get_headers() {
597 - 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 );
598 615 }
599 616
600 617 /**
601 618 * Get email attachments.
@@ -673,27 +690,25 @@
673 690 * @param string $content
674 691 *
675 692 * @return string
676 693 */
677 - public function apply_style_inline( $content ) {
678 - 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 + }
679 699
680 - // get CSS styles
700 + // Get CSS styles
681 701 ob_start();
682 702 learn_press_get_template( 'emails/email-styles.php' );
683 703 $css = apply_filters( 'learn_press_email_styles', ob_get_clean(), $this->id, $this );
684 704
685 - try {
686 - if ( ! class_exists( 'Emogrifier' ) ) {
687 - include_once LP_PLUGIN_PATH . 'inc/libraries/class-emogrifier.php';
688 - }
689 - // apply CSS styles inline for picky email clients
690 - $emogrifier = new Emogrifier( $content, $css );
691 - $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 ) {
692 710
693 - } catch ( Exception $e ) {
694 -
695 - }
696 711 }
697 712
698 713 return apply_filters( 'learn-press/email-content-inline-style', $content, $this->id );
699 714 }
@@ -748,14 +763,14 @@
748 763 * @param string|array $to
749 764 * @param string $subject
750 765 * @param string $message
751 766 * @param string|string[] $headers
752 - * @param array $attachments
767 + * @param array $attachments
753 768 *
754 769 * @editor tungnx
770 + * @return bool
755 771 * @version 1.0.1
756 772 *
757 - * @return bool
758 773 */
759 774 public function send( $to, string $subject, string $message, $headers, array $attachments ): bool {
760 775 $return = false;
761 776 $message = apply_filters( 'learn-press/email-content', $this->apply_style_inline( $message ), $this );
@@ -790,8 +805,9 @@
790 805 * Get common variables.
791 806 * Variables use for click add to content of Email
792 807 *
793 808 * @param string $format
809 + *
794 810 * @return array
795 811 * @author tungnx
796 812 * @since 4.1.1
797 813 */
@@ -802,13 +818,14 @@
802 818 $header = $heading;
803 819 $footer = $footer_text;
804 820
805 821 if ( $format != 'plain' ) {
806 - $header = $this->email_header( $heading, false );
807 - $footer = $this->email_footer( $footer_text, false );
822 + $header = $this->email_header( $heading );
823 + $footer = $this->email_footer( $footer_text );
808 824 }
809 825
810 826 $admin_user = get_user_by( 'email', get_option( 'admin_email' ) );
827 +
811 828 return apply_filters(
812 829 'email_variables_common',
813 830 [
814 831 '{{header}}' => $header,
@@ -844,9 +861,9 @@
844 861 * In case the email is not for sending to specific admin (like user who has bought course or author of course, etc..)
845 862 * So, we do not need this field.
846 863 */
847 864
848 - $enable_recipients = apply_filters( 'learn-press/enable-email-recipients', ! empty( $this->recipients ), $this );
865 + $enable_recipients = $this->enable_recipients;
849 866
850 867 $default = array_merge(
851 868 array(
852 869 array(
@@ -863,9 +880,9 @@
863 880 $enable_recipients ? array(
864 881 array(
865 882 'title' => esc_html__( 'Recipient(s)', 'learnpress' ),
866 883 'type' => 'text',
867 - 'default' => get_option( 'admin_email' ),
884 + 'default' => $this->recipients,
868 885 'id' => $this->get_field_name( 'recipients' ),
869 886 'desc' => esc_html__( 'Separate other recipients with commas.', 'learnpress' ),
870 887 ),
871 888 ) : array(),
@@ -884,9 +901,9 @@
884 901 'id' => $this->get_field_name( 'heading' ),
885 902 'css' => 'width:400px',
886 903 ),
887 904 array(
888 - 'title' => esc_html__( 'Content type', 'learnpress' ),
905 + 'title' => esc_html__( 'Content', 'learnpress' ),
889 906 'type' => 'email-content',
890 907 'default' => '',
891 908 'id' => $this->get_field_name( 'email_content' ),
892 909 'template_base' => $this->template_base,
@@ -908,11 +925,11 @@
908 925
909 926 /**
910 927 * Get settings in admin.
911 928 *
929 + * @return bool|mixed
912 930 * @since 3.0.0
913 931 *
914 - * @return bool|mixed
915 932 */
916 933 public function get_settings() {
917 934 return apply_filters( 'learn-press/email-settings/' . $this->id . '/settings', $this->_default_settings() );
918 935 }
@@ -919,13 +936,13 @@
919 936
920 937 /**
921 938 * Get instructors to send mail.
922 939 *
923 - * @since 3.0.0
924 - *
925 940 * @param null $order_id
926 941 *
927 942 * @return array
943 + * @since 3.0.0
944 + *
928 945 */
929 946 public function get_order_instructors( $order_id ) {
930 947 if ( ! $order_id ) {
931 948 return array();
@@ -981,13 +998,12 @@
981 998 /**
982 999 * Email header.
983 1000 *
984 1001 * @param string $heading
985 - * @param bool $echo
986 1002 *
987 1003 * @return string
988 1004 */
989 - public function email_header( string $heading, bool $echo = true ): string {
1005 + public function email_header( string $heading ): string {
990 1006 ob_start();
991 1007 learn_press_get_template(
992 1008 'emails/email-header.php',
993 1009 [
@@ -994,15 +1010,10 @@
994 1010 'email_heading' => $heading,
995 1011 'image_header' => $this->get_image_header(),
996 1012 ]
997 1013 );
998 - $header = ob_get_clean();
999 1014
1000 - if ( $echo ) {
1001 - echo wp_kses_post( $header );
1002 - }
1003 -
1004 - return $header;
1015 + return ob_get_clean();
1005 1016 }
1006 1017
1007 1018 /**
1008 1019 * Email footer.
@@ -1007,22 +1018,16 @@
1007 1018 /**
1008 1019 * Email footer.
1009 1020 *
1010 1021 * @param string $footer_text
1011 - * @param bool $echo
1012 1022 *
1013 1023 * @return string
1014 1024 */
1015 - public function email_footer( string $footer_text, bool $echo = true ): string {
1025 + public function email_footer( string $footer_text ): string {
1016 1026 ob_start();
1017 1027 learn_press_get_template( 'emails/email-footer.php', array( 'footer_text' => $footer_text ) );
1018 - $footer = ob_get_clean();
1019 1028
1020 - if ( $echo ) {
1021 - echo wp_kses_post( $footer );
1022 - }
1023 -
1024 - return $footer;
1029 + return ob_get_clean();
1025 1030 }
1026 1031
1027 1032 /**
1028 1033 * Set receive email
@@ -1034,13 +1039,14 @@
1034 1039 }
1035 1040
1036 1041 /**
1037 1042 * Method called by background on LP_Background_Single_Email
1043 + *
1044 + * @param array $params
1045 + *
1038 1046 * @see LP_Background_Single_Email::handle()
1039 1047 *
1040 - * @param array $params
1041 1048 */
1042 1049 public function handle( array $params ) {
1043 -
1044 1050 }
1045 1051 }
1046 1052 }