Changeset 2596119
- Timestamp:
- 09/09/2021 10:18:38 AM (5 years ago)
- Location:
- juvo-mail-editor
- Files:
-
- 4 added
- 16 edited
- 1 copied
-
tags/2.0.8 (copied) (copied from juvo-mail-editor/trunk)
-
tags/2.0.8/juvo-mail-editor.php (modified) (1 diff)
-
tags/2.0.8/readme.txt (modified) (1 diff)
-
tags/2.0.8/src/Integrations/BuddyBoss.php (modified) (1 diff)
-
tags/2.0.8/src/Mail_Editor.php (modified) (3 diffs)
-
tags/2.0.8/src/Mails/New_User.php (modified) (1 diff)
-
tags/2.0.8/src/Mails/New_User_Admin.php (modified) (1 diff)
-
tags/2.0.8/src/Mails/Password_Changed.php (added)
-
tags/2.0.8/src/Mails/Password_Changed_Admin.php (added)
-
tags/2.0.8/src/Mails/Password_Reset.php (modified) (2 diffs)
-
tags/2.0.8/src/Relay.php (modified) (4 diffs)
-
trunk/juvo-mail-editor.php (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/src/Integrations/BuddyBoss.php (modified) (1 diff)
-
trunk/src/Mail_Editor.php (modified) (3 diffs)
-
trunk/src/Mails/New_User.php (modified) (1 diff)
-
trunk/src/Mails/New_User_Admin.php (modified) (1 diff)
-
trunk/src/Mails/Password_Changed.php (added)
-
trunk/src/Mails/Password_Changed_Admin.php (added)
-
trunk/src/Mails/Password_Reset.php (modified) (2 diffs)
-
trunk/src/Relay.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
juvo-mail-editor/tags/2.0.8/juvo-mail-editor.php
r2595821 r2596119 8 8 * Text Domain: juvo-mail-editor 9 9 * Domain Path: /languages 10 * Version: 2.0. 710 * Version: 2.0.8 11 11 */ 12 12 -
juvo-mail-editor/tags/2.0.8/readme.txt
r2595821 r2596119 4 4 License: GPLv2 or later 5 5 Tested up to: 5.8 6 Stable tag: 2.0. 76 Stable tag: 2.0.8 7 7 8 8 JUVO Mail Editor helps to modify the standard WordPress Mailings and allows adding dynamic mail triggers. -
juvo-mail-editor/tags/2.0.8/src/Integrations/BuddyBoss.php
r2578743 r2596119 5 5 class BuddyBoss { 6 6 7 public function useTemplate( string $content, string $trigger, $context ){7 public function useTemplate( array $args ): array { 8 8 if ( function_exists( 'bp_is_active' ) ) { 9 /** @phpstan-ignore-next-line */ 10 return bp_email_core_wp_get_template( $content, $context ); 9 // BoddyBoss might have already applied the template 10 if ( isset( $args["message"] ) && strpos( $args["message"], '<!DOCTYPE html>' ) === false ) { 11 /** @phpstan-ignore-next-line */ 12 $args["message"] = bp_email_core_wp_get_template( $args["message"] ); 13 } 11 14 } 12 15 13 return $ content;16 return $args; 14 17 } 15 18 -
juvo-mail-editor/tags/2.0.8/src/Mail_Editor.php
r2587510 r2596119 11 11 use JUVO_MailEditor\Mails\New_User_Admin_Rest; 12 12 use JUVO_MailEditor\Mails\New_User_Rest; 13 use JUVO_MailEditor\Mails\Password_Changed; 14 use JUVO_MailEditor\Mails\Password_Changed_Admin; 13 15 use JUVO_MailEditor\Mails\Password_Reset; 14 16 use JUVO_MailEditor\Mails\Password_Reset_Admin; … … 152 154 $this->loader->add_filter( "juvo_mail_editor_trigger", $passwordReset, "registerTrigger" ); 153 155 $this->loader->add_filter( "juvo_mail_editor_post_metabox", $passwordReset, "addCustomFields" ); 154 155 156 $this->loader->add_filter( 'retrieve_password_message', $passwordReset, 'password_reset_email_message', 10, 4 ); 156 $this->loader->add_filter( 'retrieve_password_title', $passwordReset, 'password_reset_email_subject', 10, 4 );157 157 158 158 /** … … 162 162 $this->loader->add_filter( "juvo_mail_editor_trigger", $passwordResetAdmin, "registerTrigger" ); 163 163 $this->loader->add_filter( "juvo_mail_editor_post_metabox", $passwordResetAdmin, "addCustomFields" ); 164 165 164 $this->loader->add_filter( "retrieve_password_message", $passwordResetAdmin, "password_reset_email_admin", 99, 4 ); 166 165 166 /** 167 * Password Changed 168 */ 169 $passwordChanged = new Password_Changed(); 170 $this->loader->add_filter( "juvo_mail_editor_trigger", $passwordChanged, "registerTrigger" ); 171 $this->loader->add_filter( "juvo_mail_editor_post_metabox", $passwordChanged, "addCustomFields" ); 172 $this->loader->add_filter( 'password_change_email', $passwordChanged, 'password_changed_email', 10, 2 ); 173 174 /** 175 * Password Changed Admin 176 */ 177 $passwordChangedAdmin = new Password_Changed_Admin(); 178 $this->loader->add_filter( "juvo_mail_editor_trigger", $passwordChangedAdmin, "registerTrigger" ); 179 $this->loader->add_filter( "juvo_mail_editor_post_metabox", $passwordChangedAdmin, "addCustomFields" ); 180 $this->loader->add_filter( 'wp_password_change_notification_email', $passwordChangedAdmin, 'password_changed_admin_email', 10, 2 ); 181 167 182 168 183 /** 169 184 * Integrations 170 185 */ 171 $this->loader->add_filter( "juvo_mail_editor_after_content_placeholder", new BuddyBoss(), "useTemplate", 10, 3 ); 172 186 $this->loader->add_filter( "wp_mail", new BuddyBoss(), "useTemplate", 99, 1 ); 173 187 } 174 188 -
juvo-mail-editor/tags/2.0.8/src/Mails/New_User.php
r2595821 r2596119 25 25 public function new_user_notification_email( array $email, WP_User $user ): array { 26 26 27 // Add Muted Capability28 if ( Relay::triggerIsMuted( $this->getTrigger() ) ) {29 return [];30 }31 32 27 $this->setPlaceholderValues( $user ); 33 28 34 $relay = new Relay( $this->getTrigger(), $this->placeholders, $user );35 $ template = $relay->getPosts();29 $relay = new Relay( $this->getTrigger(), $this->placeholders, $user ); 30 $relay->sendMails(); 36 31 37 if ( ! empty( $template ) ) { 38 $email["to"] = $relay->prepareRecipients( $template[0] ); 39 $email["subject"] = $relay->prepareSubject( $template[0] ); 40 $email["message"] = $relay->prepareContent( $template[0] ); 41 } 42 43 return $email; 32 return []; 44 33 } 45 34 -
juvo-mail-editor/tags/2.0.8/src/Mails/New_User_Admin.php
r2595821 r2596119 15 15 function new_user_notification_email_admin( array $email, WP_User $user ): array { 16 16 17 // Add Muted Capability18 if ( Relay::triggerIsMuted( $this->getTrigger() ) ) {19 return [];20 }21 22 17 $this->setPlaceholderValues( $user ); 23 18 24 $relay = new Relay( $this->getTrigger(), $this->placeholders, $user );25 $ template = $relay->getPosts();19 $relay = new Relay( $this->getTrigger(), $this->placeholders, $user ); 20 $relay->sendMails(); 26 21 27 if ( ! empty( $template ) ) { 28 $email["to"] = $relay->prepareRecipients( $template[0] ); 29 $email["subject"] = $relay->prepareSubject( $template[0] ); 30 $email["message"] = $relay->prepareContent( $template[0] ); 31 } 32 33 return $email; 22 return []; 34 23 } 35 24 -
juvo-mail-editor/tags/2.0.8/src/Mails/Password_Reset.php
r2594645 r2596119 19 19 ]; 20 20 21 /** 22 * @param string $message 23 * @param string $key 24 * @param string $user_login 25 * @param WP_User $user 26 * 27 * @return string Empty string to prevent default wordpress mail from being sent 28 */ 21 29 function password_reset_email_message( string $message, string $key, string $user_login, WP_User $user ): string { 22 23 // Add Muted Capability24 if ( Relay::triggerIsMuted( $this->getTrigger() ) ) {25 return "";26 }27 30 28 31 $this->setPlaceholderValues( $user, [ "key" => $key ] ); 29 32 30 $relay = new Relay( $this->getTrigger(), $this->placeholders, $user );31 $ template = $relay->getPosts();33 $relay = new Relay( $this->getTrigger(), $this->placeholders, $user ); 34 $relay->sendMails(); 32 35 33 if ( ! empty( $template ) ) { 34 return $relay->prepareContent( $template[0] ); 35 } else { 36 return $relay->prepareContent(); 37 } 36 return ""; 38 37 39 38 } … … 47 46 public function getTrigger(): string { 48 47 return "password_reset"; 49 }50 51 function password_reset_email_subject( string $title, string $user_login, WP_User $user ): string {52 $this->setPlaceholderValues( $user );53 $relay = new Relay( $this->getTrigger(), $this->placeholders, $user );54 $template = $relay->getPosts();55 56 if ( ! empty( $template ) ) {57 return $relay->prepareSubject( $template[0] );58 } else {59 return $relay->prepareSubject();60 }61 62 63 48 } 64 49 -
juvo-mail-editor/tags/2.0.8/src/Relay.php
r2595821 r2596119 50 50 51 51 /** 52 * Sends mails for all posts that are associated with the trigger. 53 * To send mails even if not post is associated set the "alwaysSend" flag. 54 * 55 * If the flag is set the term defaults are used for the mailing 56 */ 57 public function sendMails() { 58 59 // Add Muted Capability 60 if ( self::triggerIsMuted( $this->trigger ) ) { 61 return false; 62 } 63 64 if ( ! empty( $this->posts ) ) { 65 foreach ( $this->posts as $post ) { 66 67 // Content 68 $content = $this->prepareContent( $post ); 69 70 // Subject 71 $subject = $this->prepareSubject( $post ); 72 73 // Recipients 74 $recipients = $this->prepareRecipients( $post ); 75 76 $mail = new Generic( $subject, $content, $recipients ); 77 $mail->send(); 78 79 } 80 } else { 81 82 // Some triggers might only send mails if a post is associated 83 $alwaysSent = get_term_meta( $this->term->term_id, Mail_Trigger_TAX::TAXONOMY_NAME . "_always_send", true ); 84 if ( ! $alwaysSent ) { 85 return false; 86 } 87 88 /// Fallback if not posts are found for configured trigger 89 $content = $this->prepareContent(); 90 $subject = $this->prepareSubject(); 91 $recipients = $this->prepareRecipients(); 92 93 $mail = new Generic( $subject, $content, $recipients ); 94 $mail->send(); 95 } 96 97 return true; 98 } 99 100 /** 101 * @return array 102 */ 103 public function getPlaceholders(): array { 104 return $this->placeholders; 105 } 106 107 /** 108 * @return WP_Term 109 */ 110 public function getTerm() { 111 return $this->term; 112 } 113 114 /** 115 * @return WP_Post[] 116 */ 117 public function getPosts(): array { 118 return $this->posts; 52 * @return false|WP_Term 53 */ 54 private function setTerm() { 55 return get_term_by( "slug", $this->trigger, Mail_Trigger_TAX::TAXONOMY_NAME ); 119 56 } 120 57 … … 140 77 141 78 /** 142 * @return false|WP_Term 143 */ 144 private function setTerm() { 145 return get_term_by( "slug", $this->trigger, Mail_Trigger_TAX::TAXONOMY_NAME ); 79 * @param array $placeholders 80 * 81 * @return array 82 */ 83 public function preparePlaceholders( array $placeholders ): array { 84 $defaultPlaceholders = get_term_meta( $this->term->term_id, Mail_Trigger_TAX::TAXONOMY_NAME . "_placeholders", true ); 85 86 if ( ! $defaultPlaceholders ) { 87 return $defaultPlaceholders; 88 } 89 90 return $placeholders + $defaultPlaceholders; 91 } 92 93 /** 94 * Sends mails for all posts that are associated with the trigger. 95 * To send mails even if not post is associated set the "alwaysSend" flag. 96 * 97 * If the flag is set the term defaults are used for the mailing 98 */ 99 public function sendMails() { 100 101 // Add Muted Capability 102 if ( self::triggerIsMuted( $this->trigger ) ) { 103 return false; 104 } 105 106 if ( ! empty( $this->posts ) ) { 107 foreach ( $this->posts as $post ) { 108 109 // Content 110 $content = $this->prepareContent( $post ); 111 112 // Subject 113 $subject = $this->prepareSubject( $post ); 114 115 // Recipients 116 $recipients = $this->prepareRecipients( $post ); 117 118 $mail = new Generic( $subject, $content, $recipients ); 119 $mail->send(); 120 121 } 122 } else { 123 124 // Some triggers might only send mails if a post is associated 125 $alwaysSent = get_term_meta( $this->term->term_id, Mail_Trigger_TAX::TAXONOMY_NAME . "_always_send", true ); 126 if ( ! $alwaysSent ) { 127 return false; 128 } 129 130 /// Fallback if not posts are found for configured trigger 131 $content = $this->prepareContent(); 132 $subject = $this->prepareSubject(); 133 $recipients = $this->prepareRecipients(); 134 135 $mail = new Generic( $subject, $content, $recipients ); 136 $mail->send(); 137 } 138 139 return true; 140 } 141 142 /** 143 * Checks if the given trigger is globally muted. 144 * Might be called manually if the mail is not send using the 'Relay' class but eg. with a filter. 145 * 146 * @param string $trigger 147 * 148 * @return bool 149 */ 150 public static function triggerIsMuted( string $trigger ): bool { 151 $pluginSettings = get_option( 'settings' ); 152 153 if ( isset( $pluginSettings['trigger_mute'] ) ) { 154 return in_array( $trigger, $pluginSettings['trigger_mute'] ); 155 } 156 157 return false; 146 158 } 147 159 … … 168 180 $content = apply_filters( "juvo_mail_editor_after_content_placeholder", $content, $this->trigger, $this->context ); 169 181 170 $ this->setContentType( $content );182 $content = $this->setContentType( $content ); 171 183 172 184 return $content; 185 } 186 187 public function setContentType( string $message ): string { 188 189 $type = "text/html"; 190 $message = wpautop( $message ); 191 192 add_filter( 'wp_mail_content_type', function( $content_type ) use ( $type ) { 193 return $type; 194 }, 10 ); 195 196 return $message; 173 197 } 174 198 … … 212 236 213 237 /** 214 * @param array $placeholders215 *216 238 * @return array 217 239 */ 218 public function preparePlaceholders( array $placeholders ): array { 219 $defaultPlaceholders = get_term_meta( $this->term->term_id, Mail_Trigger_TAX::TAXONOMY_NAME . "_placeholders", true ); 220 221 if ( ! $defaultPlaceholders ) { 222 return $defaultPlaceholders; 223 } 224 225 return $placeholders + $defaultPlaceholders; 226 } 227 228 public function setContentType( string $message ): string { 229 230 $type = 'text/plain'; 231 232 if ( $message != strip_tags( $message ) ) { 233 $type = "text/html"; 234 $message = wpautop( $message ); 235 } 236 237 add_filter( 'wp_mail_content_type', function( $content_type ) use ( $type ) { 238 return $type; 239 }, 10 ); 240 241 return $message; 242 } 243 244 /** 245 * Checks if the given trigger is globally muted. 246 * Might be called manually if the mail is not send using the 'Relay' class but eg. with a filter. 247 * 248 * @param string $trigger 249 * 250 * @return bool 251 */ 252 public static function triggerIsMuted( string $trigger ): bool { 253 $pluginSettings = get_option( 'settings' ); 254 255 if ( isset( $pluginSettings['trigger_mute'] ) ) { 256 $mutedTriggers = $pluginSettings['trigger_mute']; 257 258 return in_array( $trigger, $mutedTriggers ); 259 } 260 261 return false; 240 public function getPlaceholders(): array { 241 return $this->placeholders; 242 } 243 244 /** 245 * @return WP_Term 246 */ 247 public function getTerm() { 248 return $this->term; 249 } 250 251 /** 252 * @return WP_Post[] 253 */ 254 public function getPosts(): array { 255 return $this->posts; 262 256 } 263 257 -
juvo-mail-editor/trunk/juvo-mail-editor.php
r2595821 r2596119 8 8 * Text Domain: juvo-mail-editor 9 9 * Domain Path: /languages 10 * Version: 2.0. 710 * Version: 2.0.8 11 11 */ 12 12 -
juvo-mail-editor/trunk/readme.txt
r2595821 r2596119 4 4 License: GPLv2 or later 5 5 Tested up to: 5.8 6 Stable tag: 2.0. 76 Stable tag: 2.0.8 7 7 8 8 JUVO Mail Editor helps to modify the standard WordPress Mailings and allows adding dynamic mail triggers. -
juvo-mail-editor/trunk/src/Integrations/BuddyBoss.php
r2578743 r2596119 5 5 class BuddyBoss { 6 6 7 public function useTemplate( string $content, string $trigger, $context ){7 public function useTemplate( array $args ): array { 8 8 if ( function_exists( 'bp_is_active' ) ) { 9 /** @phpstan-ignore-next-line */ 10 return bp_email_core_wp_get_template( $content, $context ); 9 // BoddyBoss might have already applied the template 10 if ( isset( $args["message"] ) && strpos( $args["message"], '<!DOCTYPE html>' ) === false ) { 11 /** @phpstan-ignore-next-line */ 12 $args["message"] = bp_email_core_wp_get_template( $args["message"] ); 13 } 11 14 } 12 15 13 return $ content;16 return $args; 14 17 } 15 18 -
juvo-mail-editor/trunk/src/Mail_Editor.php
r2587510 r2596119 11 11 use JUVO_MailEditor\Mails\New_User_Admin_Rest; 12 12 use JUVO_MailEditor\Mails\New_User_Rest; 13 use JUVO_MailEditor\Mails\Password_Changed; 14 use JUVO_MailEditor\Mails\Password_Changed_Admin; 13 15 use JUVO_MailEditor\Mails\Password_Reset; 14 16 use JUVO_MailEditor\Mails\Password_Reset_Admin; … … 152 154 $this->loader->add_filter( "juvo_mail_editor_trigger", $passwordReset, "registerTrigger" ); 153 155 $this->loader->add_filter( "juvo_mail_editor_post_metabox", $passwordReset, "addCustomFields" ); 154 155 156 $this->loader->add_filter( 'retrieve_password_message', $passwordReset, 'password_reset_email_message', 10, 4 ); 156 $this->loader->add_filter( 'retrieve_password_title', $passwordReset, 'password_reset_email_subject', 10, 4 );157 157 158 158 /** … … 162 162 $this->loader->add_filter( "juvo_mail_editor_trigger", $passwordResetAdmin, "registerTrigger" ); 163 163 $this->loader->add_filter( "juvo_mail_editor_post_metabox", $passwordResetAdmin, "addCustomFields" ); 164 165 164 $this->loader->add_filter( "retrieve_password_message", $passwordResetAdmin, "password_reset_email_admin", 99, 4 ); 166 165 166 /** 167 * Password Changed 168 */ 169 $passwordChanged = new Password_Changed(); 170 $this->loader->add_filter( "juvo_mail_editor_trigger", $passwordChanged, "registerTrigger" ); 171 $this->loader->add_filter( "juvo_mail_editor_post_metabox", $passwordChanged, "addCustomFields" ); 172 $this->loader->add_filter( 'password_change_email', $passwordChanged, 'password_changed_email', 10, 2 ); 173 174 /** 175 * Password Changed Admin 176 */ 177 $passwordChangedAdmin = new Password_Changed_Admin(); 178 $this->loader->add_filter( "juvo_mail_editor_trigger", $passwordChangedAdmin, "registerTrigger" ); 179 $this->loader->add_filter( "juvo_mail_editor_post_metabox", $passwordChangedAdmin, "addCustomFields" ); 180 $this->loader->add_filter( 'wp_password_change_notification_email', $passwordChangedAdmin, 'password_changed_admin_email', 10, 2 ); 181 167 182 168 183 /** 169 184 * Integrations 170 185 */ 171 $this->loader->add_filter( "juvo_mail_editor_after_content_placeholder", new BuddyBoss(), "useTemplate", 10, 3 ); 172 186 $this->loader->add_filter( "wp_mail", new BuddyBoss(), "useTemplate", 99, 1 ); 173 187 } 174 188 -
juvo-mail-editor/trunk/src/Mails/New_User.php
r2595821 r2596119 25 25 public function new_user_notification_email( array $email, WP_User $user ): array { 26 26 27 // Add Muted Capability28 if ( Relay::triggerIsMuted( $this->getTrigger() ) ) {29 return [];30 }31 32 27 $this->setPlaceholderValues( $user ); 33 28 34 $relay = new Relay( $this->getTrigger(), $this->placeholders, $user );35 $ template = $relay->getPosts();29 $relay = new Relay( $this->getTrigger(), $this->placeholders, $user ); 30 $relay->sendMails(); 36 31 37 if ( ! empty( $template ) ) { 38 $email["to"] = $relay->prepareRecipients( $template[0] ); 39 $email["subject"] = $relay->prepareSubject( $template[0] ); 40 $email["message"] = $relay->prepareContent( $template[0] ); 41 } 42 43 return $email; 32 return []; 44 33 } 45 34 -
juvo-mail-editor/trunk/src/Mails/New_User_Admin.php
r2595821 r2596119 15 15 function new_user_notification_email_admin( array $email, WP_User $user ): array { 16 16 17 // Add Muted Capability18 if ( Relay::triggerIsMuted( $this->getTrigger() ) ) {19 return [];20 }21 22 17 $this->setPlaceholderValues( $user ); 23 18 24 $relay = new Relay( $this->getTrigger(), $this->placeholders, $user );25 $ template = $relay->getPosts();19 $relay = new Relay( $this->getTrigger(), $this->placeholders, $user ); 20 $relay->sendMails(); 26 21 27 if ( ! empty( $template ) ) { 28 $email["to"] = $relay->prepareRecipients( $template[0] ); 29 $email["subject"] = $relay->prepareSubject( $template[0] ); 30 $email["message"] = $relay->prepareContent( $template[0] ); 31 } 32 33 return $email; 22 return []; 34 23 } 35 24 -
juvo-mail-editor/trunk/src/Mails/Password_Reset.php
r2594645 r2596119 19 19 ]; 20 20 21 /** 22 * @param string $message 23 * @param string $key 24 * @param string $user_login 25 * @param WP_User $user 26 * 27 * @return string Empty string to prevent default wordpress mail from being sent 28 */ 21 29 function password_reset_email_message( string $message, string $key, string $user_login, WP_User $user ): string { 22 23 // Add Muted Capability24 if ( Relay::triggerIsMuted( $this->getTrigger() ) ) {25 return "";26 }27 30 28 31 $this->setPlaceholderValues( $user, [ "key" => $key ] ); 29 32 30 $relay = new Relay( $this->getTrigger(), $this->placeholders, $user );31 $ template = $relay->getPosts();33 $relay = new Relay( $this->getTrigger(), $this->placeholders, $user ); 34 $relay->sendMails(); 32 35 33 if ( ! empty( $template ) ) { 34 return $relay->prepareContent( $template[0] ); 35 } else { 36 return $relay->prepareContent(); 37 } 36 return ""; 38 37 39 38 } … … 47 46 public function getTrigger(): string { 48 47 return "password_reset"; 49 }50 51 function password_reset_email_subject( string $title, string $user_login, WP_User $user ): string {52 $this->setPlaceholderValues( $user );53 $relay = new Relay( $this->getTrigger(), $this->placeholders, $user );54 $template = $relay->getPosts();55 56 if ( ! empty( $template ) ) {57 return $relay->prepareSubject( $template[0] );58 } else {59 return $relay->prepareSubject();60 }61 62 63 48 } 64 49 -
juvo-mail-editor/trunk/src/Relay.php
r2595821 r2596119 50 50 51 51 /** 52 * Sends mails for all posts that are associated with the trigger. 53 * To send mails even if not post is associated set the "alwaysSend" flag. 54 * 55 * If the flag is set the term defaults are used for the mailing 56 */ 57 public function sendMails() { 58 59 // Add Muted Capability 60 if ( self::triggerIsMuted( $this->trigger ) ) { 61 return false; 62 } 63 64 if ( ! empty( $this->posts ) ) { 65 foreach ( $this->posts as $post ) { 66 67 // Content 68 $content = $this->prepareContent( $post ); 69 70 // Subject 71 $subject = $this->prepareSubject( $post ); 72 73 // Recipients 74 $recipients = $this->prepareRecipients( $post ); 75 76 $mail = new Generic( $subject, $content, $recipients ); 77 $mail->send(); 78 79 } 80 } else { 81 82 // Some triggers might only send mails if a post is associated 83 $alwaysSent = get_term_meta( $this->term->term_id, Mail_Trigger_TAX::TAXONOMY_NAME . "_always_send", true ); 84 if ( ! $alwaysSent ) { 85 return false; 86 } 87 88 /// Fallback if not posts are found for configured trigger 89 $content = $this->prepareContent(); 90 $subject = $this->prepareSubject(); 91 $recipients = $this->prepareRecipients(); 92 93 $mail = new Generic( $subject, $content, $recipients ); 94 $mail->send(); 95 } 96 97 return true; 98 } 99 100 /** 101 * @return array 102 */ 103 public function getPlaceholders(): array { 104 return $this->placeholders; 105 } 106 107 /** 108 * @return WP_Term 109 */ 110 public function getTerm() { 111 return $this->term; 112 } 113 114 /** 115 * @return WP_Post[] 116 */ 117 public function getPosts(): array { 118 return $this->posts; 52 * @return false|WP_Term 53 */ 54 private function setTerm() { 55 return get_term_by( "slug", $this->trigger, Mail_Trigger_TAX::TAXONOMY_NAME ); 119 56 } 120 57 … … 140 77 141 78 /** 142 * @return false|WP_Term 143 */ 144 private function setTerm() { 145 return get_term_by( "slug", $this->trigger, Mail_Trigger_TAX::TAXONOMY_NAME ); 79 * @param array $placeholders 80 * 81 * @return array 82 */ 83 public function preparePlaceholders( array $placeholders ): array { 84 $defaultPlaceholders = get_term_meta( $this->term->term_id, Mail_Trigger_TAX::TAXONOMY_NAME . "_placeholders", true ); 85 86 if ( ! $defaultPlaceholders ) { 87 return $defaultPlaceholders; 88 } 89 90 return $placeholders + $defaultPlaceholders; 91 } 92 93 /** 94 * Sends mails for all posts that are associated with the trigger. 95 * To send mails even if not post is associated set the "alwaysSend" flag. 96 * 97 * If the flag is set the term defaults are used for the mailing 98 */ 99 public function sendMails() { 100 101 // Add Muted Capability 102 if ( self::triggerIsMuted( $this->trigger ) ) { 103 return false; 104 } 105 106 if ( ! empty( $this->posts ) ) { 107 foreach ( $this->posts as $post ) { 108 109 // Content 110 $content = $this->prepareContent( $post ); 111 112 // Subject 113 $subject = $this->prepareSubject( $post ); 114 115 // Recipients 116 $recipients = $this->prepareRecipients( $post ); 117 118 $mail = new Generic( $subject, $content, $recipients ); 119 $mail->send(); 120 121 } 122 } else { 123 124 // Some triggers might only send mails if a post is associated 125 $alwaysSent = get_term_meta( $this->term->term_id, Mail_Trigger_TAX::TAXONOMY_NAME . "_always_send", true ); 126 if ( ! $alwaysSent ) { 127 return false; 128 } 129 130 /// Fallback if not posts are found for configured trigger 131 $content = $this->prepareContent(); 132 $subject = $this->prepareSubject(); 133 $recipients = $this->prepareRecipients(); 134 135 $mail = new Generic( $subject, $content, $recipients ); 136 $mail->send(); 137 } 138 139 return true; 140 } 141 142 /** 143 * Checks if the given trigger is globally muted. 144 * Might be called manually if the mail is not send using the 'Relay' class but eg. with a filter. 145 * 146 * @param string $trigger 147 * 148 * @return bool 149 */ 150 public static function triggerIsMuted( string $trigger ): bool { 151 $pluginSettings = get_option( 'settings' ); 152 153 if ( isset( $pluginSettings['trigger_mute'] ) ) { 154 return in_array( $trigger, $pluginSettings['trigger_mute'] ); 155 } 156 157 return false; 146 158 } 147 159 … … 168 180 $content = apply_filters( "juvo_mail_editor_after_content_placeholder", $content, $this->trigger, $this->context ); 169 181 170 $ this->setContentType( $content );182 $content = $this->setContentType( $content ); 171 183 172 184 return $content; 185 } 186 187 public function setContentType( string $message ): string { 188 189 $type = "text/html"; 190 $message = wpautop( $message ); 191 192 add_filter( 'wp_mail_content_type', function( $content_type ) use ( $type ) { 193 return $type; 194 }, 10 ); 195 196 return $message; 173 197 } 174 198 … … 212 236 213 237 /** 214 * @param array $placeholders215 *216 238 * @return array 217 239 */ 218 public function preparePlaceholders( array $placeholders ): array { 219 $defaultPlaceholders = get_term_meta( $this->term->term_id, Mail_Trigger_TAX::TAXONOMY_NAME . "_placeholders", true ); 220 221 if ( ! $defaultPlaceholders ) { 222 return $defaultPlaceholders; 223 } 224 225 return $placeholders + $defaultPlaceholders; 226 } 227 228 public function setContentType( string $message ): string { 229 230 $type = 'text/plain'; 231 232 if ( $message != strip_tags( $message ) ) { 233 $type = "text/html"; 234 $message = wpautop( $message ); 235 } 236 237 add_filter( 'wp_mail_content_type', function( $content_type ) use ( $type ) { 238 return $type; 239 }, 10 ); 240 241 return $message; 242 } 243 244 /** 245 * Checks if the given trigger is globally muted. 246 * Might be called manually if the mail is not send using the 'Relay' class but eg. with a filter. 247 * 248 * @param string $trigger 249 * 250 * @return bool 251 */ 252 public static function triggerIsMuted( string $trigger ): bool { 253 $pluginSettings = get_option( 'settings' ); 254 255 if ( isset( $pluginSettings['trigger_mute'] ) ) { 256 $mutedTriggers = $pluginSettings['trigger_mute']; 257 258 return in_array( $trigger, $mutedTriggers ); 259 } 260 261 return false; 240 public function getPlaceholders(): array { 241 return $this->placeholders; 242 } 243 244 /** 245 * @return WP_Term 246 */ 247 public function getTerm() { 248 return $this->term; 249 } 250 251 /** 252 * @return WP_Post[] 253 */ 254 public function getPosts(): array { 255 return $this->posts; 262 256 } 263 257
Note: See TracChangeset
for help on using the changeset viewer.