Plugin Directory

Changeset 2672700


Ignore:
Timestamp:
02/04/2022 07:25:36 AM (4 years ago)
Author:
juvodesign
Message:

Update to version 3.0.5 from GitHub

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

Legend:

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

    r2665461 r2672700  
    88 * Text Domain:     juvo-mail-editor
    99 * Domain Path:     /languages
    10  * Version:         3.0.4
     10 * Version:         3.0.5
    1111 */
    1212
  • juvo-mail-editor/tags/3.0.5/readme.txt

    r2665461 r2672700  
    44License: GPLv2 or later
    55Tested up to: 5.9
    6 Stable tag: 3.0.4
     6Stable tag: 3.0.5
    77
    88JUVO Mail Editor helps to modify the standard WordPress Mailings and allows adding dynamic mail triggers.
     
    2222* Seamless integration to any mail styling plugin - even buddyboss.
    2323* Multilanguage support
     24* Set CC, BCC and Attachments for mails
    2425
    2526== Frequently Asked Questions ==
  • juvo-mail-editor/tags/3.0.5/src/Mail_Generator.php

    r2655718 r2672700  
    1414        add_filter( 'juvo_mail_editor_trigger', array( $this, 'registerTrigger' ) );
    1515
    16         add_filter( "juvo_mail_editor_{$this->getTrigger()}_always_sent", array( $this, 'getAlwaysSent' ), 1, 0 );
    17         add_filter( "juvo_mail_editor_{$this->getTrigger()}_subject", array( $this, 'getSubject' ), 1, 0 );
    18         add_filter( "juvo_mail_editor_{$this->getTrigger()}_message", array( $this, 'getMessage' ), 1, 0 );
    19         add_filter( "juvo_mail_editor_{$this->getTrigger()}_default_recipients", array( $this, 'getRecipient' ), 1, 0 );
     16        add_filter( "juvo_mail_editor_{$this->getTrigger()}_always_sent", array( $this, 'getAlwaysSent' ), 10, 0 );
     17        add_filter( "juvo_mail_editor_{$this->getTrigger()}_subject", array( $this, 'getSubject' ), 10, 1 );
     18        add_filter( "juvo_mail_editor_{$this->getTrigger()}_message", array( $this, 'getMessage' ), 10, 1 );
     19        add_filter( "juvo_mail_editor_{$this->getTrigger()}_recipients", array( $this, 'getRecipients' ), 10, 1 );
    2020        add_filter(
    2121            "juvo_mail_editor_{$this->getTrigger()}_placeholders",
  • juvo-mail-editor/tags/3.0.5/src/Mails/Generic.php

    r2665450 r2672700  
    1010    private $recipients;
    1111    private $headers;
     12    private $attachments;
    1213
    1314    /**
     
    1617     * @param string $subject
    1718     * @param string $content
    18      * @param string $recipients
     19     * @param array $recipients
     20     * @param array $headers
     21     * @param array $attachments
    1922     */
    20     public function __construct( string $subject, string $content, string $recipients, array $headers ) {
    21         $this->subject    = $subject;
    22         $this->content    = $content;
    23         $this->recipients = $recipients;
    24         $this->headers    = $headers;
     23    public function __construct( string $subject, string $content, array $recipients, array $headers, array $attachments ) {
     24        $this->subject     = $subject;
     25        $this->content     = $content;
     26        $this->recipients  = $recipients;
     27        $this->headers     = $headers;
     28        $this->attachments = $attachments;
    2529    }
    2630
     
    2933     */
    3034    public function send() {
    31         return wp_mail( $this->recipients, $this->subject, $this->content, $this->headers );
     35        return wp_mail( $this->recipients, $this->subject, $this->content, $this->headers, $this->attachments );
    3236    }
    3337}
  • juvo-mail-editor/tags/3.0.5/src/Mails/Mail.php

    r2655718 r2672700  
    55interface Mail {
    66
    7     public function getSubject(): string;
     7    public function getSubject( string $subject ): string;
    88
    9     public function getMessage(): string;
     9    public function getMessage( string $message ): string;
    1010
    11     public function getRecipient(): string;
     11    public function getRecipients( array $recipients ): array;
    1212
    1313    public function getAlwaysSent(): bool;
  • juvo-mail-editor/tags/3.0.5/src/Mails/New_User.php

    r2655718 r2672700  
    3939    }
    4040
    41     public function getSubject(): string {
     41    public function getSubject( string $subject ): string {
     42
     43        if ( ! empty( $subject ) ) {
     44            return $subject;
     45        }
     46
    4247        return sprintf( __( '%s Login Details', 'default' ), '{{site.name}}' );
    4348    }
    4449
    45     public function getMessage(): string {
     50    public function getMessage( string $message ): string {
     51
     52        if ( ! empty( $message ) ) {
     53            return $message;
     54        }
     55
    4656        $message = sprintf( __( 'Username: %s', 'default' ), '{{user.name}}' ) . "\r\n\r\n";
    4757        $message .= __( 'To set your password, visit the following address:', 'default' ) . "\r\n\r\n";
     
    5161    }
    5262
    53     public function getRecipient(): string {
    54         return '{{user.user_email}}';
     63    public function getRecipients( array $recipients ): array {
     64
     65        if ( ! empty( $recipients ) ) {
     66            return $recipients;
     67        }
     68
     69        return [ '{{user.user_email}}' ];
    5570    }
    5671
  • juvo-mail-editor/tags/3.0.5/src/Mails/New_User_Admin.php

    r2655718 r2672700  
    1717    public function prepareSend( array $email, WP_User $user ): array {
    1818        do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user ] );
     19
    1920        return $this->emptyMailArray( $email );
    2021    }
    2122
    22     public function getSubject(): string {
     23    public function getSubject( string $subject ): string {
     24
     25        if ( ! empty( $subject ) ) {
     26            return $subject;
     27        }
     28
    2329        return sprintf( __( '[%s] New User Registration', 'default' ), '{{site.name}}' );
    2430    }
    2531
    26     public function getMessage(): string {
     32    public function getMessage( string $message ): string {
     33
     34        if ( ! empty( $message ) ) {
     35            return $message;
     36        }
     37
    2738        $message = sprintf( __( 'New user registration on your site %s:', 'default' ), '{{site.name}}' ) . "\r\n\r\n";
    2839        $message .= sprintf( __( 'Username: %s', 'default' ), '{{user.name}}' ) . "\r\n\r\n";
     
    3243    }
    3344
    34     public function getRecipient(): string {
    35         return '{{site.admin_email}}';
     45    public function getRecipients( array $recipients ): array {
     46
     47        if ( ! empty( $recipients ) ) {
     48            return $recipients;
     49        }
     50
     51        return [ '{{site.admin_email}}' ];
    3652    }
    3753
  • juvo-mail-editor/tags/3.0.5/src/Mails/New_User_Admin_Rest.php

    r2655718 r2672700  
    1919    }
    2020
    21     public function getSubject(): string {
     21    public function getSubject( string $subject ): string {
     22
     23        if ( ! empty( $subject ) ) {
     24            return $subject;
     25        }
     26
    2227        return sprintf( __( '[%s] New User Registration', 'default' ), '{{site.name}}' );
    2328    }
    2429
    25     public function getMessage(): string {
     30    public function getMessage( string $message ): string {
     31
     32        if ( ! empty( $message ) ) {
     33            return $message;
     34        }
     35
    2636        $message = sprintf( __( 'New user registration on your site %s:', 'default' ), '{{site.name}}' ) . "\r\n\r\n";
    2737        $message .= sprintf( __( 'Username: %s', 'default' ), '{{user.name}}' ) . "\r\n\r\n";
     
    3141    }
    3242
    33     public function getRecipient(): string {
    34         return '{{site.admin_email}}';
     43    public function getRecipients( array $recipients ): array {
     44
     45        if ( ! empty( $recipients ) ) {
     46            return $recipients;
     47        }
     48
     49        return [ '{{site.admin_email}}' ];
    3550    }
    3651
  • juvo-mail-editor/tags/3.0.5/src/Mails/New_User_Rest.php

    r2655718 r2672700  
    4646    }
    4747
    48     public function getSubject(): string {
     48    public function getSubject( string $subject ): string {
     49
     50        if ( ! empty( $subject ) ) {
     51            return $subject;
     52        }
     53
    4954        return sprintf( __( '%s Login Details', 'default' ), '{{site.name}}' );
    5055    }
    5156
    52     public function getMessage(): string {
     57    public function getMessage( string $message ): string {
     58
     59        if ( ! empty( $message ) ) {
     60            return $message;
     61        }
     62
    5363        $message = sprintf( __( 'Username: %s', 'default' ), '{{user.name}}' ) . "\r\n\r\n";
    5464        $message .= __( 'To set your password, visit the following address:', 'default' ) . "\r\n\r\n";
     
    5868    }
    5969
    60     public function getRecipient(): string {
    61         return '{{user.user_email}}';
     70    public function getRecipients( array $recipients ): array {
     71
     72        if ( ! empty( $recipients ) ) {
     73            return $recipients;
     74        }
     75
     76        return [ '{{user.user_email}}' ];
    6277    }
    6378
  • juvo-mail-editor/tags/3.0.5/src/Mails/Password_Changed.php

    r2655718 r2672700  
    2424    }
    2525
    26     public function getSubject(): string {
     26    public function getSubject( string $subject ): string {
     27
     28        if ( ! empty( $subject ) ) {
     29            return $subject;
     30        }
     31
    2732        return sprintf( __( '%s Password Changed', 'default' ), '{{site.name}}' );
    2833    }
    2934
    30     public function getMessage(): string {
     35    public function getMessage( string $message ): string {
     36
     37        if ( ! empty( $message ) ) {
     38            return $message;
     39        }
     40
    3141        $message = __(
    3242            'Hi ###USERNAME###,
     
    6070    }
    6171
    62     public function getRecipient(): string {
    63         return '{{user.user_email}}';
     72    public function getRecipients( array $recipients ): array {
     73
     74        if ( ! empty( $recipients ) ) {
     75            return $recipients;
     76        }
     77
     78        return [ '{{user.user_email}}' ];
    6479    }
    6580
  • juvo-mail-editor/tags/3.0.5/src/Mails/Password_Changed_Admin.php

    r2655718 r2672700  
    2424    }
    2525
    26     public function getSubject(): string {
     26    public function getSubject( string $subject ): string {
     27
     28        if ( ! empty( $subject ) ) {
     29            return $subject;
     30        }
     31
    2732        return sprintf( __( '%s Password Changed', 'default' ), '{{site.name}}' );
    2833    }
    2934
    30     public function getMessage(): string {
     35    public function getMessage( string $message ): string {
     36
     37        if ( ! empty( $message ) ) {
     38            return $message;
     39        }
     40
    3141        return sprintf( __( 'Password changed for user: %s', 'default' ), '{{user.name}}' ) . "\r\n";
    3242    }
    3343
    34     public function getRecipient(): string {
    35         return '{{site.admin_email}}';
     44    public function getRecipients( array $recipients ): array {
     45
     46        if ( ! empty( $recipients ) ) {
     47            return $recipients;
     48        }
     49
     50        return [ '{{site.admin_email}}' ];
    3651    }
    3752
    3853    public function prepareSend( array $email, WP_User $user ): array {
    3954        do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user ] );
     55
    4056        return $this->emptyMailArray( $email );
    4157    }
  • juvo-mail-editor/tags/3.0.5/src/Mails/Password_Reset.php

    r2655718 r2672700  
    2626    public function prepareSend( $message, string $key, $user_login, WP_User $user ): string {
    2727        do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user, 'key' => $key ] );
     28
    2829        return '';
    2930    }
    3031
    31     public function getSubject(): string {
     32    public function getSubject( string $subject ): string {
     33
     34        if ( ! empty( $subject ) ) {
     35            return $subject;
     36        }
     37
    3238        return __( 'Password Reset', 'juvo-mail-editor' );
    3339    }
    3440
    35     public function getMessage(): string {
     41    public function getMessage( string $message ): string {
     42
     43        if ( ! empty( $message ) ) {
     44            return $message;
     45        }
     46
    3647        $message = __( 'Someone has requested a password reset for the following account:', 'default' ) . "\r\n\r\n";
    3748        $message .= sprintf( __( 'Site Name: %s', 'default' ), '{{ site.name }}' ) . "\r\n\r\n";
     
    4455    }
    4556
    46     public function getRecipient(): string {
    47         return '{{ user.user_email }}';
     57    public function getRecipients( array $recipients ): array {
     58
     59        if ( ! empty( $recipients ) ) {
     60            return $recipients;
     61        }
     62
     63        return [ '{{user.user_email}}' ];
    4864    }
    4965
  • juvo-mail-editor/tags/3.0.5/src/Mails/Password_Reset_Admin.php

    r2655718 r2672700  
    1414    }
    1515
    16     public function getSubject(): string {
     16    public function getSubject( string $subject ): string {
     17
     18        if ( ! empty( $subject ) ) {
     19            return $subject;
     20        }
     21
    1722        return __( 'Password Reset (Admin)', 'juvo-mail-editor' );
    1823    }
    1924
    20     public function getMessage(): string {
     25    public function getMessage( string $message ): string {
     26
     27        if ( ! empty( $message ) ) {
     28            return $message;
     29        }
     30
    2131        $message = __( 'Someone has requested a password reset for the following account:', 'default' ) . "\r\n\r\n";
    2232        $message .= sprintf( __( 'Site Name: %s', 'default' ), '{{ site.name}}' ) . "\r\n\r\n";
     
    2636    }
    2737
    28     public function getRecipient(): string {
    29         return '{{ site.admin_email}}';
     38    public function getRecipients( array $recipients ): array {
     39
     40        if ( ! empty( $recipients ) ) {
     41            return $recipients;
     42        }
     43
     44        return [ '{{site.admin_email}}' ];
    3045    }
    3146
    3247    public function prepareSend( $message, $key, $user_login, WP_User $user ): string {
    3348        do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user, 'key' => $key ] );
     49
    3450        return '';
    3551    }
  • juvo-mail-editor/tags/3.0.5/src/Mails_PT.php

    r2655718 r2672700  
    8484        $cmb->add_field(
    8585            array(
    86                 'name'   => __( 'Recipients', 'juvo-mail-editor' ),
    87                 'desc'   => __( 'Comma seperated list of mail addresses', 'juvo-mail-editor' ),
    88                 'id'     => self::POST_TYPE_NAME . '_recipients',
    89                 'type'   => 'text',
    90                 'column' => true,
    91             )
    92         );
    93 
    94         $cmb->add_field(
    95             array(
    9686                'name'   => __( 'Subject', 'juvo-mail-editor' ),
    9787                'desc'   => __( 'E-Mail subject', 'juvo-mail-editor' ),
     
    10292        );
    10393
     94        $cmb->add_field(
     95            array(
     96                'name'   => __( 'Recipients', 'juvo-mail-editor' ),
     97                'id'     => self::POST_TYPE_NAME . '_recipients',
     98                'type'   => 'text',
     99                'column' => true,
     100            )
     101        );
     102
     103        $recipient_group = $cmb->add_field( array(
     104            'id'          => self::POST_TYPE_NAME . '_recipients',
     105            'type'        => 'group',
     106            'description' => __( 'Comma seperated list of mail addresses', 'juvo-mail-editor' ),
     107            'options'     => array(
     108                'group_title'    => __( 'Recipient {#}', 'cmb2' ),
     109                'add_button'     => __( 'Add Another Entry', 'cmb2' ),
     110                'remove_button'  => __( 'Remove Entry', 'cmb2' ),
     111                'sortable'       => true,
     112                'closed'         => true,
     113                'remove_confirm' => esc_html__( 'Are you sure you want to remove?', 'cmb2' ),
     114            ),
     115            'classes'     => "cmb-flex"
     116        ) );
     117
     118        $this->addRecipientGroupFields( $recipient_group, $cmb );
     119
     120        $cc_group = $cmb->add_field( array(
     121            'id'          => self::POST_TYPE_NAME . '_cc',
     122            'type'        => 'group',
     123            'description' => __( 'Add recipients that should receive a carbon copy (CC). CC Recipients are visible in emails', 'juvo-mail-editor' ),
     124            'options'     => array(
     125                'group_title'    => __( 'CC Recipient {#}', 'cmb2' ),
     126                'add_button'     => __( 'Add Another Entry', 'cmb2' ),
     127                'remove_button'  => __( 'Remove Entry', 'cmb2' ),
     128                'sortable'       => true,
     129                'closed'         => true,
     130                'remove_confirm' => esc_html__( 'Are you sure you want to remove?', 'cmb2' ),
     131            ),
     132            'classes'     => "cmb-flex"
     133        ) );
     134
     135        $this->addRecipientGroupFields( $cc_group, $cmb );
     136
     137        $bcc_group = $cmb->add_field( array(
     138            'id'          => self::POST_TYPE_NAME . '_bcc',
     139            'type'        => 'group',
     140            'description' => __( 'Add recipients that should receive a “blind carbon copy.” Behaves like CC but without revealing the recipients in the email.', 'juvo-mail-editor' ),
     141            'options'     => array(
     142                'group_title'    => __( 'BCC Recipient {#}', 'cmb2' ),
     143                'add_button'     => __( 'Add Another Entry', 'cmb2' ),
     144                'remove_button'  => __( 'Remove Entry', 'cmb2' ),
     145                'sortable'       => true,
     146                'closed'         => true,
     147                'remove_confirm' => esc_html__( 'Are you sure you want to remove?', 'cmb2' ),
     148            ),
     149            'classes'     => "cmb-flex"
     150        ) );
     151
     152        $this->addRecipientGroupFields( $bcc_group, $cmb );
     153
     154
     155        $cmb->add_field( array(
     156            'name' => __( 'Attachments', 'juvo-mail-editor' ),
     157            'desc' => '',
     158            'id'   => self::POST_TYPE_NAME . '_attachments',
     159            'type' => 'file_list',
     160        ) );
     161
    104162        apply_filters( 'juvo_mail_editor_post_metabox', $cmb );
    105163    }
    106164
     165    private function addRecipientGroupFields( string $group, $cmb ) {
     166        $cmb->add_group_field( $group, array(
     167            'name'    => __( 'Name', 'juvo-mail-editor' ),
     168            'id'      => 'name',
     169            'type'    => 'text',
     170            'classes' => "flex-col-2"
     171        ) );
     172
     173        $cmb->add_group_field( $group, array(
     174            'name'       => __( 'Mail', 'juvo-mail-editor' ),
     175            'id'         => 'mail',
     176            'type'       => 'text',
     177            'classes'    => "flex-col-2",
     178            'attributes' => array(
     179                'data-validation' => 'required',
     180            ),
     181        ) );
     182    }
     183
    107184}
  • juvo-mail-editor/tags/3.0.5/src/Relay.php

    r2665461 r2672700  
    133133                $headers = $relay->prepareHeaders( $post );
    134134
     135                // Attachments
     136                $attachments = $relay->prepareAttachments( $post );
     137
    135138                // Restore language context
    136139                if ( $switched_locale ) {
     
    138141                }
    139142
    140                 $mail = new Generic( $subject, $content, $recipients, $headers );
     143                $mail = new Generic( $subject, $content, $recipients, $headers, $attachments );
    141144                $mail->send();
    142145
     
    156159
    157160            // Fallback if not posts are found for configured trigger
    158             $content    = $relay->prepareContent();
    159             $subject    = $relay->prepareSubject();
    160             $recipients = $relay->prepareRecipients();
    161             $headers    = $relay->prepareHeaders();
     161            $content     = $relay->prepareContent();
     162            $subject     = $relay->prepareSubject();
     163            $recipients  = $relay->prepareRecipients();
     164            $headers     = $relay->prepareHeaders();
     165            $attachments = $relay->prepareAttachments();
    162166
    163167            if ( $switched_locale ) {
     
    165169            }
    166170
    167             $mail = new Generic( $subject, $content, $recipients, $headers );
     171            $mail = new Generic( $subject, $content, $recipients, $headers, $attachments );
    168172            $mail->send();
    169173
     
    194198     * @param WP_Post|null $post
    195199     *
     200     * @return array
     201     */
     202    public function prepareRecipients( WP_Post $post = null ): array {
     203
     204        $recipients = [];
     205
     206        // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
     207        if ( $post ) {
     208            $recipients = get_post_meta( $post->ID, Mails_PT::POST_TYPE_NAME . '_recipients', true );
     209        }
     210
     211        $recipients = apply_filters( "juvo_mail_editor_{$this->trigger}_recipients", $this->parseToCcBcc( $recipients ), $this->context );
     212
     213        return apply_filters( 'juvo_mail_editor_after_recipient_placeholder', $recipients, $this->trigger, $this->context );
     214    }
     215
     216    /**
     217     * @param WP_Post|null $post
     218     *
    196219     * @return string
    197220     */
    198     public function prepareRecipients( WP_Post $post = null ): string {
    199 
    200         // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
    201         if ( ! $post || ! $recipients = get_post_meta( $post->ID, Mails_PT::POST_TYPE_NAME . '_recipients', true ) ) {
    202             $recipients = apply_filters( "juvo_mail_editor_{$this->trigger}_default_recipients", '', $this->context );
    203         }
    204 
    205         $recipients = apply_filters( 'juvo_mail_editor_before_recipient_placeholder', $recipients, $this->trigger, $this->context );
    206         $recipients = Placeholder::replacePlaceholder( $this->placeholders, $recipients, $this->context );
    207 
    208         return apply_filters( 'juvo_mail_editor_after_recipient_placeholder', $recipients, $this->trigger, $this->context );
    209     }
    210 
    211     /**
    212      * @param WP_Post|null $post
    213      *
    214      * @return string
    215      */
    216221    public function prepareContent( WP_Post $post = null ): string {
    217222
    218         // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
    219         if ( ! $post || ! $content = get_the_content( null, false, $post ) ) {
    220             $content = apply_filters( "juvo_mail_editor_{$this->trigger}_message", '', $this->context );
    221         } else {
     223        $content = '';
     224
     225        // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
     226        if ( $post && $content = get_the_content( null, false, $post ) ) {
    222227            $blocks  = parse_blocks( $content );
    223228            $content = '';
     
    228233        }
    229234
    230         $content = apply_filters( 'juvo_mail_editor_before_content_placeholder', $content, $this->trigger, $this->context );
     235        $content = apply_filters( "juvo_mail_editor_{$this->trigger}_message", $content, $this->context );
    231236        $content = Placeholder::replacePlaceholder( $this->placeholders, $content, $this->context );
    232237        $content = apply_filters( 'juvo_mail_editor_after_content_placeholder', $content, $this->trigger, $this->context );
     
    260265    public function prepareSubject( WP_Post $post = null ): string {
    261266
    262         // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
    263         if ( ! $post || ! $subject = get_post_meta( $post->ID, Mails_PT::POST_TYPE_NAME . '_subject', true ) ) {
    264             $subject = apply_filters( "juvo_mail_editor_{$this->trigger}_subject", '', $this->context );
    265         }
    266 
    267         $subject = apply_filters( 'juvo_mail_editor_before_subject_placeholder', $subject, $this->trigger, $this->context );
     267        $subject = '';
     268
     269        // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
     270        if ( $post ) {
     271            $subject = get_post_meta( $post->ID, Mails_PT::POST_TYPE_NAME . '_subject', true );
     272        }
     273
     274        $subject = apply_filters( "juvo_mail_editor_{$this->trigger}_subject", $subject, $this->context );
    268275        $subject = Placeholder::replacePlaceholder( $this->placeholders, $subject, $this->context );
    269276
     
    308315        }
    309316
     317        // Add CC and BCC
     318        $headers = $this->prepareCc( $headers, $post );
     319        $headers = $this->prepareBcc( $headers, $post );
     320
    310321        return apply_filters( "juvo_mail_editor_{$this->trigger}_headers", $headers, $this->context );
    311322    }
    312323
     324    private function prepareAttachments( WP_Post $post = null ): array {
     325
     326        $attachments = [];
     327
     328        // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
     329        if ( $post ) {
     330            $attachments = get_post_meta( $post->ID, Mails_PT::POST_TYPE_NAME . '_attachments', true ) ?: [];
     331
     332            if ( empty( $attachments ) ) {
     333                return $attachments;
     334            }
     335
     336            foreach ( $attachments as $id => &$attachment ) {
     337                $attachment = get_attached_file( $id );
     338            }
     339        }
     340
     341        return apply_filters( "juvo_mail_editor_{$this->trigger}_attachments", $attachments, $this->context );
     342    }
     343
     344    private function prepareCc( array $headers, WP_Post $post = null ): array {
     345
     346        $cc = [];
     347
     348        // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
     349        if ( $post ) {
     350            $cc = get_post_meta( $post->ID, Mails_PT::POST_TYPE_NAME . '_cc', true );
     351        }
     352
     353        $cc = apply_filters( "juvo_mail_editor_{$this->trigger}_cc", $this->parseToCcBcc( $cc, "Cc:" ), $this->context );
     354        $cc = apply_filters( 'juvo_mail_editor_after_cc_placeholder', $cc, $this->trigger, $this->context );
     355
     356        return array_merge( $headers, $cc );
     357    }
     358
     359    private function prepareBcc( array $headers, WP_Post $post = null ): array {
     360
     361        $bcc = [];
     362
     363        // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
     364        if ( $post ) {
     365            $bcc = get_post_meta( $post->ID, Mails_PT::POST_TYPE_NAME . '_bcc', true );
     366        }
     367
     368        $bcc = apply_filters( "juvo_mail_editor_{$this->trigger}_bcc", $this->parseToCcBcc( $bcc, "Bcc:" ), $this->context );
     369        $bcc = apply_filters( 'juvo_mail_editor_after_bcc_placeholder', $bcc, $this->trigger, $this->context );
     370
     371        return array_merge( $headers, $bcc );
     372    }
     373
     374    /**
     375     * Parses cmb2 repeater groups or strings to wp_mail compatible array format for "to", "cc" and "bcc"
     376     *
     377     * @param array|string $recipients
     378     * @param string $prefix "Cc:" or "Bcc:"
     379     *
     380     * @return array
     381     */
     382    private function parseToCcBcc( $recipients, string $prefix = "" ): array {
     383
     384        if ( empty( $recipients ) ) {
     385            return [];
     386        }
     387
     388        if ( is_string( $recipients ) ) {
     389            $recipients = explode( ",", $recipients );
     390        }
     391
     392        foreach ( $recipients as &$recipient ) {
     393
     394            if ( ! empty( $recipient['name'] ) && ! empty( $recipient['mail'] ) ) {
     395                $recipient = "{$recipient['name']} <{$recipient['mail']}>";
     396            } elseif ( empty( $recipient['name'] ) && ! empty( $recipient['mail'] ) ) {
     397                $recipient = $recipient['mail'];
     398            }
     399
     400            $recipient = Placeholder::replacePlaceholder( $this->placeholders, $recipient, $this->context );
     401
     402            if ( ! empty( $prefix ) ) {
     403                $recipient = $prefix . " " . $recipient;
     404            }
     405        }
     406
     407        return $recipients;
     408
     409    }
     410
    313411}
  • juvo-mail-editor/tags/3.0.5/vendor/autoload.php

    r2665461 r2672700  
    55require_once __DIR__ . '/composer/autoload_real.php';
    66
    7 return ComposerAutoloaderInitdf996d0981a8b06c2981bee783fc4f04::getLoader();
     7return ComposerAutoloaderInitfdfdf11997bf846c7668e97b172e1c1f::getLoader();
  • juvo-mail-editor/tags/3.0.5/vendor/composer/autoload_real.php

    r2665461 r2672700  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInitdf996d0981a8b06c2981bee783fc4f04
     5class ComposerAutoloaderInitfdfdf11997bf846c7668e97b172e1c1f
    66{
    77    private static $loader;
     
    2323        }
    2424
    25         spl_autoload_register(array('ComposerAutoloaderInitdf996d0981a8b06c2981bee783fc4f04', 'loadClassLoader'), true, true);
     25        spl_autoload_register(array('ComposerAutoloaderInitfdfdf11997bf846c7668e97b172e1c1f', 'loadClassLoader'), true, true);
    2626        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
    27         spl_autoload_unregister(array('ComposerAutoloaderInitdf996d0981a8b06c2981bee783fc4f04', 'loadClassLoader'));
     27        spl_autoload_unregister(array('ComposerAutoloaderInitfdfdf11997bf846c7668e97b172e1c1f', '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\ComposerStaticInitdf996d0981a8b06c2981bee783fc4f04::getInitializer($loader));
     33            call_user_func(\Composer\Autoload\ComposerStaticInitfdfdf11997bf846c7668e97b172e1c1f::getInitializer($loader));
    3434        } else {
    3535            $map = require __DIR__ . '/autoload_namespaces.php';
     
    5252
    5353        if ($useStaticLoader) {
    54             $includeFiles = Composer\Autoload\ComposerStaticInitdf996d0981a8b06c2981bee783fc4f04::$files;
     54            $includeFiles = Composer\Autoload\ComposerStaticInitfdfdf11997bf846c7668e97b172e1c1f::$files;
    5555        } else {
    5656            $includeFiles = require __DIR__ . '/autoload_files.php';
    5757        }
    5858        foreach ($includeFiles as $fileIdentifier => $file) {
    59             composerRequiredf996d0981a8b06c2981bee783fc4f04($fileIdentifier, $file);
     59            composerRequirefdfdf11997bf846c7668e97b172e1c1f($fileIdentifier, $file);
    6060        }
    6161
     
    6969 * @return void
    7070 */
    71 function composerRequiredf996d0981a8b06c2981bee783fc4f04($fileIdentifier, $file)
     71function composerRequirefdfdf11997bf846c7668e97b172e1c1f($fileIdentifier, $file)
    7272{
    7373    if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
  • juvo-mail-editor/tags/3.0.5/vendor/composer/autoload_static.php

    r2665461 r2672700  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInitdf996d0981a8b06c2981bee783fc4f04
     7class ComposerStaticInitfdfdf11997bf846c7668e97b172e1c1f
    88{
    99    public static $files = array (
     
    9494    {
    9595        return \Closure::bind(function () use ($loader) {
    96             $loader->prefixLengthsPsr4 = ComposerStaticInitdf996d0981a8b06c2981bee783fc4f04::$prefixLengthsPsr4;
    97             $loader->prefixDirsPsr4 = ComposerStaticInitdf996d0981a8b06c2981bee783fc4f04::$prefixDirsPsr4;
    98             $loader->fallbackDirsPsr4 = ComposerStaticInitdf996d0981a8b06c2981bee783fc4f04::$fallbackDirsPsr4;
    99             $loader->prefixesPsr0 = ComposerStaticInitdf996d0981a8b06c2981bee783fc4f04::$prefixesPsr0;
    100             $loader->classMap = ComposerStaticInitdf996d0981a8b06c2981bee783fc4f04::$classMap;
     96            $loader->prefixLengthsPsr4 = ComposerStaticInitfdfdf11997bf846c7668e97b172e1c1f::$prefixLengthsPsr4;
     97            $loader->prefixDirsPsr4 = ComposerStaticInitfdfdf11997bf846c7668e97b172e1c1f::$prefixDirsPsr4;
     98            $loader->fallbackDirsPsr4 = ComposerStaticInitfdfdf11997bf846c7668e97b172e1c1f::$fallbackDirsPsr4;
     99            $loader->prefixesPsr0 = ComposerStaticInitfdfdf11997bf846c7668e97b172e1c1f::$prefixesPsr0;
     100            $loader->classMap = ComposerStaticInitfdfdf11997bf846c7668e97b172e1c1f::$classMap;
    101101
    102102        }, null, ClassLoader::class);
  • juvo-mail-editor/tags/3.0.5/vendor/composer/installed.php

    r2665461 r2672700  
    11<?php return array(
    22    'root' => array(
    3         'pretty_version' => '3.0.4',
    4         'version' => '3.0.4.0',
     3        'pretty_version' => '3.0.5',
     4        'version' => '3.0.5.0',
    55        'type' => 'wordpress-plugin',
    66        'install_path' => __DIR__ . '/../../',
    77        'aliases' => array(),
    8         'reference' => '2d251ec3164a7834e1949b59ad82a1c12336148d',
     8        'reference' => '78ed8db8c7bf3e36838fbdeedd047527631aec6d',
    99        'name' => 'juvo/mail-editor',
    1010        'dev' => false,
     
    3939        ),
    4040        'juvo/mail-editor' => array(
    41             'pretty_version' => '3.0.4',
    42             'version' => '3.0.4.0',
     41            'pretty_version' => '3.0.5',
     42            'version' => '3.0.5.0',
    4343            'type' => 'wordpress-plugin',
    4444            'install_path' => __DIR__ . '/../../',
    4545            'aliases' => array(),
    46             'reference' => '2d251ec3164a7834e1949b59ad82a1c12336148d',
     46            'reference' => '78ed8db8c7bf3e36838fbdeedd047527631aec6d',
    4747            'dev_requirement' => false,
    4848        ),
  • juvo-mail-editor/trunk/juvo-mail-editor.php

    r2665461 r2672700  
    88 * Text Domain:     juvo-mail-editor
    99 * Domain Path:     /languages
    10  * Version:         3.0.4
     10 * Version:         3.0.5
    1111 */
    1212
  • juvo-mail-editor/trunk/readme.txt

    r2665461 r2672700  
    44License: GPLv2 or later
    55Tested up to: 5.9
    6 Stable tag: 3.0.4
     6Stable tag: 3.0.5
    77
    88JUVO Mail Editor helps to modify the standard WordPress Mailings and allows adding dynamic mail triggers.
     
    2222* Seamless integration to any mail styling plugin - even buddyboss.
    2323* Multilanguage support
     24* Set CC, BCC and Attachments for mails
    2425
    2526== Frequently Asked Questions ==
  • juvo-mail-editor/trunk/src/Mail_Generator.php

    r2655718 r2672700  
    1414        add_filter( 'juvo_mail_editor_trigger', array( $this, 'registerTrigger' ) );
    1515
    16         add_filter( "juvo_mail_editor_{$this->getTrigger()}_always_sent", array( $this, 'getAlwaysSent' ), 1, 0 );
    17         add_filter( "juvo_mail_editor_{$this->getTrigger()}_subject", array( $this, 'getSubject' ), 1, 0 );
    18         add_filter( "juvo_mail_editor_{$this->getTrigger()}_message", array( $this, 'getMessage' ), 1, 0 );
    19         add_filter( "juvo_mail_editor_{$this->getTrigger()}_default_recipients", array( $this, 'getRecipient' ), 1, 0 );
     16        add_filter( "juvo_mail_editor_{$this->getTrigger()}_always_sent", array( $this, 'getAlwaysSent' ), 10, 0 );
     17        add_filter( "juvo_mail_editor_{$this->getTrigger()}_subject", array( $this, 'getSubject' ), 10, 1 );
     18        add_filter( "juvo_mail_editor_{$this->getTrigger()}_message", array( $this, 'getMessage' ), 10, 1 );
     19        add_filter( "juvo_mail_editor_{$this->getTrigger()}_recipients", array( $this, 'getRecipients' ), 10, 1 );
    2020        add_filter(
    2121            "juvo_mail_editor_{$this->getTrigger()}_placeholders",
  • juvo-mail-editor/trunk/src/Mails/Generic.php

    r2665450 r2672700  
    1010    private $recipients;
    1111    private $headers;
     12    private $attachments;
    1213
    1314    /**
     
    1617     * @param string $subject
    1718     * @param string $content
    18      * @param string $recipients
     19     * @param array $recipients
     20     * @param array $headers
     21     * @param array $attachments
    1922     */
    20     public function __construct( string $subject, string $content, string $recipients, array $headers ) {
    21         $this->subject    = $subject;
    22         $this->content    = $content;
    23         $this->recipients = $recipients;
    24         $this->headers    = $headers;
     23    public function __construct( string $subject, string $content, array $recipients, array $headers, array $attachments ) {
     24        $this->subject     = $subject;
     25        $this->content     = $content;
     26        $this->recipients  = $recipients;
     27        $this->headers     = $headers;
     28        $this->attachments = $attachments;
    2529    }
    2630
     
    2933     */
    3034    public function send() {
    31         return wp_mail( $this->recipients, $this->subject, $this->content, $this->headers );
     35        return wp_mail( $this->recipients, $this->subject, $this->content, $this->headers, $this->attachments );
    3236    }
    3337}
  • juvo-mail-editor/trunk/src/Mails/Mail.php

    r2655718 r2672700  
    55interface Mail {
    66
    7     public function getSubject(): string;
     7    public function getSubject( string $subject ): string;
    88
    9     public function getMessage(): string;
     9    public function getMessage( string $message ): string;
    1010
    11     public function getRecipient(): string;
     11    public function getRecipients( array $recipients ): array;
    1212
    1313    public function getAlwaysSent(): bool;
  • juvo-mail-editor/trunk/src/Mails/New_User.php

    r2655718 r2672700  
    3939    }
    4040
    41     public function getSubject(): string {
     41    public function getSubject( string $subject ): string {
     42
     43        if ( ! empty( $subject ) ) {
     44            return $subject;
     45        }
     46
    4247        return sprintf( __( '%s Login Details', 'default' ), '{{site.name}}' );
    4348    }
    4449
    45     public function getMessage(): string {
     50    public function getMessage( string $message ): string {
     51
     52        if ( ! empty( $message ) ) {
     53            return $message;
     54        }
     55
    4656        $message = sprintf( __( 'Username: %s', 'default' ), '{{user.name}}' ) . "\r\n\r\n";
    4757        $message .= __( 'To set your password, visit the following address:', 'default' ) . "\r\n\r\n";
     
    5161    }
    5262
    53     public function getRecipient(): string {
    54         return '{{user.user_email}}';
     63    public function getRecipients( array $recipients ): array {
     64
     65        if ( ! empty( $recipients ) ) {
     66            return $recipients;
     67        }
     68
     69        return [ '{{user.user_email}}' ];
    5570    }
    5671
  • juvo-mail-editor/trunk/src/Mails/New_User_Admin.php

    r2655718 r2672700  
    1717    public function prepareSend( array $email, WP_User $user ): array {
    1818        do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user ] );
     19
    1920        return $this->emptyMailArray( $email );
    2021    }
    2122
    22     public function getSubject(): string {
     23    public function getSubject( string $subject ): string {
     24
     25        if ( ! empty( $subject ) ) {
     26            return $subject;
     27        }
     28
    2329        return sprintf( __( '[%s] New User Registration', 'default' ), '{{site.name}}' );
    2430    }
    2531
    26     public function getMessage(): string {
     32    public function getMessage( string $message ): string {
     33
     34        if ( ! empty( $message ) ) {
     35            return $message;
     36        }
     37
    2738        $message = sprintf( __( 'New user registration on your site %s:', 'default' ), '{{site.name}}' ) . "\r\n\r\n";
    2839        $message .= sprintf( __( 'Username: %s', 'default' ), '{{user.name}}' ) . "\r\n\r\n";
     
    3243    }
    3344
    34     public function getRecipient(): string {
    35         return '{{site.admin_email}}';
     45    public function getRecipients( array $recipients ): array {
     46
     47        if ( ! empty( $recipients ) ) {
     48            return $recipients;
     49        }
     50
     51        return [ '{{site.admin_email}}' ];
    3652    }
    3753
  • juvo-mail-editor/trunk/src/Mails/New_User_Admin_Rest.php

    r2655718 r2672700  
    1919    }
    2020
    21     public function getSubject(): string {
     21    public function getSubject( string $subject ): string {
     22
     23        if ( ! empty( $subject ) ) {
     24            return $subject;
     25        }
     26
    2227        return sprintf( __( '[%s] New User Registration', 'default' ), '{{site.name}}' );
    2328    }
    2429
    25     public function getMessage(): string {
     30    public function getMessage( string $message ): string {
     31
     32        if ( ! empty( $message ) ) {
     33            return $message;
     34        }
     35
    2636        $message = sprintf( __( 'New user registration on your site %s:', 'default' ), '{{site.name}}' ) . "\r\n\r\n";
    2737        $message .= sprintf( __( 'Username: %s', 'default' ), '{{user.name}}' ) . "\r\n\r\n";
     
    3141    }
    3242
    33     public function getRecipient(): string {
    34         return '{{site.admin_email}}';
     43    public function getRecipients( array $recipients ): array {
     44
     45        if ( ! empty( $recipients ) ) {
     46            return $recipients;
     47        }
     48
     49        return [ '{{site.admin_email}}' ];
    3550    }
    3651
  • juvo-mail-editor/trunk/src/Mails/New_User_Rest.php

    r2655718 r2672700  
    4646    }
    4747
    48     public function getSubject(): string {
     48    public function getSubject( string $subject ): string {
     49
     50        if ( ! empty( $subject ) ) {
     51            return $subject;
     52        }
     53
    4954        return sprintf( __( '%s Login Details', 'default' ), '{{site.name}}' );
    5055    }
    5156
    52     public function getMessage(): string {
     57    public function getMessage( string $message ): string {
     58
     59        if ( ! empty( $message ) ) {
     60            return $message;
     61        }
     62
    5363        $message = sprintf( __( 'Username: %s', 'default' ), '{{user.name}}' ) . "\r\n\r\n";
    5464        $message .= __( 'To set your password, visit the following address:', 'default' ) . "\r\n\r\n";
     
    5868    }
    5969
    60     public function getRecipient(): string {
    61         return '{{user.user_email}}';
     70    public function getRecipients( array $recipients ): array {
     71
     72        if ( ! empty( $recipients ) ) {
     73            return $recipients;
     74        }
     75
     76        return [ '{{user.user_email}}' ];
    6277    }
    6378
  • juvo-mail-editor/trunk/src/Mails/Password_Changed.php

    r2655718 r2672700  
    2424    }
    2525
    26     public function getSubject(): string {
     26    public function getSubject( string $subject ): string {
     27
     28        if ( ! empty( $subject ) ) {
     29            return $subject;
     30        }
     31
    2732        return sprintf( __( '%s Password Changed', 'default' ), '{{site.name}}' );
    2833    }
    2934
    30     public function getMessage(): string {
     35    public function getMessage( string $message ): string {
     36
     37        if ( ! empty( $message ) ) {
     38            return $message;
     39        }
     40
    3141        $message = __(
    3242            'Hi ###USERNAME###,
     
    6070    }
    6171
    62     public function getRecipient(): string {
    63         return '{{user.user_email}}';
     72    public function getRecipients( array $recipients ): array {
     73
     74        if ( ! empty( $recipients ) ) {
     75            return $recipients;
     76        }
     77
     78        return [ '{{user.user_email}}' ];
    6479    }
    6580
  • juvo-mail-editor/trunk/src/Mails/Password_Changed_Admin.php

    r2655718 r2672700  
    2424    }
    2525
    26     public function getSubject(): string {
     26    public function getSubject( string $subject ): string {
     27
     28        if ( ! empty( $subject ) ) {
     29            return $subject;
     30        }
     31
    2732        return sprintf( __( '%s Password Changed', 'default' ), '{{site.name}}' );
    2833    }
    2934
    30     public function getMessage(): string {
     35    public function getMessage( string $message ): string {
     36
     37        if ( ! empty( $message ) ) {
     38            return $message;
     39        }
     40
    3141        return sprintf( __( 'Password changed for user: %s', 'default' ), '{{user.name}}' ) . "\r\n";
    3242    }
    3343
    34     public function getRecipient(): string {
    35         return '{{site.admin_email}}';
     44    public function getRecipients( array $recipients ): array {
     45
     46        if ( ! empty( $recipients ) ) {
     47            return $recipients;
     48        }
     49
     50        return [ '{{site.admin_email}}' ];
    3651    }
    3752
    3853    public function prepareSend( array $email, WP_User $user ): array {
    3954        do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user ] );
     55
    4056        return $this->emptyMailArray( $email );
    4157    }
  • juvo-mail-editor/trunk/src/Mails/Password_Reset.php

    r2655718 r2672700  
    2626    public function prepareSend( $message, string $key, $user_login, WP_User $user ): string {
    2727        do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user, 'key' => $key ] );
     28
    2829        return '';
    2930    }
    3031
    31     public function getSubject(): string {
     32    public function getSubject( string $subject ): string {
     33
     34        if ( ! empty( $subject ) ) {
     35            return $subject;
     36        }
     37
    3238        return __( 'Password Reset', 'juvo-mail-editor' );
    3339    }
    3440
    35     public function getMessage(): string {
     41    public function getMessage( string $message ): string {
     42
     43        if ( ! empty( $message ) ) {
     44            return $message;
     45        }
     46
    3647        $message = __( 'Someone has requested a password reset for the following account:', 'default' ) . "\r\n\r\n";
    3748        $message .= sprintf( __( 'Site Name: %s', 'default' ), '{{ site.name }}' ) . "\r\n\r\n";
     
    4455    }
    4556
    46     public function getRecipient(): string {
    47         return '{{ user.user_email }}';
     57    public function getRecipients( array $recipients ): array {
     58
     59        if ( ! empty( $recipients ) ) {
     60            return $recipients;
     61        }
     62
     63        return [ '{{user.user_email}}' ];
    4864    }
    4965
  • juvo-mail-editor/trunk/src/Mails/Password_Reset_Admin.php

    r2655718 r2672700  
    1414    }
    1515
    16     public function getSubject(): string {
     16    public function getSubject( string $subject ): string {
     17
     18        if ( ! empty( $subject ) ) {
     19            return $subject;
     20        }
     21
    1722        return __( 'Password Reset (Admin)', 'juvo-mail-editor' );
    1823    }
    1924
    20     public function getMessage(): string {
     25    public function getMessage( string $message ): string {
     26
     27        if ( ! empty( $message ) ) {
     28            return $message;
     29        }
     30
    2131        $message = __( 'Someone has requested a password reset for the following account:', 'default' ) . "\r\n\r\n";
    2232        $message .= sprintf( __( 'Site Name: %s', 'default' ), '{{ site.name}}' ) . "\r\n\r\n";
     
    2636    }
    2737
    28     public function getRecipient(): string {
    29         return '{{ site.admin_email}}';
     38    public function getRecipients( array $recipients ): array {
     39
     40        if ( ! empty( $recipients ) ) {
     41            return $recipients;
     42        }
     43
     44        return [ '{{site.admin_email}}' ];
    3045    }
    3146
    3247    public function prepareSend( $message, $key, $user_login, WP_User $user ): string {
    3348        do_action( "juvo_mail_editor_send", $this->getTrigger(), [ "user" => $user, 'key' => $key ] );
     49
    3450        return '';
    3551    }
  • juvo-mail-editor/trunk/src/Mails_PT.php

    r2655718 r2672700  
    8484        $cmb->add_field(
    8585            array(
    86                 'name'   => __( 'Recipients', 'juvo-mail-editor' ),
    87                 'desc'   => __( 'Comma seperated list of mail addresses', 'juvo-mail-editor' ),
    88                 'id'     => self::POST_TYPE_NAME . '_recipients',
    89                 'type'   => 'text',
    90                 'column' => true,
    91             )
    92         );
    93 
    94         $cmb->add_field(
    95             array(
    9686                'name'   => __( 'Subject', 'juvo-mail-editor' ),
    9787                'desc'   => __( 'E-Mail subject', 'juvo-mail-editor' ),
     
    10292        );
    10393
     94        $cmb->add_field(
     95            array(
     96                'name'   => __( 'Recipients', 'juvo-mail-editor' ),
     97                'id'     => self::POST_TYPE_NAME . '_recipients',
     98                'type'   => 'text',
     99                'column' => true,
     100            )
     101        );
     102
     103        $recipient_group = $cmb->add_field( array(
     104            'id'          => self::POST_TYPE_NAME . '_recipients',
     105            'type'        => 'group',
     106            'description' => __( 'Comma seperated list of mail addresses', 'juvo-mail-editor' ),
     107            'options'     => array(
     108                'group_title'    => __( 'Recipient {#}', 'cmb2' ),
     109                'add_button'     => __( 'Add Another Entry', 'cmb2' ),
     110                'remove_button'  => __( 'Remove Entry', 'cmb2' ),
     111                'sortable'       => true,
     112                'closed'         => true,
     113                'remove_confirm' => esc_html__( 'Are you sure you want to remove?', 'cmb2' ),
     114            ),
     115            'classes'     => "cmb-flex"
     116        ) );
     117
     118        $this->addRecipientGroupFields( $recipient_group, $cmb );
     119
     120        $cc_group = $cmb->add_field( array(
     121            'id'          => self::POST_TYPE_NAME . '_cc',
     122            'type'        => 'group',
     123            'description' => __( 'Add recipients that should receive a carbon copy (CC). CC Recipients are visible in emails', 'juvo-mail-editor' ),
     124            'options'     => array(
     125                'group_title'    => __( 'CC Recipient {#}', 'cmb2' ),
     126                'add_button'     => __( 'Add Another Entry', 'cmb2' ),
     127                'remove_button'  => __( 'Remove Entry', 'cmb2' ),
     128                'sortable'       => true,
     129                'closed'         => true,
     130                'remove_confirm' => esc_html__( 'Are you sure you want to remove?', 'cmb2' ),
     131            ),
     132            'classes'     => "cmb-flex"
     133        ) );
     134
     135        $this->addRecipientGroupFields( $cc_group, $cmb );
     136
     137        $bcc_group = $cmb->add_field( array(
     138            'id'          => self::POST_TYPE_NAME . '_bcc',
     139            'type'        => 'group',
     140            'description' => __( 'Add recipients that should receive a “blind carbon copy.” Behaves like CC but without revealing the recipients in the email.', 'juvo-mail-editor' ),
     141            'options'     => array(
     142                'group_title'    => __( 'BCC Recipient {#}', 'cmb2' ),
     143                'add_button'     => __( 'Add Another Entry', 'cmb2' ),
     144                'remove_button'  => __( 'Remove Entry', 'cmb2' ),
     145                'sortable'       => true,
     146                'closed'         => true,
     147                'remove_confirm' => esc_html__( 'Are you sure you want to remove?', 'cmb2' ),
     148            ),
     149            'classes'     => "cmb-flex"
     150        ) );
     151
     152        $this->addRecipientGroupFields( $bcc_group, $cmb );
     153
     154
     155        $cmb->add_field( array(
     156            'name' => __( 'Attachments', 'juvo-mail-editor' ),
     157            'desc' => '',
     158            'id'   => self::POST_TYPE_NAME . '_attachments',
     159            'type' => 'file_list',
     160        ) );
     161
    104162        apply_filters( 'juvo_mail_editor_post_metabox', $cmb );
    105163    }
    106164
     165    private function addRecipientGroupFields( string $group, $cmb ) {
     166        $cmb->add_group_field( $group, array(
     167            'name'    => __( 'Name', 'juvo-mail-editor' ),
     168            'id'      => 'name',
     169            'type'    => 'text',
     170            'classes' => "flex-col-2"
     171        ) );
     172
     173        $cmb->add_group_field( $group, array(
     174            'name'       => __( 'Mail', 'juvo-mail-editor' ),
     175            'id'         => 'mail',
     176            'type'       => 'text',
     177            'classes'    => "flex-col-2",
     178            'attributes' => array(
     179                'data-validation' => 'required',
     180            ),
     181        ) );
     182    }
     183
    107184}
  • juvo-mail-editor/trunk/src/Relay.php

    r2665461 r2672700  
    133133                $headers = $relay->prepareHeaders( $post );
    134134
     135                // Attachments
     136                $attachments = $relay->prepareAttachments( $post );
     137
    135138                // Restore language context
    136139                if ( $switched_locale ) {
     
    138141                }
    139142
    140                 $mail = new Generic( $subject, $content, $recipients, $headers );
     143                $mail = new Generic( $subject, $content, $recipients, $headers, $attachments );
    141144                $mail->send();
    142145
     
    156159
    157160            // Fallback if not posts are found for configured trigger
    158             $content    = $relay->prepareContent();
    159             $subject    = $relay->prepareSubject();
    160             $recipients = $relay->prepareRecipients();
    161             $headers    = $relay->prepareHeaders();
     161            $content     = $relay->prepareContent();
     162            $subject     = $relay->prepareSubject();
     163            $recipients  = $relay->prepareRecipients();
     164            $headers     = $relay->prepareHeaders();
     165            $attachments = $relay->prepareAttachments();
    162166
    163167            if ( $switched_locale ) {
     
    165169            }
    166170
    167             $mail = new Generic( $subject, $content, $recipients, $headers );
     171            $mail = new Generic( $subject, $content, $recipients, $headers, $attachments );
    168172            $mail->send();
    169173
     
    194198     * @param WP_Post|null $post
    195199     *
     200     * @return array
     201     */
     202    public function prepareRecipients( WP_Post $post = null ): array {
     203
     204        $recipients = [];
     205
     206        // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
     207        if ( $post ) {
     208            $recipients = get_post_meta( $post->ID, Mails_PT::POST_TYPE_NAME . '_recipients', true );
     209        }
     210
     211        $recipients = apply_filters( "juvo_mail_editor_{$this->trigger}_recipients", $this->parseToCcBcc( $recipients ), $this->context );
     212
     213        return apply_filters( 'juvo_mail_editor_after_recipient_placeholder', $recipients, $this->trigger, $this->context );
     214    }
     215
     216    /**
     217     * @param WP_Post|null $post
     218     *
    196219     * @return string
    197220     */
    198     public function prepareRecipients( WP_Post $post = null ): string {
    199 
    200         // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
    201         if ( ! $post || ! $recipients = get_post_meta( $post->ID, Mails_PT::POST_TYPE_NAME . '_recipients', true ) ) {
    202             $recipients = apply_filters( "juvo_mail_editor_{$this->trigger}_default_recipients", '', $this->context );
    203         }
    204 
    205         $recipients = apply_filters( 'juvo_mail_editor_before_recipient_placeholder', $recipients, $this->trigger, $this->context );
    206         $recipients = Placeholder::replacePlaceholder( $this->placeholders, $recipients, $this->context );
    207 
    208         return apply_filters( 'juvo_mail_editor_after_recipient_placeholder', $recipients, $this->trigger, $this->context );
    209     }
    210 
    211     /**
    212      * @param WP_Post|null $post
    213      *
    214      * @return string
    215      */
    216221    public function prepareContent( WP_Post $post = null ): string {
    217222
    218         // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
    219         if ( ! $post || ! $content = get_the_content( null, false, $post ) ) {
    220             $content = apply_filters( "juvo_mail_editor_{$this->trigger}_message", '', $this->context );
    221         } else {
     223        $content = '';
     224
     225        // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
     226        if ( $post && $content = get_the_content( null, false, $post ) ) {
    222227            $blocks  = parse_blocks( $content );
    223228            $content = '';
     
    228233        }
    229234
    230         $content = apply_filters( 'juvo_mail_editor_before_content_placeholder', $content, $this->trigger, $this->context );
     235        $content = apply_filters( "juvo_mail_editor_{$this->trigger}_message", $content, $this->context );
    231236        $content = Placeholder::replacePlaceholder( $this->placeholders, $content, $this->context );
    232237        $content = apply_filters( 'juvo_mail_editor_after_content_placeholder', $content, $this->trigger, $this->context );
     
    260265    public function prepareSubject( WP_Post $post = null ): string {
    261266
    262         // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
    263         if ( ! $post || ! $subject = get_post_meta( $post->ID, Mails_PT::POST_TYPE_NAME . '_subject', true ) ) {
    264             $subject = apply_filters( "juvo_mail_editor_{$this->trigger}_subject", '', $this->context );
    265         }
    266 
    267         $subject = apply_filters( 'juvo_mail_editor_before_subject_placeholder', $subject, $this->trigger, $this->context );
     267        $subject = '';
     268
     269        // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
     270        if ( $post ) {
     271            $subject = get_post_meta( $post->ID, Mails_PT::POST_TYPE_NAME . '_subject', true );
     272        }
     273
     274        $subject = apply_filters( "juvo_mail_editor_{$this->trigger}_subject", $subject, $this->context );
    268275        $subject = Placeholder::replacePlaceholder( $this->placeholders, $subject, $this->context );
    269276
     
    308315        }
    309316
     317        // Add CC and BCC
     318        $headers = $this->prepareCc( $headers, $post );
     319        $headers = $this->prepareBcc( $headers, $post );
     320
    310321        return apply_filters( "juvo_mail_editor_{$this->trigger}_headers", $headers, $this->context );
    311322    }
    312323
     324    private function prepareAttachments( WP_Post $post = null ): array {
     325
     326        $attachments = [];
     327
     328        // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
     329        if ( $post ) {
     330            $attachments = get_post_meta( $post->ID, Mails_PT::POST_TYPE_NAME . '_attachments', true ) ?: [];
     331
     332            if ( empty( $attachments ) ) {
     333                return $attachments;
     334            }
     335
     336            foreach ( $attachments as $id => &$attachment ) {
     337                $attachment = get_attached_file( $id );
     338            }
     339        }
     340
     341        return apply_filters( "juvo_mail_editor_{$this->trigger}_attachments", $attachments, $this->context );
     342    }
     343
     344    private function prepareCc( array $headers, WP_Post $post = null ): array {
     345
     346        $cc = [];
     347
     348        // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
     349        if ( $post ) {
     350            $cc = get_post_meta( $post->ID, Mails_PT::POST_TYPE_NAME . '_cc', true );
     351        }
     352
     353        $cc = apply_filters( "juvo_mail_editor_{$this->trigger}_cc", $this->parseToCcBcc( $cc, "Cc:" ), $this->context );
     354        $cc = apply_filters( 'juvo_mail_editor_after_cc_placeholder', $cc, $this->trigger, $this->context );
     355
     356        return array_merge( $headers, $cc );
     357    }
     358
     359    private function prepareBcc( array $headers, WP_Post $post = null ): array {
     360
     361        $bcc = [];
     362
     363        // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
     364        if ( $post ) {
     365            $bcc = get_post_meta( $post->ID, Mails_PT::POST_TYPE_NAME . '_bcc', true );
     366        }
     367
     368        $bcc = apply_filters( "juvo_mail_editor_{$this->trigger}_bcc", $this->parseToCcBcc( $bcc, "Bcc:" ), $this->context );
     369        $bcc = apply_filters( 'juvo_mail_editor_after_bcc_placeholder', $bcc, $this->trigger, $this->context );
     370
     371        return array_merge( $headers, $bcc );
     372    }
     373
     374    /**
     375     * Parses cmb2 repeater groups or strings to wp_mail compatible array format for "to", "cc" and "bcc"
     376     *
     377     * @param array|string $recipients
     378     * @param string $prefix "Cc:" or "Bcc:"
     379     *
     380     * @return array
     381     */
     382    private function parseToCcBcc( $recipients, string $prefix = "" ): array {
     383
     384        if ( empty( $recipients ) ) {
     385            return [];
     386        }
     387
     388        if ( is_string( $recipients ) ) {
     389            $recipients = explode( ",", $recipients );
     390        }
     391
     392        foreach ( $recipients as &$recipient ) {
     393
     394            if ( ! empty( $recipient['name'] ) && ! empty( $recipient['mail'] ) ) {
     395                $recipient = "{$recipient['name']} <{$recipient['mail']}>";
     396            } elseif ( empty( $recipient['name'] ) && ! empty( $recipient['mail'] ) ) {
     397                $recipient = $recipient['mail'];
     398            }
     399
     400            $recipient = Placeholder::replacePlaceholder( $this->placeholders, $recipient, $this->context );
     401
     402            if ( ! empty( $prefix ) ) {
     403                $recipient = $prefix . " " . $recipient;
     404            }
     405        }
     406
     407        return $recipients;
     408
     409    }
     410
    313411}
  • juvo-mail-editor/trunk/vendor/autoload.php

    r2665461 r2672700  
    55require_once __DIR__ . '/composer/autoload_real.php';
    66
    7 return ComposerAutoloaderInitdf996d0981a8b06c2981bee783fc4f04::getLoader();
     7return ComposerAutoloaderInitfdfdf11997bf846c7668e97b172e1c1f::getLoader();
  • juvo-mail-editor/trunk/vendor/composer/autoload_real.php

    r2665461 r2672700  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInitdf996d0981a8b06c2981bee783fc4f04
     5class ComposerAutoloaderInitfdfdf11997bf846c7668e97b172e1c1f
    66{
    77    private static $loader;
     
    2323        }
    2424
    25         spl_autoload_register(array('ComposerAutoloaderInitdf996d0981a8b06c2981bee783fc4f04', 'loadClassLoader'), true, true);
     25        spl_autoload_register(array('ComposerAutoloaderInitfdfdf11997bf846c7668e97b172e1c1f', 'loadClassLoader'), true, true);
    2626        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
    27         spl_autoload_unregister(array('ComposerAutoloaderInitdf996d0981a8b06c2981bee783fc4f04', 'loadClassLoader'));
     27        spl_autoload_unregister(array('ComposerAutoloaderInitfdfdf11997bf846c7668e97b172e1c1f', '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\ComposerStaticInitdf996d0981a8b06c2981bee783fc4f04::getInitializer($loader));
     33            call_user_func(\Composer\Autoload\ComposerStaticInitfdfdf11997bf846c7668e97b172e1c1f::getInitializer($loader));
    3434        } else {
    3535            $map = require __DIR__ . '/autoload_namespaces.php';
     
    5252
    5353        if ($useStaticLoader) {
    54             $includeFiles = Composer\Autoload\ComposerStaticInitdf996d0981a8b06c2981bee783fc4f04::$files;
     54            $includeFiles = Composer\Autoload\ComposerStaticInitfdfdf11997bf846c7668e97b172e1c1f::$files;
    5555        } else {
    5656            $includeFiles = require __DIR__ . '/autoload_files.php';
    5757        }
    5858        foreach ($includeFiles as $fileIdentifier => $file) {
    59             composerRequiredf996d0981a8b06c2981bee783fc4f04($fileIdentifier, $file);
     59            composerRequirefdfdf11997bf846c7668e97b172e1c1f($fileIdentifier, $file);
    6060        }
    6161
     
    6969 * @return void
    7070 */
    71 function composerRequiredf996d0981a8b06c2981bee783fc4f04($fileIdentifier, $file)
     71function composerRequirefdfdf11997bf846c7668e97b172e1c1f($fileIdentifier, $file)
    7272{
    7373    if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
  • juvo-mail-editor/trunk/vendor/composer/autoload_static.php

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

    r2665461 r2672700  
    11<?php return array(
    22    'root' => array(
    3         'pretty_version' => '3.0.4',
    4         'version' => '3.0.4.0',
     3        'pretty_version' => '3.0.5',
     4        'version' => '3.0.5.0',
    55        'type' => 'wordpress-plugin',
    66        'install_path' => __DIR__ . '/../../',
    77        'aliases' => array(),
    8         'reference' => '2d251ec3164a7834e1949b59ad82a1c12336148d',
     8        'reference' => '78ed8db8c7bf3e36838fbdeedd047527631aec6d',
    99        'name' => 'juvo/mail-editor',
    1010        'dev' => false,
     
    3939        ),
    4040        'juvo/mail-editor' => array(
    41             'pretty_version' => '3.0.4',
    42             'version' => '3.0.4.0',
     41            'pretty_version' => '3.0.5',
     42            'version' => '3.0.5.0',
    4343            'type' => 'wordpress-plugin',
    4444            'install_path' => __DIR__ . '/../../',
    4545            'aliases' => array(),
    46             'reference' => '2d251ec3164a7834e1949b59ad82a1c12336148d',
     46            'reference' => '78ed8db8c7bf3e36838fbdeedd047527631aec6d',
    4747            'dev_requirement' => false,
    4848        ),
Note: See TracChangeset for help on using the changeset viewer.