Plugin Directory

Changeset 2655718


Ignore:
Timestamp:
01/11/2022 09:57:02 AM (4 years ago)
Author:
juvodesign
Message:

Update to version 3.0.2 from GitHub

Location:
juvo-mail-editor
Files:
40 edited
1 copied

Legend:

Unmodified
Added
Removed
  • juvo-mail-editor/tags/3.0.2/juvo-mail-editor.php

    r2654150 r2655718  
    88 * Text Domain:     juvo-mail-editor
    99 * Domain Path:     /languages
    10  * Version:         3.0.1
     10 * Version:         3.0.2
    1111 */
    1212
  • juvo-mail-editor/tags/3.0.2/readme.txt

    r2654150 r2655718  
    44License: GPLv2 or later
    55Tested up to: 5.8
    6 Stable tag: 3.0.1
     6Stable tag: 3.0.2
    77
    88JUVO 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  
    120120
    121121        /**
     122         * Handle Sending
     123         */
     124        add_action( "juvo_mail_editor_send", array( Relay::class, 'sendMails' ), 10, 2 );
     125
     126        /**
    122127         * Placeholders
    123128         */
     
    127132         * New User Notification for enduser
    128133         */
    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 ); // Rest
     134        $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
    131136
    132137        /**
    133138         * New User Notification Admin
    134139         */
    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 ); // Rest
     140        $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
    137142
    138143        /**
    139144         * Password Reset
    140145         */
    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 );
    142147
    143148        /**
    144149         * Password Reset Admin
    145150         */
    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 );
    147152
    148153        /**
    149154         * Password Changed
    150155         */
    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 );
    152157
    153158        /**
    154159         * Password Changed Admin
    155160         */
    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 );
    157162
    158163        /**
  • juvo-mail-editor/tags/3.0.2/src/Mail_Generator.php

    r2654150 r2655718  
    1919        add_filter( "juvo_mail_editor_{$this->getTrigger()}_default_recipients", array( $this, 'getRecipient' ), 1, 0 );
    2020        add_filter(
    21             "juvo_mail_editor_{$this->getTrigger()}_default_placeholder",
     21            "juvo_mail_editor_{$this->getTrigger()}_placeholders",
    2222            array(
    2323                $this,
    24                 'getDefaultPlaceholder',
     24                'getPlaceholders',
    2525            ),
    2626            1,
    27             0
     27            2
    2828        );
    2929        add_filter( "juvo_mail_editor_{$this->getTrigger()}_language", array( $this, 'getLanguage' ), 1, 2 );
    3030    }
    3131
     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     */
    3237    abstract protected function getTrigger(): string;
    3338
    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    }
    3553
    3654    /**
     
    4563    }
    4664
    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
    4871
    4972    /**
     
    5679    public function addCustomFields( CMB2 $cmb ): CMB2 {
    5780        return $cmb;
    58     } // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
     81    }
    5982
    6083    public function postHasTrigger( CMB2_Field $field ): bool {
     
    7396        return $language;
    7497    }
    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 array
    82      */
    83     abstract protected function getPlaceholderValues(): array;
    8498
    8599    /**
     
    102116    }
    103117
     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     */
    104127    protected function emptyMailArray( array $email, $val = null ): array {
    105128        foreach ( $email as $key => $item ) {
  • juvo-mail-editor/tags/3.0.2/src/Mail_Trigger_TAX.php

    r2644151 r2655718  
    122122                );
    123123            }
     124
    124125            if ( is_wp_error( $term ) ) {
    125126                $errors->add( 'juvo_mail_editor_term_error', $term->get_error_message() );
     
    127128            }
    128129
    129             // wp_insert_term returns an error while wp_update_term return an instance of WP_Term... thanks for nothing
    130             // normalize $term to be the term_id
    131             if ( is_array( $term ) ) {
    132                 $term = $term['term_id'];
    133             } else { // @phpstan-ignore-line
    134                 $term = $term->term_id;
    135             }
    136130        }
    137131
  • juvo-mail-editor/tags/3.0.2/src/Mails/Mail.php

    r2654150 r2655718  
    1111    public function getRecipient(): string;
    1212
    13     /**
    14      * Return default placeholder set
    15      *
    16      * @return array
    17      */
    18     public function getDefaultPlaceholder(): array;
    19 
    2013    public function getAlwaysSent(): bool;
    2114
  • juvo-mail-editor/tags/3.0.2/src/Mails/New_User.php

    r2654150 r2655718  
    44
    55use JUVO_MailEditor\Mail_Generator;
    6 use JUVO_MailEditor\Relay;
    76use WP_User;
    87
    98class New_User extends Mail_Generator {
    10 
    11     protected WP_User $user;
    129
    1310    protected function getTrigger(): string {
     
    1512    }
    1613
    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 ] );
    2716        return $this->emptyMailArray( $email );
    2817    }
    2918
    3019    /**
    31      * @inheritDoc
     20     * @param array|null $context
     21     *
     22     * @return string[]
    3223     */
    33     protected function getPlaceholderValues(): array {
    34         $placeholders = $this->getDefaultPlaceholder();
     24    public function getPlaceholders( array $placeholders, ?array $context ): array {
    3525
    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;
    3836        $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>';
    3937
    4038        return $placeholders;
    41     }
    42 
    43     /**
    44      * @inheritDoc
    45      */
    46     public function getDefaultPlaceholder(): array {
    47         return array(
    48             'password_reset_link' => '',
    49         );
    5039    }
    5140
  • juvo-mail-editor/tags/3.0.2/src/Mails/New_User_Admin.php

    r2654150 r2655718  
    44
    55use JUVO_MailEditor\Mail_Generator;
    6 use JUVO_MailEditor\Relay;
    76use WP_User;
    87
    98class New_User_Admin extends Mail_Generator {
    10 
    11     protected WP_User $user;
    129
    1310    /**
     
    1815    }
    1916
    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 ] );
    3019        return $this->emptyMailArray( $email );
    3120    }
     
    5140    }
    5241
    53     /**
    54      * @inheritDoc
    55      */
    56     public function getDefaultPlaceholder(): array {
    57         return array();
    58     }
    59 
    60     /**
    61      * @inheritDoc
    62      */
    63     protected function getPlaceholderValues(): array {
    64         return array();
    65     }
    66 
    6742    public function getAlwaysSent(): bool {
    6843        return true;
  • juvo-mail-editor/tags/3.0.2/src/Mails/New_User_Admin_Rest.php

    r2654150 r2655718  
    44
    55use JUVO_MailEditor\Mail_Generator;
    6 use JUVO_MailEditor\Relay;
     6use WP_User;
    77
    88class New_User_Admin_Rest extends Mail_Generator {
    99
    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 ] );
    2412    }
    2513
     
    5139    }
    5240
    53     /**
    54      * @inheritDoc
    55      */
    56     public function getDefaultPlaceholder(): array {
    57         return array();
    58     }
    59 
    6041    public function getAlwaysSent(): bool {
    6142        return false;
  • juvo-mail-editor/tags/3.0.2/src/Mails/New_User_Rest.php

    r2654150 r2655718  
    44
    55use JUVO_MailEditor\Mail_Generator;
    6 use JUVO_MailEditor\Relay;
    76use WP_User;
    87
    98class New_User_Rest extends Mail_Generator {
    109
    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 ] );
    2212    }
    2313
     
    2515     * @inheritDoc
    2616     */
    27     protected function getPlaceholderValues(): array {
     17    public function getPlaceholders( array $placeholders, ?array $context ): array {
    2818
    29         $placeholders = $this->getDefaultPlaceholder();
     19        $placeholders = array_merge( $placeholders, array(
     20            'password_reset_link' => '',
     21        ) );
    3022
    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;
    3329        $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>';
    3430
    3531        return $placeholders;
     32
    3633    }
    3734
  • juvo-mail-editor/tags/3.0.2/src/Mails/Password_Changed.php

    r2654150 r2655718  
    88use JUVO_MailEditor\Mail_Trigger_TAX;
    99use JUVO_MailEditor\Mails_PT;
    10 use JUVO_MailEditor\Relay;
    1110use WP_User;
    1211
     
    6564    }
    6665
    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 ] );
    7468
    7569        return $this->emptyMailArray( $email );
    76     }
    77 
    78     /**
    79      * @inheritDoc
    80      */
    81     protected function getPlaceholderValues(): array {
    82         return array();
    83     }
    84 
    85     /**
    86      * @inheritDoc
    87      */
    88     public function getDefaultPlaceholder(): array {
    89         return array();
    9070    }
    9171
  • juvo-mail-editor/tags/3.0.2/src/Mails/Password_Changed_Admin.php

    r2654150 r2655718  
    88use JUVO_MailEditor\Mail_Trigger_TAX;
    99use JUVO_MailEditor\Mails_PT;
    10 use JUVO_MailEditor\Relay;
    1110use WP_User;
    1211
     
    3736    }
    3837
    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 ] );
    4740        return $this->emptyMailArray( $email );
    48     }
    49 
    50     /**
    51      * @inheritDoc
    52      */
    53     protected function getPlaceholderValues(): array {
    54         return array();
    55     }
    56 
    57     /**
    58      * @inheritDoc
    59      */
    60     public function getDefaultPlaceholder(): array {
    61         return array();
    6241    }
    6342
     
    6645    }
    6746
    68     protected function setPlaceholderValues( WP_User $user, array $options = array() ): void {
    69     }
    70 
    7147    protected function getName(): string {
    7248        return 'Password Changed (Admin)';
  • juvo-mail-editor/tags/3.0.2/src/Mails/Password_Reset.php

    r2654150 r2655718  
    88use JUVO_MailEditor\Mail_Trigger_TAX;
    99use JUVO_MailEditor\Mails_PT;
    10 use JUVO_MailEditor\Relay;
    1110use WP_User;
    1211
    1312class Password_Reset extends Mail_Generator {
    14 
    15     protected WP_User $user;
    16     protected string $key;
    1713
    1814    protected function getTrigger(): string {
     
    2824    }
    2925
    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 ] );
    4128        return '';
    4229    }
     
    6855     * @inheritDoc
    6956     */
    70     public function getDefaultPlaceholder(): array {
    71         return array(
     57    public function getPlaceholders( array $placeholders, ?array $context ): array {
     58
     59        $placeholders = array_merge( $placeholders, array(
    7260            'password_reset_link' => '',
    73         );
    74     }
     61        ) );
    7562
    76     /**
    77      * @inheritDoc
    78      */
    79     protected function getPlaceholderValues(): array {
     63        if ( empty( $context ) ) {
     64            return $placeholders;
     65        }
    8066
    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>';
    8569        }
    8670
  • juvo-mail-editor/tags/3.0.2/src/Mails/Password_Reset_Admin.php

    r2654150 r2655718  
    66use CMB2;
    77use JUVO_MailEditor\Mail_Generator;
    8 use JUVO_MailEditor\Relay;
     8use WP_User;
    99
    1010class Password_Reset_Admin extends Mail_Generator {
     
    3030    }
    3131
    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 ] );
    4034        return '';
    41     }
    42 
    43     /**
    44      * @inheritDoc
    45      */
    46     protected function getPlaceholderValues(): array {
    47         return array();
    4835    }
    4936
    5037    protected function getTrigger(): string {
    5138        return 'password_reset_admin';
    52     }
    53 
    54     /**
    55      * @inheritDoc
    56      */
    57     public function getDefaultPlaceholder(): array {
    58         return array();
    5939    }
    6040
  • juvo-mail-editor/tags/3.0.2/src/Mails_PT.php

    r2644151 r2655718  
    8585            array(
    8686                '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' ),
    8888                'id'     => self::POST_TYPE_NAME . '_recipients',
    8989                'type'   => 'text',
  • juvo-mail-editor/tags/3.0.2/src/Relay.php

    r2644151 r2655718  
    3737     *
    3838     * @param string $trigger
    39      * @param array $placeholders
    4039     * @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 ) {
    4343        $this->trigger      = $trigger;
    4444        $this->context      = $context;
    45         $this->term         = $this->setTerm();
     45        $this->term         = $term;
    4646        $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();
    5548    }
    5649
     
    7972
    8073    /**
    81      * @param array $placeholders
    82      *
    8374     * @return array
    8475     */
    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 );
    9378    }
    9479
     
    9984     * If the flag is set the term defaults are used for the mailing
    10085     */
    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        }
    10293
    10394        // Add Muted Capability
    104         if ( self::triggerIsMuted( $this->trigger ) ) {
     95        if ( self::triggerIsMuted( $trigger ) ) {
    10596            return false;
    10697        }
     98
     99        $relay = new self( $trigger, $context, $term );
    107100
    108101        // Store blog language defaults
     
    111104        $blogLang   = locale_get_primary_language( $blogLocale );
    112105
    113         if ( ! empty( $this->posts ) ) {
     106        if ( ! empty( $relay->posts ) ) {
    114107            // If templates were created for trigger
    115108
    116             foreach ( $this->posts as $post ) {
    117 
    118                 $locale = apply_filters( "juvo_mail_editor_{$this->trigger}_language", $blogLocale, $this->context );
     109            foreach ( $relay->posts as $post ) {
     110
     111                $locale = apply_filters( "juvo_mail_editor_{$trigger}_language", $blogLocale, $relay->context );
    119112                $lang   = locale_get_primary_language( $locale );
    120113
     
    129122
    130123                // Recipients
    131                 $recipients = $this->prepareRecipients( $post );
     124                $recipients = $relay->prepareRecipients( $post );
    132125
    133126                // Content
    134                 $content = $this->prepareContent( $post );
     127                $content = $relay->prepareContent( $post );
    135128
    136129                // Subject
    137                 $subject = $this->prepareSubject( $post );
     130                $subject = $relay->prepareSubject( $post );
    138131
    139132                // Restore language context
     
    150143
    151144            // Some triggers might only send mails if a post is associated
    152             $alwaysSent = apply_filters( "juvo_mail_editor_{$this->trigger}_always_sent", false );
     145            $alwaysSent = apply_filters( "juvo_mail_editor_{$trigger}_always_sent", false );
    153146            if ( ! $alwaysSent ) {
    154147                return false;
    155148            }
    156149
    157             $lang = apply_filters( "juvo_mail_editor_{$this->trigger}_language", $blogLocale, $this->context );
     150            $lang = apply_filters( "juvo_mail_editor_{$trigger}_language", $blogLocale, $relay->context );
    158151
    159152            $switched_locale = switch_to_locale( $lang );
    160153
    161154            // 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();
    165158
    166159            if ( $switched_locale ) {
     
    192185
    193186        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 );
    194205    }
    195206
     
    257268
    258269    /**
    259      * @param WP_Post|null $post
    260      *
    261      * @return string
    262      */
    263     public function prepareRecipients( WP_Post $post = null ): string {
    264 
    265         // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
    266         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     /**
    277270     * @return array
    278271     */
  • juvo-mail-editor/tags/3.0.2/vendor/autoload.php

    r2654150 r2655718  
    55require_once __DIR__ . '/composer/autoload_real.php';
    66
    7 return ComposerAutoloaderInit76482599c4a7f1e1877c9fc12cff0611::getLoader();
     7return ComposerAutoloaderInitea9602c371634370be8f852af5c4b8cd::getLoader();
  • juvo-mail-editor/tags/3.0.2/vendor/composer/autoload_real.php

    r2654150 r2655718  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInit76482599c4a7f1e1877c9fc12cff0611
     5class ComposerAutoloaderInitea9602c371634370be8f852af5c4b8cd
    66{
    77    private static $loader;
     
    2323        }
    2424
    25         spl_autoload_register(array('ComposerAutoloaderInit76482599c4a7f1e1877c9fc12cff0611', 'loadClassLoader'), true, true);
     25        spl_autoload_register(array('ComposerAutoloaderInitea9602c371634370be8f852af5c4b8cd', 'loadClassLoader'), true, true);
    2626        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
    27         spl_autoload_unregister(array('ComposerAutoloaderInit76482599c4a7f1e1877c9fc12cff0611', 'loadClassLoader'));
     27        spl_autoload_unregister(array('ComposerAutoloaderInitea9602c371634370be8f852af5c4b8cd', 'loadClassLoader'));
    2828
    2929        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
     
    3131            require __DIR__ . '/autoload_static.php';
    3232
    33             call_user_func(\Composer\Autoload\ComposerStaticInit76482599c4a7f1e1877c9fc12cff0611::getInitializer($loader));
     33            call_user_func(\Composer\Autoload\ComposerStaticInitea9602c371634370be8f852af5c4b8cd::getInitializer($loader));
    3434        } else {
    3535            $map = require __DIR__ . '/autoload_namespaces.php';
     
    5252
    5353        if ($useStaticLoader) {
    54             $includeFiles = Composer\Autoload\ComposerStaticInit76482599c4a7f1e1877c9fc12cff0611::$files;
     54            $includeFiles = Composer\Autoload\ComposerStaticInitea9602c371634370be8f852af5c4b8cd::$files;
    5555        } else {
    5656            $includeFiles = require __DIR__ . '/autoload_files.php';
    5757        }
    5858        foreach ($includeFiles as $fileIdentifier => $file) {
    59             composerRequire76482599c4a7f1e1877c9fc12cff0611($fileIdentifier, $file);
     59            composerRequireea9602c371634370be8f852af5c4b8cd($fileIdentifier, $file);
    6060        }
    6161
     
    6464}
    6565
    66 function composerRequire76482599c4a7f1e1877c9fc12cff0611($fileIdentifier, $file)
     66function composerRequireea9602c371634370be8f852af5c4b8cd($fileIdentifier, $file)
    6767{
    6868    if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
  • juvo-mail-editor/tags/3.0.2/vendor/composer/autoload_static.php

    r2654150 r2655718  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInit76482599c4a7f1e1877c9fc12cff0611
     7class ComposerStaticInitea9602c371634370be8f852af5c4b8cd
    88{
    99    public static $files = array (
     
    9494    {
    9595        return \Closure::bind(function () use ($loader) {
    96             $loader->prefixLengthsPsr4 = ComposerStaticInit76482599c4a7f1e1877c9fc12cff0611::$prefixLengthsPsr4;
    97             $loader->prefixDirsPsr4 = ComposerStaticInit76482599c4a7f1e1877c9fc12cff0611::$prefixDirsPsr4;
    98             $loader->fallbackDirsPsr4 = ComposerStaticInit76482599c4a7f1e1877c9fc12cff0611::$fallbackDirsPsr4;
    99             $loader->prefixesPsr0 = ComposerStaticInit76482599c4a7f1e1877c9fc12cff0611::$prefixesPsr0;
    100             $loader->classMap = ComposerStaticInit76482599c4a7f1e1877c9fc12cff0611::$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;
    101101
    102102        }, null, ClassLoader::class);
  • juvo-mail-editor/tags/3.0.2/vendor/composer/installed.php

    r2654150 r2655718  
    11<?php return array(
    22    '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',
    55        'type' => 'wordpress-plugin',
    66        'install_path' => __DIR__ . '/../../',
    77        'aliases' => array(),
    8         'reference' => '4d9364fb994ade9d09584753f64df3f53b155ccc',
     8        'reference' => '6fd4fbd2bc7de6e147bda5e1da988cae07a8694f',
    99        'name' => 'juvo/mail-editor',
    1010        'dev' => false,
     
    3939        ),
    4040        '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',
    4343            'type' => 'wordpress-plugin',
    4444            'install_path' => __DIR__ . '/../../',
    4545            'aliases' => array(),
    46             'reference' => '4d9364fb994ade9d09584753f64df3f53b155ccc',
     46            'reference' => '6fd4fbd2bc7de6e147bda5e1da988cae07a8694f',
    4747            'dev_requirement' => false,
    4848        ),
  • juvo-mail-editor/trunk/juvo-mail-editor.php

    r2654150 r2655718  
    88 * Text Domain:     juvo-mail-editor
    99 * Domain Path:     /languages
    10  * Version:         3.0.1
     10 * Version:         3.0.2
    1111 */
    1212
  • juvo-mail-editor/trunk/readme.txt

    r2654150 r2655718  
    44License: GPLv2 or later
    55Tested up to: 5.8
    6 Stable tag: 3.0.1
     6Stable tag: 3.0.2
    77
    88JUVO 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  
    120120
    121121        /**
     122         * Handle Sending
     123         */
     124        add_action( "juvo_mail_editor_send", array( Relay::class, 'sendMails' ), 10, 2 );
     125
     126        /**
    122127         * Placeholders
    123128         */
     
    127132         * New User Notification for enduser
    128133         */
    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 ); // Rest
     134        $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
    131136
    132137        /**
    133138         * New User Notification Admin
    134139         */
    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 ); // Rest
     140        $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
    137142
    138143        /**
    139144         * Password Reset
    140145         */
    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 );
    142147
    143148        /**
    144149         * Password Reset Admin
    145150         */
    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 );
    147152
    148153        /**
    149154         * Password Changed
    150155         */
    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 );
    152157
    153158        /**
    154159         * Password Changed Admin
    155160         */
    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 );
    157162
    158163        /**
  • juvo-mail-editor/trunk/src/Mail_Generator.php

    r2654150 r2655718  
    1919        add_filter( "juvo_mail_editor_{$this->getTrigger()}_default_recipients", array( $this, 'getRecipient' ), 1, 0 );
    2020        add_filter(
    21             "juvo_mail_editor_{$this->getTrigger()}_default_placeholder",
     21            "juvo_mail_editor_{$this->getTrigger()}_placeholders",
    2222            array(
    2323                $this,
    24                 'getDefaultPlaceholder',
     24                'getPlaceholders',
    2525            ),
    2626            1,
    27             0
     27            2
    2828        );
    2929        add_filter( "juvo_mail_editor_{$this->getTrigger()}_language", array( $this, 'getLanguage' ), 1, 2 );
    3030    }
    3131
     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     */
    3237    abstract protected function getTrigger(): string;
    3338
    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    }
    3553
    3654    /**
     
    4563    }
    4664
    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
    4871
    4972    /**
     
    5679    public function addCustomFields( CMB2 $cmb ): CMB2 {
    5780        return $cmb;
    58     } // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
     81    }
    5982
    6083    public function postHasTrigger( CMB2_Field $field ): bool {
     
    7396        return $language;
    7497    }
    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 array
    82      */
    83     abstract protected function getPlaceholderValues(): array;
    8498
    8599    /**
     
    102116    }
    103117
     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     */
    104127    protected function emptyMailArray( array $email, $val = null ): array {
    105128        foreach ( $email as $key => $item ) {
  • juvo-mail-editor/trunk/src/Mail_Trigger_TAX.php

    r2644151 r2655718  
    122122                );
    123123            }
     124
    124125            if ( is_wp_error( $term ) ) {
    125126                $errors->add( 'juvo_mail_editor_term_error', $term->get_error_message() );
     
    127128            }
    128129
    129             // wp_insert_term returns an error while wp_update_term return an instance of WP_Term... thanks for nothing
    130             // normalize $term to be the term_id
    131             if ( is_array( $term ) ) {
    132                 $term = $term['term_id'];
    133             } else { // @phpstan-ignore-line
    134                 $term = $term->term_id;
    135             }
    136130        }
    137131
  • juvo-mail-editor/trunk/src/Mails/Mail.php

    r2654150 r2655718  
    1111    public function getRecipient(): string;
    1212
    13     /**
    14      * Return default placeholder set
    15      *
    16      * @return array
    17      */
    18     public function getDefaultPlaceholder(): array;
    19 
    2013    public function getAlwaysSent(): bool;
    2114
  • juvo-mail-editor/trunk/src/Mails/New_User.php

    r2654150 r2655718  
    44
    55use JUVO_MailEditor\Mail_Generator;
    6 use JUVO_MailEditor\Relay;
    76use WP_User;
    87
    98class New_User extends Mail_Generator {
    10 
    11     protected WP_User $user;
    129
    1310    protected function getTrigger(): string {
     
    1512    }
    1613
    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 ] );
    2716        return $this->emptyMailArray( $email );
    2817    }
    2918
    3019    /**
    31      * @inheritDoc
     20     * @param array|null $context
     21     *
     22     * @return string[]
    3223     */
    33     protected function getPlaceholderValues(): array {
    34         $placeholders = $this->getDefaultPlaceholder();
     24    public function getPlaceholders( array $placeholders, ?array $context ): array {
    3525
    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;
    3836        $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>';
    3937
    4038        return $placeholders;
    41     }
    42 
    43     /**
    44      * @inheritDoc
    45      */
    46     public function getDefaultPlaceholder(): array {
    47         return array(
    48             'password_reset_link' => '',
    49         );
    5039    }
    5140
  • juvo-mail-editor/trunk/src/Mails/New_User_Admin.php

    r2654150 r2655718  
    44
    55use JUVO_MailEditor\Mail_Generator;
    6 use JUVO_MailEditor\Relay;
    76use WP_User;
    87
    98class New_User_Admin extends Mail_Generator {
    10 
    11     protected WP_User $user;
    129
    1310    /**
     
    1815    }
    1916
    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 ] );
    3019        return $this->emptyMailArray( $email );
    3120    }
     
    5140    }
    5241
    53     /**
    54      * @inheritDoc
    55      */
    56     public function getDefaultPlaceholder(): array {
    57         return array();
    58     }
    59 
    60     /**
    61      * @inheritDoc
    62      */
    63     protected function getPlaceholderValues(): array {
    64         return array();
    65     }
    66 
    6742    public function getAlwaysSent(): bool {
    6843        return true;
  • juvo-mail-editor/trunk/src/Mails/New_User_Admin_Rest.php

    r2654150 r2655718  
    44
    55use JUVO_MailEditor\Mail_Generator;
    6 use JUVO_MailEditor\Relay;
     6use WP_User;
    77
    88class New_User_Admin_Rest extends Mail_Generator {
    99
    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 ] );
    2412    }
    2513
     
    5139    }
    5240
    53     /**
    54      * @inheritDoc
    55      */
    56     public function getDefaultPlaceholder(): array {
    57         return array();
    58     }
    59 
    6041    public function getAlwaysSent(): bool {
    6142        return false;
  • juvo-mail-editor/trunk/src/Mails/New_User_Rest.php

    r2654150 r2655718  
    44
    55use JUVO_MailEditor\Mail_Generator;
    6 use JUVO_MailEditor\Relay;
    76use WP_User;
    87
    98class New_User_Rest extends Mail_Generator {
    109
    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 ] );
    2212    }
    2313
     
    2515     * @inheritDoc
    2616     */
    27     protected function getPlaceholderValues(): array {
     17    public function getPlaceholders( array $placeholders, ?array $context ): array {
    2818
    29         $placeholders = $this->getDefaultPlaceholder();
     19        $placeholders = array_merge( $placeholders, array(
     20            'password_reset_link' => '',
     21        ) );
    3022
    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;
    3329        $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>';
    3430
    3531        return $placeholders;
     32
    3633    }
    3734
  • juvo-mail-editor/trunk/src/Mails/Password_Changed.php

    r2654150 r2655718  
    88use JUVO_MailEditor\Mail_Trigger_TAX;
    99use JUVO_MailEditor\Mails_PT;
    10 use JUVO_MailEditor\Relay;
    1110use WP_User;
    1211
     
    6564    }
    6665
    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 ] );
    7468
    7569        return $this->emptyMailArray( $email );
    76     }
    77 
    78     /**
    79      * @inheritDoc
    80      */
    81     protected function getPlaceholderValues(): array {
    82         return array();
    83     }
    84 
    85     /**
    86      * @inheritDoc
    87      */
    88     public function getDefaultPlaceholder(): array {
    89         return array();
    9070    }
    9171
  • juvo-mail-editor/trunk/src/Mails/Password_Changed_Admin.php

    r2654150 r2655718  
    88use JUVO_MailEditor\Mail_Trigger_TAX;
    99use JUVO_MailEditor\Mails_PT;
    10 use JUVO_MailEditor\Relay;
    1110use WP_User;
    1211
     
    3736    }
    3837
    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 ] );
    4740        return $this->emptyMailArray( $email );
    48     }
    49 
    50     /**
    51      * @inheritDoc
    52      */
    53     protected function getPlaceholderValues(): array {
    54         return array();
    55     }
    56 
    57     /**
    58      * @inheritDoc
    59      */
    60     public function getDefaultPlaceholder(): array {
    61         return array();
    6241    }
    6342
     
    6645    }
    6746
    68     protected function setPlaceholderValues( WP_User $user, array $options = array() ): void {
    69     }
    70 
    7147    protected function getName(): string {
    7248        return 'Password Changed (Admin)';
  • juvo-mail-editor/trunk/src/Mails/Password_Reset.php

    r2654150 r2655718  
    88use JUVO_MailEditor\Mail_Trigger_TAX;
    99use JUVO_MailEditor\Mails_PT;
    10 use JUVO_MailEditor\Relay;
    1110use WP_User;
    1211
    1312class Password_Reset extends Mail_Generator {
    14 
    15     protected WP_User $user;
    16     protected string $key;
    1713
    1814    protected function getTrigger(): string {
     
    2824    }
    2925
    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 ] );
    4128        return '';
    4229    }
     
    6855     * @inheritDoc
    6956     */
    70     public function getDefaultPlaceholder(): array {
    71         return array(
     57    public function getPlaceholders( array $placeholders, ?array $context ): array {
     58
     59        $placeholders = array_merge( $placeholders, array(
    7260            'password_reset_link' => '',
    73         );
    74     }
     61        ) );
    7562
    76     /**
    77      * @inheritDoc
    78      */
    79     protected function getPlaceholderValues(): array {
     63        if ( empty( $context ) ) {
     64            return $placeholders;
     65        }
    8066
    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>';
    8569        }
    8670
  • juvo-mail-editor/trunk/src/Mails/Password_Reset_Admin.php

    r2654150 r2655718  
    66use CMB2;
    77use JUVO_MailEditor\Mail_Generator;
    8 use JUVO_MailEditor\Relay;
     8use WP_User;
    99
    1010class Password_Reset_Admin extends Mail_Generator {
     
    3030    }
    3131
    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 ] );
    4034        return '';
    41     }
    42 
    43     /**
    44      * @inheritDoc
    45      */
    46     protected function getPlaceholderValues(): array {
    47         return array();
    4835    }
    4936
    5037    protected function getTrigger(): string {
    5138        return 'password_reset_admin';
    52     }
    53 
    54     /**
    55      * @inheritDoc
    56      */
    57     public function getDefaultPlaceholder(): array {
    58         return array();
    5939    }
    6040
  • juvo-mail-editor/trunk/src/Mails_PT.php

    r2644151 r2655718  
    8585            array(
    8686                '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' ),
    8888                'id'     => self::POST_TYPE_NAME . '_recipients',
    8989                'type'   => 'text',
  • juvo-mail-editor/trunk/src/Relay.php

    r2644151 r2655718  
    3737     *
    3838     * @param string $trigger
    39      * @param array $placeholders
    4039     * @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 ) {
    4343        $this->trigger      = $trigger;
    4444        $this->context      = $context;
    45         $this->term         = $this->setTerm();
     45        $this->term         = $term;
    4646        $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();
    5548    }
    5649
     
    7972
    8073    /**
    81      * @param array $placeholders
    82      *
    8374     * @return array
    8475     */
    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 );
    9378    }
    9479
     
    9984     * If the flag is set the term defaults are used for the mailing
    10085     */
    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        }
    10293
    10394        // Add Muted Capability
    104         if ( self::triggerIsMuted( $this->trigger ) ) {
     95        if ( self::triggerIsMuted( $trigger ) ) {
    10596            return false;
    10697        }
     98
     99        $relay = new self( $trigger, $context, $term );
    107100
    108101        // Store blog language defaults
     
    111104        $blogLang   = locale_get_primary_language( $blogLocale );
    112105
    113         if ( ! empty( $this->posts ) ) {
     106        if ( ! empty( $relay->posts ) ) {
    114107            // If templates were created for trigger
    115108
    116             foreach ( $this->posts as $post ) {
    117 
    118                 $locale = apply_filters( "juvo_mail_editor_{$this->trigger}_language", $blogLocale, $this->context );
     109            foreach ( $relay->posts as $post ) {
     110
     111                $locale = apply_filters( "juvo_mail_editor_{$trigger}_language", $blogLocale, $relay->context );
    119112                $lang   = locale_get_primary_language( $locale );
    120113
     
    129122
    130123                // Recipients
    131                 $recipients = $this->prepareRecipients( $post );
     124                $recipients = $relay->prepareRecipients( $post );
    132125
    133126                // Content
    134                 $content = $this->prepareContent( $post );
     127                $content = $relay->prepareContent( $post );
    135128
    136129                // Subject
    137                 $subject = $this->prepareSubject( $post );
     130                $subject = $relay->prepareSubject( $post );
    138131
    139132                // Restore language context
     
    150143
    151144            // Some triggers might only send mails if a post is associated
    152             $alwaysSent = apply_filters( "juvo_mail_editor_{$this->trigger}_always_sent", false );
     145            $alwaysSent = apply_filters( "juvo_mail_editor_{$trigger}_always_sent", false );
    153146            if ( ! $alwaysSent ) {
    154147                return false;
    155148            }
    156149
    157             $lang = apply_filters( "juvo_mail_editor_{$this->trigger}_language", $blogLocale, $this->context );
     150            $lang = apply_filters( "juvo_mail_editor_{$trigger}_language", $blogLocale, $relay->context );
    158151
    159152            $switched_locale = switch_to_locale( $lang );
    160153
    161154            // 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();
    165158
    166159            if ( $switched_locale ) {
     
    192185
    193186        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 );
    194205    }
    195206
     
    257268
    258269    /**
    259      * @param WP_Post|null $post
    260      *
    261      * @return string
    262      */
    263     public function prepareRecipients( WP_Post $post = null ): string {
    264 
    265         // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
    266         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     /**
    277270     * @return array
    278271     */
  • juvo-mail-editor/trunk/vendor/autoload.php

    r2654150 r2655718  
    55require_once __DIR__ . '/composer/autoload_real.php';
    66
    7 return ComposerAutoloaderInit76482599c4a7f1e1877c9fc12cff0611::getLoader();
     7return ComposerAutoloaderInitea9602c371634370be8f852af5c4b8cd::getLoader();
  • juvo-mail-editor/trunk/vendor/composer/autoload_real.php

    r2654150 r2655718  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInit76482599c4a7f1e1877c9fc12cff0611
     5class ComposerAutoloaderInitea9602c371634370be8f852af5c4b8cd
    66{
    77    private static $loader;
     
    2323        }
    2424
    25         spl_autoload_register(array('ComposerAutoloaderInit76482599c4a7f1e1877c9fc12cff0611', 'loadClassLoader'), true, true);
     25        spl_autoload_register(array('ComposerAutoloaderInitea9602c371634370be8f852af5c4b8cd', 'loadClassLoader'), true, true);
    2626        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
    27         spl_autoload_unregister(array('ComposerAutoloaderInit76482599c4a7f1e1877c9fc12cff0611', 'loadClassLoader'));
     27        spl_autoload_unregister(array('ComposerAutoloaderInitea9602c371634370be8f852af5c4b8cd', 'loadClassLoader'));
    2828
    2929        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
     
    3131            require __DIR__ . '/autoload_static.php';
    3232
    33             call_user_func(\Composer\Autoload\ComposerStaticInit76482599c4a7f1e1877c9fc12cff0611::getInitializer($loader));
     33            call_user_func(\Composer\Autoload\ComposerStaticInitea9602c371634370be8f852af5c4b8cd::getInitializer($loader));
    3434        } else {
    3535            $map = require __DIR__ . '/autoload_namespaces.php';
     
    5252
    5353        if ($useStaticLoader) {
    54             $includeFiles = Composer\Autoload\ComposerStaticInit76482599c4a7f1e1877c9fc12cff0611::$files;
     54            $includeFiles = Composer\Autoload\ComposerStaticInitea9602c371634370be8f852af5c4b8cd::$files;
    5555        } else {
    5656            $includeFiles = require __DIR__ . '/autoload_files.php';
    5757        }
    5858        foreach ($includeFiles as $fileIdentifier => $file) {
    59             composerRequire76482599c4a7f1e1877c9fc12cff0611($fileIdentifier, $file);
     59            composerRequireea9602c371634370be8f852af5c4b8cd($fileIdentifier, $file);
    6060        }
    6161
     
    6464}
    6565
    66 function composerRequire76482599c4a7f1e1877c9fc12cff0611($fileIdentifier, $file)
     66function composerRequireea9602c371634370be8f852af5c4b8cd($fileIdentifier, $file)
    6767{
    6868    if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
  • juvo-mail-editor/trunk/vendor/composer/autoload_static.php

    r2654150 r2655718  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInit76482599c4a7f1e1877c9fc12cff0611
     7class ComposerStaticInitea9602c371634370be8f852af5c4b8cd
    88{
    99    public static $files = array (
     
    9494    {
    9595        return \Closure::bind(function () use ($loader) {
    96             $loader->prefixLengthsPsr4 = ComposerStaticInit76482599c4a7f1e1877c9fc12cff0611::$prefixLengthsPsr4;
    97             $loader->prefixDirsPsr4 = ComposerStaticInit76482599c4a7f1e1877c9fc12cff0611::$prefixDirsPsr4;
    98             $loader->fallbackDirsPsr4 = ComposerStaticInit76482599c4a7f1e1877c9fc12cff0611::$fallbackDirsPsr4;
    99             $loader->prefixesPsr0 = ComposerStaticInit76482599c4a7f1e1877c9fc12cff0611::$prefixesPsr0;
    100             $loader->classMap = ComposerStaticInit76482599c4a7f1e1877c9fc12cff0611::$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;
    101101
    102102        }, null, ClassLoader::class);
  • juvo-mail-editor/trunk/vendor/composer/installed.php

    r2654150 r2655718  
    11<?php return array(
    22    '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',
    55        'type' => 'wordpress-plugin',
    66        'install_path' => __DIR__ . '/../../',
    77        'aliases' => array(),
    8         'reference' => '4d9364fb994ade9d09584753f64df3f53b155ccc',
     8        'reference' => '6fd4fbd2bc7de6e147bda5e1da988cae07a8694f',
    99        'name' => 'juvo/mail-editor',
    1010        'dev' => false,
     
    3939        ),
    4040        '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',
    4343            'type' => 'wordpress-plugin',
    4444            'install_path' => __DIR__ . '/../../',
    4545            'aliases' => array(),
    46             'reference' => '4d9364fb994ade9d09584753f64df3f53b155ccc',
     46            'reference' => '6fd4fbd2bc7de6e147bda5e1da988cae07a8694f',
    4747            'dev_requirement' => false,
    4848        ),
Note: See TracChangeset for help on using the changeset viewer.