Changeset 2655718
- Timestamp:
- 01/11/2022 09:57:02 AM (4 years ago)
- Location:
- juvo-mail-editor
- Files:
-
- 40 edited
- 1 copied
-
tags/3.0.2 (copied) (copied from juvo-mail-editor/trunk)
-
tags/3.0.2/juvo-mail-editor.php (modified) (1 diff)
-
tags/3.0.2/readme.txt (modified) (1 diff)
-
tags/3.0.2/src/Mail_Editor.php (modified) (2 diffs)
-
tags/3.0.2/src/Mail_Generator.php (modified) (5 diffs)
-
tags/3.0.2/src/Mail_Trigger_TAX.php (modified) (2 diffs)
-
tags/3.0.2/src/Mails/Mail.php (modified) (1 diff)
-
tags/3.0.2/src/Mails/New_User.php (modified) (2 diffs)
-
tags/3.0.2/src/Mails/New_User_Admin.php (modified) (3 diffs)
-
tags/3.0.2/src/Mails/New_User_Admin_Rest.php (modified) (2 diffs)
-
tags/3.0.2/src/Mails/New_User_Rest.php (modified) (2 diffs)
-
tags/3.0.2/src/Mails/Password_Changed.php (modified) (2 diffs)
-
tags/3.0.2/src/Mails/Password_Changed_Admin.php (modified) (3 diffs)
-
tags/3.0.2/src/Mails/Password_Reset.php (modified) (3 diffs)
-
tags/3.0.2/src/Mails/Password_Reset_Admin.php (modified) (2 diffs)
-
tags/3.0.2/src/Mails_PT.php (modified) (1 diff)
-
tags/3.0.2/src/Relay.php (modified) (8 diffs)
-
tags/3.0.2/vendor/autoload.php (modified) (1 diff)
-
tags/3.0.2/vendor/composer/autoload_real.php (modified) (5 diffs)
-
tags/3.0.2/vendor/composer/autoload_static.php (modified) (2 diffs)
-
tags/3.0.2/vendor/composer/installed.php (modified) (2 diffs)
-
trunk/juvo-mail-editor.php (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/src/Mail_Editor.php (modified) (2 diffs)
-
trunk/src/Mail_Generator.php (modified) (5 diffs)
-
trunk/src/Mail_Trigger_TAX.php (modified) (2 diffs)
-
trunk/src/Mails/Mail.php (modified) (1 diff)
-
trunk/src/Mails/New_User.php (modified) (2 diffs)
-
trunk/src/Mails/New_User_Admin.php (modified) (3 diffs)
-
trunk/src/Mails/New_User_Admin_Rest.php (modified) (2 diffs)
-
trunk/src/Mails/New_User_Rest.php (modified) (2 diffs)
-
trunk/src/Mails/Password_Changed.php (modified) (2 diffs)
-
trunk/src/Mails/Password_Changed_Admin.php (modified) (3 diffs)
-
trunk/src/Mails/Password_Reset.php (modified) (3 diffs)
-
trunk/src/Mails/Password_Reset_Admin.php (modified) (2 diffs)
-
trunk/src/Mails_PT.php (modified) (1 diff)
-
trunk/src/Relay.php (modified) (8 diffs)
-
trunk/vendor/autoload.php (modified) (1 diff)
-
trunk/vendor/composer/autoload_real.php (modified) (5 diffs)
-
trunk/vendor/composer/autoload_static.php (modified) (2 diffs)
-
trunk/vendor/composer/installed.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
juvo-mail-editor/tags/3.0.2/juvo-mail-editor.php
r2654150 r2655718 8 8 * Text Domain: juvo-mail-editor 9 9 * Domain Path: /languages 10 * Version: 3.0. 110 * Version: 3.0.2 11 11 */ 12 12 -
juvo-mail-editor/tags/3.0.2/readme.txt
r2654150 r2655718 4 4 License: GPLv2 or later 5 5 Tested up to: 5.8 6 Stable tag: 3.0. 16 Stable tag: 3.0.2 7 7 8 8 JUVO Mail Editor helps to modify the standard WordPress Mailings and allows adding dynamic mail triggers. -
juvo-mail-editor/tags/3.0.2/src/Mail_Editor.php
r2654150 r2655718 120 120 121 121 /** 122 * Handle Sending 123 */ 124 add_action( "juvo_mail_editor_send", array( Relay::class, 'sendMails' ), 10, 2 ); 125 126 /** 122 127 * Placeholders 123 128 */ … … 127 132 * New User Notification for enduser 128 133 */ 129 $this->loader->add_action( 'wp_new_user_notification_email', new New_User(), ' send', 10, 2 );130 $this->loader->add_action( 'rest_insert_user', new New_User_Rest(), ' send', 12, 1 ); // Rest134 $this->loader->add_action( 'wp_new_user_notification_email', new New_User(), 'prepareSend', 10, 2 ); 135 $this->loader->add_action( 'rest_insert_user', new New_User_Rest(), 'prepareSend', 12, 1 ); // Rest 131 136 132 137 /** 133 138 * New User Notification Admin 134 139 */ 135 $this->loader->add_action( 'wp_new_user_notification_email_admin', new New_User_Admin(), ' send', 10, 2 );136 $this->loader->add_action( 'rest_insert_user', new New_User_Admin_Rest(), ' send', 12, 1 ); // Rest140 $this->loader->add_action( 'wp_new_user_notification_email_admin', new New_User_Admin(), 'prepareSend', 10, 2 ); 141 $this->loader->add_action( 'rest_insert_user', new New_User_Admin_Rest(), 'prepareSend', 12, 1 ); // Rest 137 142 138 143 /** 139 144 * Password Reset 140 145 */ 141 $this->loader->add_filter( 'retrieve_password_message', new Password_Reset(), ' send', 10, 4 );146 $this->loader->add_filter( 'retrieve_password_message', new Password_Reset(), 'prepareSend', 10, 4 ); 142 147 143 148 /** 144 149 * Password Reset Admin 145 150 */ 146 $this->loader->add_filter( 'retrieve_password_message', new Password_Reset_Admin(), ' send', 99, 4 );151 $this->loader->add_filter( 'retrieve_password_message', new Password_Reset_Admin(), 'prepareSend', 99, 4 ); 147 152 148 153 /** 149 154 * Password Changed 150 155 */ 151 $this->loader->add_filter( 'password_change_email', new Password_Changed(), ' send', 10, 2 );156 $this->loader->add_filter( 'password_change_email', new Password_Changed(), 'prepareSend', 10, 2 ); 152 157 153 158 /** 154 159 * Password Changed Admin 155 160 */ 156 $this->loader->add_filter( 'wp_password_change_notification_email', new Password_Changed_Admin(), ' send', 10, 2 );161 $this->loader->add_filter( 'wp_password_change_notification_email', new Password_Changed_Admin(), 'prepareSend', 10, 2 ); 157 162 158 163 /** -
juvo-mail-editor/tags/3.0.2/src/Mail_Generator.php
r2654150 r2655718 19 19 add_filter( "juvo_mail_editor_{$this->getTrigger()}_default_recipients", array( $this, 'getRecipient' ), 1, 0 ); 20 20 add_filter( 21 "juvo_mail_editor_{$this->getTrigger()}_ default_placeholder",21 "juvo_mail_editor_{$this->getTrigger()}_placeholders", 22 22 array( 23 23 $this, 24 'get DefaultPlaceholder',24 'getPlaceholders', 25 25 ), 26 26 1, 27 027 2 28 28 ); 29 29 add_filter( "juvo_mail_editor_{$this->getTrigger()}_language", array( $this, 'getLanguage' ), 1, 2 ); 30 30 } 31 31 32 /** 33 * Returns the trigger slug which should be unique and is used for all consecutive filters and actions 34 * 35 * @return string trigger slug 36 */ 32 37 abstract protected function getTrigger(): string; 33 38 34 abstract public function send( ...$params ); 39 /** 40 * Returns the custom placeholders available for this trigger. 41 * They may not necessarily have a value. 42 * 43 * The function should always return all custom placeholder no matter if they have a value or not. 44 * This allows filters or other functions to fill or show the placeholder in the most dynamic way. 45 * 46 * @param array|null $context 47 * 48 * @return array Array key equals the accessor in twig 49 */ 50 public function getPlaceholders( array $placeholders, ?array $context ): array { 51 return $placeholders; 52 } 35 53 36 54 /** … … 45 63 } 46 64 47 abstract protected function getName(): string; 65 /** 66 * Returns the triggers nicename in a human-readable format 67 * 68 * @return string trigger nicename 69 */ 70 abstract protected function getName(): string; // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed 48 71 49 72 /** … … 56 79 public function addCustomFields( CMB2 $cmb ): CMB2 { 57 80 return $cmb; 58 } // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed81 } 59 82 60 83 public function postHasTrigger( CMB2_Field $field ): bool { … … 73 96 return $language; 74 97 } 75 76 /**77 * Fill the default placeholders with their real values.78 * Params are most likely equal to the context.79 * This function should be called inside the send() method.80 *81 * @return array82 */83 abstract protected function getPlaceholderValues(): array;84 98 85 99 /** … … 102 116 } 103 117 118 /** 119 * Utility function that completely empties the often used mail array. 120 * This is most useful if hooking into native core function 121 * 122 * @param array $email 123 * @param null $val 124 * 125 * @return array 126 */ 104 127 protected function emptyMailArray( array $email, $val = null ): array { 105 128 foreach ( $email as $key => $item ) { -
juvo-mail-editor/tags/3.0.2/src/Mail_Trigger_TAX.php
r2644151 r2655718 122 122 ); 123 123 } 124 124 125 if ( is_wp_error( $term ) ) { 125 126 $errors->add( 'juvo_mail_editor_term_error', $term->get_error_message() ); … … 127 128 } 128 129 129 // wp_insert_term returns an error while wp_update_term return an instance of WP_Term... thanks for nothing130 // normalize $term to be the term_id131 if ( is_array( $term ) ) {132 $term = $term['term_id'];133 } else { // @phpstan-ignore-line134 $term = $term->term_id;135 }136 130 } 137 131 -
juvo-mail-editor/tags/3.0.2/src/Mails/Mail.php
r2654150 r2655718 11 11 public function getRecipient(): string; 12 12 13 /**14 * Return default placeholder set15 *16 * @return array17 */18 public function getDefaultPlaceholder(): array;19 20 13 public function getAlwaysSent(): bool; 21 14 -
juvo-mail-editor/tags/3.0.2/src/Mails/New_User.php
r2654150 r2655718 4 4 5 5 use JUVO_MailEditor\Mail_Generator; 6 use JUVO_MailEditor\Relay;7 6 use WP_User; 8 7 9 8 class New_User extends Mail_Generator { 10 11 protected WP_User $user;12 9 13 10 protected function getTrigger(): string { … … 15 12 } 16 13 17 public function send( ...$params ) { 18 list( $email, $user ) = $params; 19 20 $this->user = $user; 21 22 $placeholders = $this->getPlaceholderValues(); 23 24 $relay = new Relay( $this->getTrigger(), $placeholders, array( 'user' => $user ) ); 25 $relay->sendMails(); 26 14 public function prepareSend( array $email, WP_User $user ): array { 15 do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user ] ); 27 16 return $this->emptyMailArray( $email ); 28 17 } 29 18 30 19 /** 31 * @inheritDoc 20 * @param array|null $context 21 * 22 * @return string[] 32 23 */ 33 protected function getPlaceholderValues(): array { 34 $placeholders = $this->getDefaultPlaceholder(); 24 public function getPlaceholders( array $placeholders, ?array $context ): array { 35 25 36 $adt_rp_key = get_password_reset_key( $this->user ); 37 $user_login = $this->user->user_login; 26 $placeholders = array_merge( $placeholders, array( 27 'password_reset_link' => '', 28 ) ); 29 30 if ( empty( $context ) ) { 31 return $placeholders; 32 } 33 34 $adt_rp_key = get_password_reset_key( $context['user'] ); 35 $user_login = $context['user']->user_login; 38 36 $placeholders['password_reset_link'] = '<a href="' . network_site_url( "wp-login.php?action=rp&key=$adt_rp_key&login=" . rawurlencode( $user_login ), 'login' ) . '">' . network_site_url( "wp-login.php?action=rp&key=$adt_rp_key&login=" . rawurlencode( $user_login ), 'login' ) . '</a>'; 39 37 40 38 return $placeholders; 41 }42 43 /**44 * @inheritDoc45 */46 public function getDefaultPlaceholder(): array {47 return array(48 'password_reset_link' => '',49 );50 39 } 51 40 -
juvo-mail-editor/tags/3.0.2/src/Mails/New_User_Admin.php
r2654150 r2655718 4 4 5 5 use JUVO_MailEditor\Mail_Generator; 6 use JUVO_MailEditor\Relay;7 6 use WP_User; 8 7 9 8 class New_User_Admin extends Mail_Generator { 10 11 protected WP_User $user;12 9 13 10 /** … … 18 15 } 19 16 20 public function send( ...$params ) { 21 list( $email, $user ) = $params; 22 23 $this->user = $user; 24 25 $placeholders = $this->getPlaceholderValues(); 26 27 $relay = new Relay( $this->getTrigger(), $placeholders, array( 'user' => $user ) ); 28 $relay->sendMails(); 29 17 public function prepareSend( array $email, WP_User $user ): array { 18 do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user ] ); 30 19 return $this->emptyMailArray( $email ); 31 20 } … … 51 40 } 52 41 53 /**54 * @inheritDoc55 */56 public function getDefaultPlaceholder(): array {57 return array();58 }59 60 /**61 * @inheritDoc62 */63 protected function getPlaceholderValues(): array {64 return array();65 }66 67 42 public function getAlwaysSent(): bool { 68 43 return true; -
juvo-mail-editor/tags/3.0.2/src/Mails/New_User_Admin_Rest.php
r2654150 r2655718 4 4 5 5 use JUVO_MailEditor\Mail_Generator; 6 use JUVO_MailEditor\Relay;6 use WP_User; 7 7 8 8 class New_User_Admin_Rest extends Mail_Generator { 9 9 10 public function send( ...$params ) { 11 list( $user ) = $params; 12 13 $placeholders = $this->getPlaceholderValues(); 14 15 $relay = new Relay( $this->getTrigger(), $placeholders, array( 'user' => $user ) ); 16 $relay->sendMails(); 17 } 18 19 /** 20 * @inheritDoc 21 */ 22 protected function getPlaceholderValues(): array { 23 return array(); 10 public function prepareSend( WP_User $user ): void { 11 do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user ] ); 24 12 } 25 13 … … 51 39 } 52 40 53 /**54 * @inheritDoc55 */56 public function getDefaultPlaceholder(): array {57 return array();58 }59 60 41 public function getAlwaysSent(): bool { 61 42 return false; -
juvo-mail-editor/tags/3.0.2/src/Mails/New_User_Rest.php
r2654150 r2655718 4 4 5 5 use JUVO_MailEditor\Mail_Generator; 6 use JUVO_MailEditor\Relay;7 6 use WP_User; 8 7 9 8 class New_User_Rest extends Mail_Generator { 10 9 11 protected WP_User $user; 12 13 public function send( ...$params ) { 14 list( $user ) = $params; 15 16 $this->user = $user; 17 18 $placeholders = $this->getPlaceholderValues(); 19 20 $relay = new Relay( $this->getTrigger(), $placeholders, array( 'user' => $user ) ); 21 $relay->sendMails(); 10 public function prepareSend( WP_User $user ) { 11 do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user ] ); 22 12 } 23 13 … … 25 15 * @inheritDoc 26 16 */ 27 p rotected function getPlaceholderValues(): array {17 public function getPlaceholders( array $placeholders, ?array $context ): array { 28 18 29 $placeholders = $this->getDefaultPlaceholder(); 19 $placeholders = array_merge( $placeholders, array( 20 'password_reset_link' => '', 21 ) ); 30 22 31 $adt_rp_key = get_password_reset_key( $this->user ); 32 $user_login = $this->user->user_login; 23 if ( empty( $context ) ) { 24 return $placeholders; 25 } 26 27 $adt_rp_key = get_password_reset_key( $context['user'] ); 28 $user_login = $context['user']->user_login; 33 29 $placeholders['password_reset_link'] = '<a href="' . network_site_url( "wp-login.php?action=rp&key=$adt_rp_key&login=" . rawurlencode( $user_login ), 'login' ) . '">' . network_site_url( "wp-login.php?action=rp&key=$adt_rp_key&login=" . rawurlencode( $user_login ), 'login' ) . '</a>'; 34 30 35 31 return $placeholders; 32 36 33 } 37 34 -
juvo-mail-editor/tags/3.0.2/src/Mails/Password_Changed.php
r2654150 r2655718 8 8 use JUVO_MailEditor\Mail_Trigger_TAX; 9 9 use JUVO_MailEditor\Mails_PT; 10 use JUVO_MailEditor\Relay;11 10 use WP_User; 12 11 … … 65 64 } 66 65 67 public function send( ...$params ) { 68 list( $email, $user ) = $params; 69 70 $placeholders = $this->getPlaceholderValues(); 71 72 $relay = new Relay( $this->getTrigger(), $placeholders, array( 'user' => $user ) ); 73 $relay->sendMails(); 66 public function prepareSend( array $email, WP_User $user ): array { 67 do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user ] ); 74 68 75 69 return $this->emptyMailArray( $email ); 76 }77 78 /**79 * @inheritDoc80 */81 protected function getPlaceholderValues(): array {82 return array();83 }84 85 /**86 * @inheritDoc87 */88 public function getDefaultPlaceholder(): array {89 return array();90 70 } 91 71 -
juvo-mail-editor/tags/3.0.2/src/Mails/Password_Changed_Admin.php
r2654150 r2655718 8 8 use JUVO_MailEditor\Mail_Trigger_TAX; 9 9 use JUVO_MailEditor\Mails_PT; 10 use JUVO_MailEditor\Relay;11 10 use WP_User; 12 11 … … 37 36 } 38 37 39 public function send( ...$params ) { 40 list( $email, $user ) = $params; 41 42 $placeholders = $this->getPlaceholderValues(); 43 44 $relay = new Relay( $this->getTrigger(), $placeholders, array( 'user' => $user ) ); 45 $relay->sendMails(); 46 38 public function prepareSend( array $email, WP_User $user ): array { 39 do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user ] ); 47 40 return $this->emptyMailArray( $email ); 48 }49 50 /**51 * @inheritDoc52 */53 protected function getPlaceholderValues(): array {54 return array();55 }56 57 /**58 * @inheritDoc59 */60 public function getDefaultPlaceholder(): array {61 return array();62 41 } 63 42 … … 66 45 } 67 46 68 protected function setPlaceholderValues( WP_User $user, array $options = array() ): void {69 }70 71 47 protected function getName(): string { 72 48 return 'Password Changed (Admin)'; -
juvo-mail-editor/tags/3.0.2/src/Mails/Password_Reset.php
r2654150 r2655718 8 8 use JUVO_MailEditor\Mail_Trigger_TAX; 9 9 use JUVO_MailEditor\Mails_PT; 10 use JUVO_MailEditor\Relay;11 10 use WP_User; 12 11 13 12 class Password_Reset extends Mail_Generator { 14 15 protected WP_User $user;16 protected string $key;17 13 18 14 protected function getTrigger(): string { … … 28 24 } 29 25 30 public function send( ...$params ) { 31 list( $message, $key, $user_login, $user ) = $params; 32 33 $this->user = $user; 34 $this->key = $key; 35 36 $placeholders = $this->getPlaceholderValues(); 37 38 $relay = new Relay( $this->getTrigger(), $placeholders, array( 'user' => $user ) ); 39 $relay->sendMails(); 40 26 public function prepareSend( $message, string $key, $user_login, WP_User $user ): string { 27 do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user, 'key' => $key ] ); 41 28 return ''; 42 29 } … … 68 55 * @inheritDoc 69 56 */ 70 public function getDefaultPlaceholder(): array { 71 return array( 57 public function getPlaceholders( array $placeholders, ?array $context ): array { 58 59 $placeholders = array_merge( $placeholders, array( 72 60 'password_reset_link' => '', 73 ); 74 } 61 ) ); 75 62 76 /** 77 * @inheritDoc 78 */ 79 protected function getPlaceholderValues(): array { 63 if ( empty( $context ) ) { 64 return $placeholders; 65 } 80 66 81 $placeholders = $this->getDefaultPlaceholder(); 82 83 if ( ! empty( $this->key ) ) { 84 $placeholders['password_reset_link'] = '<a href="' . network_site_url( "wp-login.php?action=rp&key={$this->key}&login=" . rawurlencode( $this->user->user_login ), 'login' ) . '">' . network_site_url( "wp-login.php?action=rp&key={$this->key}&login=" . rawurlencode( $this->user->user_login ), 'login' ) . '</a>'; 67 if ( ! empty( $context['key'] ) ) { 68 $placeholders['password_reset_link'] = '<a href="' . network_site_url( "wp-login.php?action=rp&key={$context['key']}&login=" . rawurlencode( $context['user']->user_login ), 'login' ) . '">' . network_site_url( "wp-login.php?action=rp&key={$context['key']}&login=" . rawurlencode( $context['user']->user_login ), 'login' ) . '</a>'; 85 69 } 86 70 -
juvo-mail-editor/tags/3.0.2/src/Mails/Password_Reset_Admin.php
r2654150 r2655718 6 6 use CMB2; 7 7 use JUVO_MailEditor\Mail_Generator; 8 use JUVO_MailEditor\Relay;8 use WP_User; 9 9 10 10 class Password_Reset_Admin extends Mail_Generator { … … 30 30 } 31 31 32 public function send( ...$params ) { 33 list( $message, $key, $user_login, $user ) = $params; 34 35 $placeholders = $this->getPlaceholderValues(); 36 37 $relay = new Relay( $this->getTrigger(), $placeholders, array( 'user' => $user ) ); 38 $relay->sendMails(); 39 32 public function prepareSend( $message, $key, $user_login, WP_User $user ): string { 33 do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user, 'key' => $key ] ); 40 34 return ''; 41 }42 43 /**44 * @inheritDoc45 */46 protected function getPlaceholderValues(): array {47 return array();48 35 } 49 36 50 37 protected function getTrigger(): string { 51 38 return 'password_reset_admin'; 52 }53 54 /**55 * @inheritDoc56 */57 public function getDefaultPlaceholder(): array {58 return array();59 39 } 60 40 -
juvo-mail-editor/tags/3.0.2/src/Mails_PT.php
r2644151 r2655718 85 85 array( 86 86 'name' => __( 'Recipients', 'juvo-mail-editor' ), 87 'desc' => __( 'Comma seperated list of mail addresses <br><code>{{CONTEXT}}</code><code>{{ADMIN_EMAIL}}</code>', 'juvo-mail-editor' ),87 'desc' => __( 'Comma seperated list of mail addresses', 'juvo-mail-editor' ), 88 88 'id' => self::POST_TYPE_NAME . '_recipients', 89 89 'type' => 'text', -
juvo-mail-editor/tags/3.0.2/src/Relay.php
r2644151 r2655718 37 37 * 38 38 * @param string $trigger 39 * @param array $placeholders40 39 * @param array $context 41 */ 42 public function __construct( string $trigger, array $placeholders, array $context = array() ) { 40 * @param WP_Term $term 41 */ 42 public function __construct( string $trigger, array $context, WP_Term $term ) { 43 43 $this->trigger = $trigger; 44 44 $this->context = $context; 45 $this->term = $t his->setTerm();45 $this->term = $term; 46 46 $this->posts = $this->setPostsForTrigger(); 47 $this->placeholders = $this->preparePlaceholders( $placeholders ); 48 } 49 50 /** 51 * @return false|WP_Term 52 */ 53 private function setTerm() { 54 return get_term_by( 'slug', $this->trigger, Mail_Trigger_TAX::TAXONOMY_NAME ); 47 $this->placeholders = $this->preparePlaceholders(); 55 48 } 56 49 … … 79 72 80 73 /** 81 * @param array $placeholders82 *83 74 * @return array 84 75 */ 85 public function preparePlaceholders( array $placeholders ): array { 86 $defaultPlaceholders = apply_filters( "juvo_mail_editor_{$this->trigger}_default_placeholder", array() ); 87 88 if ( ! $defaultPlaceholders ) { 89 return $defaultPlaceholders; 90 } 91 92 return $placeholders + $defaultPlaceholders; 76 public function preparePlaceholders(): array { 77 return apply_filters( "juvo_mail_editor_{$this->trigger}_placeholders", array(), $this->context ); 93 78 } 94 79 … … 99 84 * If the flag is set the term defaults are used for the mailing 100 85 */ 101 public function sendMails() { 86 public static function sendMails( string $trigger, array $context = array() ) { 87 88 $term = get_term_by( 'slug', $trigger, Mail_Trigger_TAX::TAXONOMY_NAME ); 89 90 if ( ! $term instanceof WP_Term ) { 91 return false; 92 } 102 93 103 94 // Add Muted Capability 104 if ( self::triggerIsMuted( $t his->trigger ) ) {95 if ( self::triggerIsMuted( $trigger ) ) { 105 96 return false; 106 97 } 98 99 $relay = new self( $trigger, $context, $term ); 107 100 108 101 // Store blog language defaults … … 111 104 $blogLang = locale_get_primary_language( $blogLocale ); 112 105 113 if ( ! empty( $ this->posts ) ) {106 if ( ! empty( $relay->posts ) ) { 114 107 // If templates were created for trigger 115 108 116 foreach ( $ this->posts as $post ) {117 118 $locale = apply_filters( "juvo_mail_editor_{$t his->trigger}_language", $blogLocale, $this->context );109 foreach ( $relay->posts as $post ) { 110 111 $locale = apply_filters( "juvo_mail_editor_{$trigger}_language", $blogLocale, $relay->context ); 119 112 $lang = locale_get_primary_language( $locale ); 120 113 … … 129 122 130 123 // Recipients 131 $recipients = $ this->prepareRecipients( $post );124 $recipients = $relay->prepareRecipients( $post ); 132 125 133 126 // Content 134 $content = $ this->prepareContent( $post );127 $content = $relay->prepareContent( $post ); 135 128 136 129 // Subject 137 $subject = $ this->prepareSubject( $post );130 $subject = $relay->prepareSubject( $post ); 138 131 139 132 // Restore language context … … 150 143 151 144 // Some triggers might only send mails if a post is associated 152 $alwaysSent = apply_filters( "juvo_mail_editor_{$t his->trigger}_always_sent", false );145 $alwaysSent = apply_filters( "juvo_mail_editor_{$trigger}_always_sent", false ); 153 146 if ( ! $alwaysSent ) { 154 147 return false; 155 148 } 156 149 157 $lang = apply_filters( "juvo_mail_editor_{$t his->trigger}_language", $blogLocale, $this->context );150 $lang = apply_filters( "juvo_mail_editor_{$trigger}_language", $blogLocale, $relay->context ); 158 151 159 152 $switched_locale = switch_to_locale( $lang ); 160 153 161 154 // Fallback if not posts are found for configured trigger 162 $content = $ this->prepareContent();163 $subject = $ this->prepareSubject();164 $recipients = $ this->prepareRecipients();155 $content = $relay->prepareContent(); 156 $subject = $relay->prepareSubject(); 157 $recipients = $relay->prepareRecipients(); 165 158 166 159 if ( $switched_locale ) { … … 192 185 193 186 return false; 187 } 188 189 /** 190 * @param WP_Post|null $post 191 * 192 * @return string 193 */ 194 public function prepareRecipients( WP_Post $post = null ): string { 195 196 // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure 197 if ( ! $post || ! $recipients = get_post_meta( $post->ID, Mails_PT::POST_TYPE_NAME . '_recipients', true ) ) { 198 $recipients = apply_filters( "juvo_mail_editor_{$this->trigger}_default_recipients", '' ); 199 } 200 201 $recipients = apply_filters( 'juvo_mail_editor_before_recipient_placeholder', $recipients, $this->trigger, $this->context ); 202 $recipients = Placeholder::replacePlaceholder( $this->placeholders, $recipients, $this->context ); 203 204 return apply_filters( 'juvo_mail_editor_after_recipient_placeholder', $recipients, $this->trigger, $this->context ); 194 205 } 195 206 … … 257 268 258 269 /** 259 * @param WP_Post|null $post260 *261 * @return string262 */263 public function prepareRecipients( WP_Post $post = null ): string {264 265 // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure266 if ( ! $post || ! $recipients = get_post_meta( $post->ID, Mails_PT::POST_TYPE_NAME . '_recipients', true ) ) {267 $recipients = apply_filters( "juvo_mail_editor_{$this->trigger}_default_recipients", '' );268 }269 270 $recipients = apply_filters( 'juvo_mail_editor_before_recipient_placeholder', $recipients, $this->trigger, $this->context );271 $recipients = Placeholder::replacePlaceholder( $this->placeholders, $recipients, $this->context );272 273 return apply_filters( 'juvo_mail_editor_after_recipient_placeholder', $recipients, $this->trigger, $this->context );274 }275 276 /**277 270 * @return array 278 271 */ -
juvo-mail-editor/tags/3.0.2/vendor/autoload.php
r2654150 r2655718 5 5 require_once __DIR__ . '/composer/autoload_real.php'; 6 6 7 return ComposerAutoloaderInit 76482599c4a7f1e1877c9fc12cff0611::getLoader();7 return ComposerAutoloaderInitea9602c371634370be8f852af5c4b8cd::getLoader(); -
juvo-mail-editor/tags/3.0.2/vendor/composer/autoload_real.php
r2654150 r2655718 3 3 // autoload_real.php @generated by Composer 4 4 5 class ComposerAutoloaderInit 76482599c4a7f1e1877c9fc12cff06115 class ComposerAutoloaderInitea9602c371634370be8f852af5c4b8cd 6 6 { 7 7 private static $loader; … … 23 23 } 24 24 25 spl_autoload_register(array('ComposerAutoloaderInit 76482599c4a7f1e1877c9fc12cff0611', 'loadClassLoader'), true, true);25 spl_autoload_register(array('ComposerAutoloaderInitea9602c371634370be8f852af5c4b8cd', 'loadClassLoader'), true, true); 26 26 self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__))); 27 spl_autoload_unregister(array('ComposerAutoloaderInit 76482599c4a7f1e1877c9fc12cff0611', 'loadClassLoader'));27 spl_autoload_unregister(array('ComposerAutoloaderInitea9602c371634370be8f852af5c4b8cd', 'loadClassLoader')); 28 28 29 29 $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); … … 31 31 require __DIR__ . '/autoload_static.php'; 32 32 33 call_user_func(\Composer\Autoload\ComposerStaticInit 76482599c4a7f1e1877c9fc12cff0611::getInitializer($loader));33 call_user_func(\Composer\Autoload\ComposerStaticInitea9602c371634370be8f852af5c4b8cd::getInitializer($loader)); 34 34 } else { 35 35 $map = require __DIR__ . '/autoload_namespaces.php'; … … 52 52 53 53 if ($useStaticLoader) { 54 $includeFiles = Composer\Autoload\ComposerStaticInit 76482599c4a7f1e1877c9fc12cff0611::$files;54 $includeFiles = Composer\Autoload\ComposerStaticInitea9602c371634370be8f852af5c4b8cd::$files; 55 55 } else { 56 56 $includeFiles = require __DIR__ . '/autoload_files.php'; 57 57 } 58 58 foreach ($includeFiles as $fileIdentifier => $file) { 59 composerRequire 76482599c4a7f1e1877c9fc12cff0611($fileIdentifier, $file);59 composerRequireea9602c371634370be8f852af5c4b8cd($fileIdentifier, $file); 60 60 } 61 61 … … 64 64 } 65 65 66 function composerRequire 76482599c4a7f1e1877c9fc12cff0611($fileIdentifier, $file)66 function composerRequireea9602c371634370be8f852af5c4b8cd($fileIdentifier, $file) 67 67 { 68 68 if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { -
juvo-mail-editor/tags/3.0.2/vendor/composer/autoload_static.php
r2654150 r2655718 5 5 namespace Composer\Autoload; 6 6 7 class ComposerStaticInit 76482599c4a7f1e1877c9fc12cff06117 class ComposerStaticInitea9602c371634370be8f852af5c4b8cd 8 8 { 9 9 public static $files = array ( … … 94 94 { 95 95 return \Closure::bind(function () use ($loader) { 96 $loader->prefixLengthsPsr4 = ComposerStaticInit 76482599c4a7f1e1877c9fc12cff0611::$prefixLengthsPsr4;97 $loader->prefixDirsPsr4 = ComposerStaticInit 76482599c4a7f1e1877c9fc12cff0611::$prefixDirsPsr4;98 $loader->fallbackDirsPsr4 = ComposerStaticInit 76482599c4a7f1e1877c9fc12cff0611::$fallbackDirsPsr4;99 $loader->prefixesPsr0 = ComposerStaticInit 76482599c4a7f1e1877c9fc12cff0611::$prefixesPsr0;100 $loader->classMap = ComposerStaticInit 76482599c4a7f1e1877c9fc12cff0611::$classMap;96 $loader->prefixLengthsPsr4 = ComposerStaticInitea9602c371634370be8f852af5c4b8cd::$prefixLengthsPsr4; 97 $loader->prefixDirsPsr4 = ComposerStaticInitea9602c371634370be8f852af5c4b8cd::$prefixDirsPsr4; 98 $loader->fallbackDirsPsr4 = ComposerStaticInitea9602c371634370be8f852af5c4b8cd::$fallbackDirsPsr4; 99 $loader->prefixesPsr0 = ComposerStaticInitea9602c371634370be8f852af5c4b8cd::$prefixesPsr0; 100 $loader->classMap = ComposerStaticInitea9602c371634370be8f852af5c4b8cd::$classMap; 101 101 102 102 }, null, ClassLoader::class); -
juvo-mail-editor/tags/3.0.2/vendor/composer/installed.php
r2654150 r2655718 1 1 <?php return array( 2 2 'root' => array( 3 'pretty_version' => '3.0. 1',4 'version' => '3.0. 1.0',3 'pretty_version' => '3.0.2', 4 'version' => '3.0.2.0', 5 5 'type' => 'wordpress-plugin', 6 6 'install_path' => __DIR__ . '/../../', 7 7 'aliases' => array(), 8 'reference' => ' 4d9364fb994ade9d09584753f64df3f53b155ccc',8 'reference' => '6fd4fbd2bc7de6e147bda5e1da988cae07a8694f', 9 9 'name' => 'juvo/mail-editor', 10 10 'dev' => false, … … 39 39 ), 40 40 'juvo/mail-editor' => array( 41 'pretty_version' => '3.0. 1',42 'version' => '3.0. 1.0',41 'pretty_version' => '3.0.2', 42 'version' => '3.0.2.0', 43 43 'type' => 'wordpress-plugin', 44 44 'install_path' => __DIR__ . '/../../', 45 45 'aliases' => array(), 46 'reference' => ' 4d9364fb994ade9d09584753f64df3f53b155ccc',46 'reference' => '6fd4fbd2bc7de6e147bda5e1da988cae07a8694f', 47 47 'dev_requirement' => false, 48 48 ), -
juvo-mail-editor/trunk/juvo-mail-editor.php
r2654150 r2655718 8 8 * Text Domain: juvo-mail-editor 9 9 * Domain Path: /languages 10 * Version: 3.0. 110 * Version: 3.0.2 11 11 */ 12 12 -
juvo-mail-editor/trunk/readme.txt
r2654150 r2655718 4 4 License: GPLv2 or later 5 5 Tested up to: 5.8 6 Stable tag: 3.0. 16 Stable tag: 3.0.2 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/Mail_Editor.php
r2654150 r2655718 120 120 121 121 /** 122 * Handle Sending 123 */ 124 add_action( "juvo_mail_editor_send", array( Relay::class, 'sendMails' ), 10, 2 ); 125 126 /** 122 127 * Placeholders 123 128 */ … … 127 132 * New User Notification for enduser 128 133 */ 129 $this->loader->add_action( 'wp_new_user_notification_email', new New_User(), ' send', 10, 2 );130 $this->loader->add_action( 'rest_insert_user', new New_User_Rest(), ' send', 12, 1 ); // Rest134 $this->loader->add_action( 'wp_new_user_notification_email', new New_User(), 'prepareSend', 10, 2 ); 135 $this->loader->add_action( 'rest_insert_user', new New_User_Rest(), 'prepareSend', 12, 1 ); // Rest 131 136 132 137 /** 133 138 * New User Notification Admin 134 139 */ 135 $this->loader->add_action( 'wp_new_user_notification_email_admin', new New_User_Admin(), ' send', 10, 2 );136 $this->loader->add_action( 'rest_insert_user', new New_User_Admin_Rest(), ' send', 12, 1 ); // Rest140 $this->loader->add_action( 'wp_new_user_notification_email_admin', new New_User_Admin(), 'prepareSend', 10, 2 ); 141 $this->loader->add_action( 'rest_insert_user', new New_User_Admin_Rest(), 'prepareSend', 12, 1 ); // Rest 137 142 138 143 /** 139 144 * Password Reset 140 145 */ 141 $this->loader->add_filter( 'retrieve_password_message', new Password_Reset(), ' send', 10, 4 );146 $this->loader->add_filter( 'retrieve_password_message', new Password_Reset(), 'prepareSend', 10, 4 ); 142 147 143 148 /** 144 149 * Password Reset Admin 145 150 */ 146 $this->loader->add_filter( 'retrieve_password_message', new Password_Reset_Admin(), ' send', 99, 4 );151 $this->loader->add_filter( 'retrieve_password_message', new Password_Reset_Admin(), 'prepareSend', 99, 4 ); 147 152 148 153 /** 149 154 * Password Changed 150 155 */ 151 $this->loader->add_filter( 'password_change_email', new Password_Changed(), ' send', 10, 2 );156 $this->loader->add_filter( 'password_change_email', new Password_Changed(), 'prepareSend', 10, 2 ); 152 157 153 158 /** 154 159 * Password Changed Admin 155 160 */ 156 $this->loader->add_filter( 'wp_password_change_notification_email', new Password_Changed_Admin(), ' send', 10, 2 );161 $this->loader->add_filter( 'wp_password_change_notification_email', new Password_Changed_Admin(), 'prepareSend', 10, 2 ); 157 162 158 163 /** -
juvo-mail-editor/trunk/src/Mail_Generator.php
r2654150 r2655718 19 19 add_filter( "juvo_mail_editor_{$this->getTrigger()}_default_recipients", array( $this, 'getRecipient' ), 1, 0 ); 20 20 add_filter( 21 "juvo_mail_editor_{$this->getTrigger()}_ default_placeholder",21 "juvo_mail_editor_{$this->getTrigger()}_placeholders", 22 22 array( 23 23 $this, 24 'get DefaultPlaceholder',24 'getPlaceholders', 25 25 ), 26 26 1, 27 027 2 28 28 ); 29 29 add_filter( "juvo_mail_editor_{$this->getTrigger()}_language", array( $this, 'getLanguage' ), 1, 2 ); 30 30 } 31 31 32 /** 33 * Returns the trigger slug which should be unique and is used for all consecutive filters and actions 34 * 35 * @return string trigger slug 36 */ 32 37 abstract protected function getTrigger(): string; 33 38 34 abstract public function send( ...$params ); 39 /** 40 * Returns the custom placeholders available for this trigger. 41 * They may not necessarily have a value. 42 * 43 * The function should always return all custom placeholder no matter if they have a value or not. 44 * This allows filters or other functions to fill or show the placeholder in the most dynamic way. 45 * 46 * @param array|null $context 47 * 48 * @return array Array key equals the accessor in twig 49 */ 50 public function getPlaceholders( array $placeholders, ?array $context ): array { 51 return $placeholders; 52 } 35 53 36 54 /** … … 45 63 } 46 64 47 abstract protected function getName(): string; 65 /** 66 * Returns the triggers nicename in a human-readable format 67 * 68 * @return string trigger nicename 69 */ 70 abstract protected function getName(): string; // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed 48 71 49 72 /** … … 56 79 public function addCustomFields( CMB2 $cmb ): CMB2 { 57 80 return $cmb; 58 } // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed81 } 59 82 60 83 public function postHasTrigger( CMB2_Field $field ): bool { … … 73 96 return $language; 74 97 } 75 76 /**77 * Fill the default placeholders with their real values.78 * Params are most likely equal to the context.79 * This function should be called inside the send() method.80 *81 * @return array82 */83 abstract protected function getPlaceholderValues(): array;84 98 85 99 /** … … 102 116 } 103 117 118 /** 119 * Utility function that completely empties the often used mail array. 120 * This is most useful if hooking into native core function 121 * 122 * @param array $email 123 * @param null $val 124 * 125 * @return array 126 */ 104 127 protected function emptyMailArray( array $email, $val = null ): array { 105 128 foreach ( $email as $key => $item ) { -
juvo-mail-editor/trunk/src/Mail_Trigger_TAX.php
r2644151 r2655718 122 122 ); 123 123 } 124 124 125 if ( is_wp_error( $term ) ) { 125 126 $errors->add( 'juvo_mail_editor_term_error', $term->get_error_message() ); … … 127 128 } 128 129 129 // wp_insert_term returns an error while wp_update_term return an instance of WP_Term... thanks for nothing130 // normalize $term to be the term_id131 if ( is_array( $term ) ) {132 $term = $term['term_id'];133 } else { // @phpstan-ignore-line134 $term = $term->term_id;135 }136 130 } 137 131 -
juvo-mail-editor/trunk/src/Mails/Mail.php
r2654150 r2655718 11 11 public function getRecipient(): string; 12 12 13 /**14 * Return default placeholder set15 *16 * @return array17 */18 public function getDefaultPlaceholder(): array;19 20 13 public function getAlwaysSent(): bool; 21 14 -
juvo-mail-editor/trunk/src/Mails/New_User.php
r2654150 r2655718 4 4 5 5 use JUVO_MailEditor\Mail_Generator; 6 use JUVO_MailEditor\Relay;7 6 use WP_User; 8 7 9 8 class New_User extends Mail_Generator { 10 11 protected WP_User $user;12 9 13 10 protected function getTrigger(): string { … … 15 12 } 16 13 17 public function send( ...$params ) { 18 list( $email, $user ) = $params; 19 20 $this->user = $user; 21 22 $placeholders = $this->getPlaceholderValues(); 23 24 $relay = new Relay( $this->getTrigger(), $placeholders, array( 'user' => $user ) ); 25 $relay->sendMails(); 26 14 public function prepareSend( array $email, WP_User $user ): array { 15 do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user ] ); 27 16 return $this->emptyMailArray( $email ); 28 17 } 29 18 30 19 /** 31 * @inheritDoc 20 * @param array|null $context 21 * 22 * @return string[] 32 23 */ 33 protected function getPlaceholderValues(): array { 34 $placeholders = $this->getDefaultPlaceholder(); 24 public function getPlaceholders( array $placeholders, ?array $context ): array { 35 25 36 $adt_rp_key = get_password_reset_key( $this->user ); 37 $user_login = $this->user->user_login; 26 $placeholders = array_merge( $placeholders, array( 27 'password_reset_link' => '', 28 ) ); 29 30 if ( empty( $context ) ) { 31 return $placeholders; 32 } 33 34 $adt_rp_key = get_password_reset_key( $context['user'] ); 35 $user_login = $context['user']->user_login; 38 36 $placeholders['password_reset_link'] = '<a href="' . network_site_url( "wp-login.php?action=rp&key=$adt_rp_key&login=" . rawurlencode( $user_login ), 'login' ) . '">' . network_site_url( "wp-login.php?action=rp&key=$adt_rp_key&login=" . rawurlencode( $user_login ), 'login' ) . '</a>'; 39 37 40 38 return $placeholders; 41 }42 43 /**44 * @inheritDoc45 */46 public function getDefaultPlaceholder(): array {47 return array(48 'password_reset_link' => '',49 );50 39 } 51 40 -
juvo-mail-editor/trunk/src/Mails/New_User_Admin.php
r2654150 r2655718 4 4 5 5 use JUVO_MailEditor\Mail_Generator; 6 use JUVO_MailEditor\Relay;7 6 use WP_User; 8 7 9 8 class New_User_Admin extends Mail_Generator { 10 11 protected WP_User $user;12 9 13 10 /** … … 18 15 } 19 16 20 public function send( ...$params ) { 21 list( $email, $user ) = $params; 22 23 $this->user = $user; 24 25 $placeholders = $this->getPlaceholderValues(); 26 27 $relay = new Relay( $this->getTrigger(), $placeholders, array( 'user' => $user ) ); 28 $relay->sendMails(); 29 17 public function prepareSend( array $email, WP_User $user ): array { 18 do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user ] ); 30 19 return $this->emptyMailArray( $email ); 31 20 } … … 51 40 } 52 41 53 /**54 * @inheritDoc55 */56 public function getDefaultPlaceholder(): array {57 return array();58 }59 60 /**61 * @inheritDoc62 */63 protected function getPlaceholderValues(): array {64 return array();65 }66 67 42 public function getAlwaysSent(): bool { 68 43 return true; -
juvo-mail-editor/trunk/src/Mails/New_User_Admin_Rest.php
r2654150 r2655718 4 4 5 5 use JUVO_MailEditor\Mail_Generator; 6 use JUVO_MailEditor\Relay;6 use WP_User; 7 7 8 8 class New_User_Admin_Rest extends Mail_Generator { 9 9 10 public function send( ...$params ) { 11 list( $user ) = $params; 12 13 $placeholders = $this->getPlaceholderValues(); 14 15 $relay = new Relay( $this->getTrigger(), $placeholders, array( 'user' => $user ) ); 16 $relay->sendMails(); 17 } 18 19 /** 20 * @inheritDoc 21 */ 22 protected function getPlaceholderValues(): array { 23 return array(); 10 public function prepareSend( WP_User $user ): void { 11 do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user ] ); 24 12 } 25 13 … … 51 39 } 52 40 53 /**54 * @inheritDoc55 */56 public function getDefaultPlaceholder(): array {57 return array();58 }59 60 41 public function getAlwaysSent(): bool { 61 42 return false; -
juvo-mail-editor/trunk/src/Mails/New_User_Rest.php
r2654150 r2655718 4 4 5 5 use JUVO_MailEditor\Mail_Generator; 6 use JUVO_MailEditor\Relay;7 6 use WP_User; 8 7 9 8 class New_User_Rest extends Mail_Generator { 10 9 11 protected WP_User $user; 12 13 public function send( ...$params ) { 14 list( $user ) = $params; 15 16 $this->user = $user; 17 18 $placeholders = $this->getPlaceholderValues(); 19 20 $relay = new Relay( $this->getTrigger(), $placeholders, array( 'user' => $user ) ); 21 $relay->sendMails(); 10 public function prepareSend( WP_User $user ) { 11 do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user ] ); 22 12 } 23 13 … … 25 15 * @inheritDoc 26 16 */ 27 p rotected function getPlaceholderValues(): array {17 public function getPlaceholders( array $placeholders, ?array $context ): array { 28 18 29 $placeholders = $this->getDefaultPlaceholder(); 19 $placeholders = array_merge( $placeholders, array( 20 'password_reset_link' => '', 21 ) ); 30 22 31 $adt_rp_key = get_password_reset_key( $this->user ); 32 $user_login = $this->user->user_login; 23 if ( empty( $context ) ) { 24 return $placeholders; 25 } 26 27 $adt_rp_key = get_password_reset_key( $context['user'] ); 28 $user_login = $context['user']->user_login; 33 29 $placeholders['password_reset_link'] = '<a href="' . network_site_url( "wp-login.php?action=rp&key=$adt_rp_key&login=" . rawurlencode( $user_login ), 'login' ) . '">' . network_site_url( "wp-login.php?action=rp&key=$adt_rp_key&login=" . rawurlencode( $user_login ), 'login' ) . '</a>'; 34 30 35 31 return $placeholders; 32 36 33 } 37 34 -
juvo-mail-editor/trunk/src/Mails/Password_Changed.php
r2654150 r2655718 8 8 use JUVO_MailEditor\Mail_Trigger_TAX; 9 9 use JUVO_MailEditor\Mails_PT; 10 use JUVO_MailEditor\Relay;11 10 use WP_User; 12 11 … … 65 64 } 66 65 67 public function send( ...$params ) { 68 list( $email, $user ) = $params; 69 70 $placeholders = $this->getPlaceholderValues(); 71 72 $relay = new Relay( $this->getTrigger(), $placeholders, array( 'user' => $user ) ); 73 $relay->sendMails(); 66 public function prepareSend( array $email, WP_User $user ): array { 67 do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user ] ); 74 68 75 69 return $this->emptyMailArray( $email ); 76 }77 78 /**79 * @inheritDoc80 */81 protected function getPlaceholderValues(): array {82 return array();83 }84 85 /**86 * @inheritDoc87 */88 public function getDefaultPlaceholder(): array {89 return array();90 70 } 91 71 -
juvo-mail-editor/trunk/src/Mails/Password_Changed_Admin.php
r2654150 r2655718 8 8 use JUVO_MailEditor\Mail_Trigger_TAX; 9 9 use JUVO_MailEditor\Mails_PT; 10 use JUVO_MailEditor\Relay;11 10 use WP_User; 12 11 … … 37 36 } 38 37 39 public function send( ...$params ) { 40 list( $email, $user ) = $params; 41 42 $placeholders = $this->getPlaceholderValues(); 43 44 $relay = new Relay( $this->getTrigger(), $placeholders, array( 'user' => $user ) ); 45 $relay->sendMails(); 46 38 public function prepareSend( array $email, WP_User $user ): array { 39 do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user ] ); 47 40 return $this->emptyMailArray( $email ); 48 }49 50 /**51 * @inheritDoc52 */53 protected function getPlaceholderValues(): array {54 return array();55 }56 57 /**58 * @inheritDoc59 */60 public function getDefaultPlaceholder(): array {61 return array();62 41 } 63 42 … … 66 45 } 67 46 68 protected function setPlaceholderValues( WP_User $user, array $options = array() ): void {69 }70 71 47 protected function getName(): string { 72 48 return 'Password Changed (Admin)'; -
juvo-mail-editor/trunk/src/Mails/Password_Reset.php
r2654150 r2655718 8 8 use JUVO_MailEditor\Mail_Trigger_TAX; 9 9 use JUVO_MailEditor\Mails_PT; 10 use JUVO_MailEditor\Relay;11 10 use WP_User; 12 11 13 12 class Password_Reset extends Mail_Generator { 14 15 protected WP_User $user;16 protected string $key;17 13 18 14 protected function getTrigger(): string { … … 28 24 } 29 25 30 public function send( ...$params ) { 31 list( $message, $key, $user_login, $user ) = $params; 32 33 $this->user = $user; 34 $this->key = $key; 35 36 $placeholders = $this->getPlaceholderValues(); 37 38 $relay = new Relay( $this->getTrigger(), $placeholders, array( 'user' => $user ) ); 39 $relay->sendMails(); 40 26 public function prepareSend( $message, string $key, $user_login, WP_User $user ): string { 27 do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user, 'key' => $key ] ); 41 28 return ''; 42 29 } … … 68 55 * @inheritDoc 69 56 */ 70 public function getDefaultPlaceholder(): array { 71 return array( 57 public function getPlaceholders( array $placeholders, ?array $context ): array { 58 59 $placeholders = array_merge( $placeholders, array( 72 60 'password_reset_link' => '', 73 ); 74 } 61 ) ); 75 62 76 /** 77 * @inheritDoc 78 */ 79 protected function getPlaceholderValues(): array { 63 if ( empty( $context ) ) { 64 return $placeholders; 65 } 80 66 81 $placeholders = $this->getDefaultPlaceholder(); 82 83 if ( ! empty( $this->key ) ) { 84 $placeholders['password_reset_link'] = '<a href="' . network_site_url( "wp-login.php?action=rp&key={$this->key}&login=" . rawurlencode( $this->user->user_login ), 'login' ) . '">' . network_site_url( "wp-login.php?action=rp&key={$this->key}&login=" . rawurlencode( $this->user->user_login ), 'login' ) . '</a>'; 67 if ( ! empty( $context['key'] ) ) { 68 $placeholders['password_reset_link'] = '<a href="' . network_site_url( "wp-login.php?action=rp&key={$context['key']}&login=" . rawurlencode( $context['user']->user_login ), 'login' ) . '">' . network_site_url( "wp-login.php?action=rp&key={$context['key']}&login=" . rawurlencode( $context['user']->user_login ), 'login' ) . '</a>'; 85 69 } 86 70 -
juvo-mail-editor/trunk/src/Mails/Password_Reset_Admin.php
r2654150 r2655718 6 6 use CMB2; 7 7 use JUVO_MailEditor\Mail_Generator; 8 use JUVO_MailEditor\Relay;8 use WP_User; 9 9 10 10 class Password_Reset_Admin extends Mail_Generator { … … 30 30 } 31 31 32 public function send( ...$params ) { 33 list( $message, $key, $user_login, $user ) = $params; 34 35 $placeholders = $this->getPlaceholderValues(); 36 37 $relay = new Relay( $this->getTrigger(), $placeholders, array( 'user' => $user ) ); 38 $relay->sendMails(); 39 32 public function prepareSend( $message, $key, $user_login, WP_User $user ): string { 33 do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user, 'key' => $key ] ); 40 34 return ''; 41 }42 43 /**44 * @inheritDoc45 */46 protected function getPlaceholderValues(): array {47 return array();48 35 } 49 36 50 37 protected function getTrigger(): string { 51 38 return 'password_reset_admin'; 52 }53 54 /**55 * @inheritDoc56 */57 public function getDefaultPlaceholder(): array {58 return array();59 39 } 60 40 -
juvo-mail-editor/trunk/src/Mails_PT.php
r2644151 r2655718 85 85 array( 86 86 'name' => __( 'Recipients', 'juvo-mail-editor' ), 87 'desc' => __( 'Comma seperated list of mail addresses <br><code>{{CONTEXT}}</code><code>{{ADMIN_EMAIL}}</code>', 'juvo-mail-editor' ),87 'desc' => __( 'Comma seperated list of mail addresses', 'juvo-mail-editor' ), 88 88 'id' => self::POST_TYPE_NAME . '_recipients', 89 89 'type' => 'text', -
juvo-mail-editor/trunk/src/Relay.php
r2644151 r2655718 37 37 * 38 38 * @param string $trigger 39 * @param array $placeholders40 39 * @param array $context 41 */ 42 public function __construct( string $trigger, array $placeholders, array $context = array() ) { 40 * @param WP_Term $term 41 */ 42 public function __construct( string $trigger, array $context, WP_Term $term ) { 43 43 $this->trigger = $trigger; 44 44 $this->context = $context; 45 $this->term = $t his->setTerm();45 $this->term = $term; 46 46 $this->posts = $this->setPostsForTrigger(); 47 $this->placeholders = $this->preparePlaceholders( $placeholders ); 48 } 49 50 /** 51 * @return false|WP_Term 52 */ 53 private function setTerm() { 54 return get_term_by( 'slug', $this->trigger, Mail_Trigger_TAX::TAXONOMY_NAME ); 47 $this->placeholders = $this->preparePlaceholders(); 55 48 } 56 49 … … 79 72 80 73 /** 81 * @param array $placeholders82 *83 74 * @return array 84 75 */ 85 public function preparePlaceholders( array $placeholders ): array { 86 $defaultPlaceholders = apply_filters( "juvo_mail_editor_{$this->trigger}_default_placeholder", array() ); 87 88 if ( ! $defaultPlaceholders ) { 89 return $defaultPlaceholders; 90 } 91 92 return $placeholders + $defaultPlaceholders; 76 public function preparePlaceholders(): array { 77 return apply_filters( "juvo_mail_editor_{$this->trigger}_placeholders", array(), $this->context ); 93 78 } 94 79 … … 99 84 * If the flag is set the term defaults are used for the mailing 100 85 */ 101 public function sendMails() { 86 public static function sendMails( string $trigger, array $context = array() ) { 87 88 $term = get_term_by( 'slug', $trigger, Mail_Trigger_TAX::TAXONOMY_NAME ); 89 90 if ( ! $term instanceof WP_Term ) { 91 return false; 92 } 102 93 103 94 // Add Muted Capability 104 if ( self::triggerIsMuted( $t his->trigger ) ) {95 if ( self::triggerIsMuted( $trigger ) ) { 105 96 return false; 106 97 } 98 99 $relay = new self( $trigger, $context, $term ); 107 100 108 101 // Store blog language defaults … … 111 104 $blogLang = locale_get_primary_language( $blogLocale ); 112 105 113 if ( ! empty( $ this->posts ) ) {106 if ( ! empty( $relay->posts ) ) { 114 107 // If templates were created for trigger 115 108 116 foreach ( $ this->posts as $post ) {117 118 $locale = apply_filters( "juvo_mail_editor_{$t his->trigger}_language", $blogLocale, $this->context );109 foreach ( $relay->posts as $post ) { 110 111 $locale = apply_filters( "juvo_mail_editor_{$trigger}_language", $blogLocale, $relay->context ); 119 112 $lang = locale_get_primary_language( $locale ); 120 113 … … 129 122 130 123 // Recipients 131 $recipients = $ this->prepareRecipients( $post );124 $recipients = $relay->prepareRecipients( $post ); 132 125 133 126 // Content 134 $content = $ this->prepareContent( $post );127 $content = $relay->prepareContent( $post ); 135 128 136 129 // Subject 137 $subject = $ this->prepareSubject( $post );130 $subject = $relay->prepareSubject( $post ); 138 131 139 132 // Restore language context … … 150 143 151 144 // Some triggers might only send mails if a post is associated 152 $alwaysSent = apply_filters( "juvo_mail_editor_{$t his->trigger}_always_sent", false );145 $alwaysSent = apply_filters( "juvo_mail_editor_{$trigger}_always_sent", false ); 153 146 if ( ! $alwaysSent ) { 154 147 return false; 155 148 } 156 149 157 $lang = apply_filters( "juvo_mail_editor_{$t his->trigger}_language", $blogLocale, $this->context );150 $lang = apply_filters( "juvo_mail_editor_{$trigger}_language", $blogLocale, $relay->context ); 158 151 159 152 $switched_locale = switch_to_locale( $lang ); 160 153 161 154 // Fallback if not posts are found for configured trigger 162 $content = $ this->prepareContent();163 $subject = $ this->prepareSubject();164 $recipients = $ this->prepareRecipients();155 $content = $relay->prepareContent(); 156 $subject = $relay->prepareSubject(); 157 $recipients = $relay->prepareRecipients(); 165 158 166 159 if ( $switched_locale ) { … … 192 185 193 186 return false; 187 } 188 189 /** 190 * @param WP_Post|null $post 191 * 192 * @return string 193 */ 194 public function prepareRecipients( WP_Post $post = null ): string { 195 196 // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure 197 if ( ! $post || ! $recipients = get_post_meta( $post->ID, Mails_PT::POST_TYPE_NAME . '_recipients', true ) ) { 198 $recipients = apply_filters( "juvo_mail_editor_{$this->trigger}_default_recipients", '' ); 199 } 200 201 $recipients = apply_filters( 'juvo_mail_editor_before_recipient_placeholder', $recipients, $this->trigger, $this->context ); 202 $recipients = Placeholder::replacePlaceholder( $this->placeholders, $recipients, $this->context ); 203 204 return apply_filters( 'juvo_mail_editor_after_recipient_placeholder', $recipients, $this->trigger, $this->context ); 194 205 } 195 206 … … 257 268 258 269 /** 259 * @param WP_Post|null $post260 *261 * @return string262 */263 public function prepareRecipients( WP_Post $post = null ): string {264 265 // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure266 if ( ! $post || ! $recipients = get_post_meta( $post->ID, Mails_PT::POST_TYPE_NAME . '_recipients', true ) ) {267 $recipients = apply_filters( "juvo_mail_editor_{$this->trigger}_default_recipients", '' );268 }269 270 $recipients = apply_filters( 'juvo_mail_editor_before_recipient_placeholder', $recipients, $this->trigger, $this->context );271 $recipients = Placeholder::replacePlaceholder( $this->placeholders, $recipients, $this->context );272 273 return apply_filters( 'juvo_mail_editor_after_recipient_placeholder', $recipients, $this->trigger, $this->context );274 }275 276 /**277 270 * @return array 278 271 */ -
juvo-mail-editor/trunk/vendor/autoload.php
r2654150 r2655718 5 5 require_once __DIR__ . '/composer/autoload_real.php'; 6 6 7 return ComposerAutoloaderInit 76482599c4a7f1e1877c9fc12cff0611::getLoader();7 return ComposerAutoloaderInitea9602c371634370be8f852af5c4b8cd::getLoader(); -
juvo-mail-editor/trunk/vendor/composer/autoload_real.php
r2654150 r2655718 3 3 // autoload_real.php @generated by Composer 4 4 5 class ComposerAutoloaderInit 76482599c4a7f1e1877c9fc12cff06115 class ComposerAutoloaderInitea9602c371634370be8f852af5c4b8cd 6 6 { 7 7 private static $loader; … … 23 23 } 24 24 25 spl_autoload_register(array('ComposerAutoloaderInit 76482599c4a7f1e1877c9fc12cff0611', 'loadClassLoader'), true, true);25 spl_autoload_register(array('ComposerAutoloaderInitea9602c371634370be8f852af5c4b8cd', 'loadClassLoader'), true, true); 26 26 self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__))); 27 spl_autoload_unregister(array('ComposerAutoloaderInit 76482599c4a7f1e1877c9fc12cff0611', 'loadClassLoader'));27 spl_autoload_unregister(array('ComposerAutoloaderInitea9602c371634370be8f852af5c4b8cd', 'loadClassLoader')); 28 28 29 29 $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); … … 31 31 require __DIR__ . '/autoload_static.php'; 32 32 33 call_user_func(\Composer\Autoload\ComposerStaticInit 76482599c4a7f1e1877c9fc12cff0611::getInitializer($loader));33 call_user_func(\Composer\Autoload\ComposerStaticInitea9602c371634370be8f852af5c4b8cd::getInitializer($loader)); 34 34 } else { 35 35 $map = require __DIR__ . '/autoload_namespaces.php'; … … 52 52 53 53 if ($useStaticLoader) { 54 $includeFiles = Composer\Autoload\ComposerStaticInit 76482599c4a7f1e1877c9fc12cff0611::$files;54 $includeFiles = Composer\Autoload\ComposerStaticInitea9602c371634370be8f852af5c4b8cd::$files; 55 55 } else { 56 56 $includeFiles = require __DIR__ . '/autoload_files.php'; 57 57 } 58 58 foreach ($includeFiles as $fileIdentifier => $file) { 59 composerRequire 76482599c4a7f1e1877c9fc12cff0611($fileIdentifier, $file);59 composerRequireea9602c371634370be8f852af5c4b8cd($fileIdentifier, $file); 60 60 } 61 61 … … 64 64 } 65 65 66 function composerRequire 76482599c4a7f1e1877c9fc12cff0611($fileIdentifier, $file)66 function composerRequireea9602c371634370be8f852af5c4b8cd($fileIdentifier, $file) 67 67 { 68 68 if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { -
juvo-mail-editor/trunk/vendor/composer/autoload_static.php
r2654150 r2655718 5 5 namespace Composer\Autoload; 6 6 7 class ComposerStaticInit 76482599c4a7f1e1877c9fc12cff06117 class ComposerStaticInitea9602c371634370be8f852af5c4b8cd 8 8 { 9 9 public static $files = array ( … … 94 94 { 95 95 return \Closure::bind(function () use ($loader) { 96 $loader->prefixLengthsPsr4 = ComposerStaticInit 76482599c4a7f1e1877c9fc12cff0611::$prefixLengthsPsr4;97 $loader->prefixDirsPsr4 = ComposerStaticInit 76482599c4a7f1e1877c9fc12cff0611::$prefixDirsPsr4;98 $loader->fallbackDirsPsr4 = ComposerStaticInit 76482599c4a7f1e1877c9fc12cff0611::$fallbackDirsPsr4;99 $loader->prefixesPsr0 = ComposerStaticInit 76482599c4a7f1e1877c9fc12cff0611::$prefixesPsr0;100 $loader->classMap = ComposerStaticInit 76482599c4a7f1e1877c9fc12cff0611::$classMap;96 $loader->prefixLengthsPsr4 = ComposerStaticInitea9602c371634370be8f852af5c4b8cd::$prefixLengthsPsr4; 97 $loader->prefixDirsPsr4 = ComposerStaticInitea9602c371634370be8f852af5c4b8cd::$prefixDirsPsr4; 98 $loader->fallbackDirsPsr4 = ComposerStaticInitea9602c371634370be8f852af5c4b8cd::$fallbackDirsPsr4; 99 $loader->prefixesPsr0 = ComposerStaticInitea9602c371634370be8f852af5c4b8cd::$prefixesPsr0; 100 $loader->classMap = ComposerStaticInitea9602c371634370be8f852af5c4b8cd::$classMap; 101 101 102 102 }, null, ClassLoader::class); -
juvo-mail-editor/trunk/vendor/composer/installed.php
r2654150 r2655718 1 1 <?php return array( 2 2 'root' => array( 3 'pretty_version' => '3.0. 1',4 'version' => '3.0. 1.0',3 'pretty_version' => '3.0.2', 4 'version' => '3.0.2.0', 5 5 'type' => 'wordpress-plugin', 6 6 'install_path' => __DIR__ . '/../../', 7 7 'aliases' => array(), 8 'reference' => ' 4d9364fb994ade9d09584753f64df3f53b155ccc',8 'reference' => '6fd4fbd2bc7de6e147bda5e1da988cae07a8694f', 9 9 'name' => 'juvo/mail-editor', 10 10 'dev' => false, … … 39 39 ), 40 40 'juvo/mail-editor' => array( 41 'pretty_version' => '3.0. 1',42 'version' => '3.0. 1.0',41 'pretty_version' => '3.0.2', 42 'version' => '3.0.2.0', 43 43 'type' => 'wordpress-plugin', 44 44 'install_path' => __DIR__ . '/../../', 45 45 'aliases' => array(), 46 'reference' => ' 4d9364fb994ade9d09584753f64df3f53b155ccc',46 'reference' => '6fd4fbd2bc7de6e147bda5e1da988cae07a8694f', 47 47 'dev_requirement' => false, 48 48 ),
Note: See TracChangeset
for help on using the changeset viewer.