Making WordPress.org

Changeset 1396


Ignore:
Timestamp:
03/13/2015 12:56:45 AM (10 years ago)
Author:
iandunn
Message:

WordCamp Organizer Reminders: Support sending reminders to multiple recipient groups.

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-organizer-reminders
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-organizer-reminders/wcor-mailer.php

    r1310 r1396  
    228228
    229229    /**
    230      * Retrieve the e-mail address that a Reminder should be sent to.
     230     * Retrieve the e-mail address(es) that a Reminder should be sent to.
    231231     *
    232232     * @param int $wordcamp_id
    233233     * @param int $email_id
    234      * @return string
    235      */
    236     protected function get_recipient( $wordcamp_id, $email_id ) {
    237         $recipient  = false;
    238         $send_where = get_post_meta( $email_id, 'wcor_send_where', true );
    239 
    240         if ( 'wcor_send_custom' == $send_where ) {
    241             $recipient = get_post_meta( $email_id, 'wcor_send_custom_address', true );
    242         } elseif ( 'wcor_send_mes' == $send_where ) {
     234     *
     235     * @return array
     236     */
     237    protected function get_recipients( $wordcamp_id, $email_id ) {
     238        $recipients = array();
     239        $send_where = get_post_meta( $email_id, 'wcor_send_where' );
     240
     241        if ( in_array( 'wcor_send_custom', $send_where ) ) {
     242            $recipients[] = get_post_meta( $email_id, 'wcor_send_custom_address', true );
     243        }
     244
     245        if ( in_array( 'wcor_send_mes', $send_where ) ) {
    243246            /** @var $multi_event_sponsors Multi_Event_Sponsors */
    244247            global $multi_event_sponsors;
    245248
    246             $recipient = $multi_event_sponsors->get_sponsor_emails( $multi_event_sponsors->get_wordcamp_me_sponsors( $wordcamp_id ) );
    247         } elseif ( 'wcor_send_sponsor_wrangler' == $send_where ) {
    248 
     249            $recipients = array_merge(
     250                $recipients,
     251                $multi_event_sponsors->get_sponsor_emails( $multi_event_sponsors->get_wordcamp_me_sponsors( $wordcamp_id ) )
     252            );
     253        }
     254
     255        if ( in_array( 'wcor_send_sponsor_wrangler', $send_where ) ) {
    249256            // If the Sponsor Wrangler email is invalid, use the default email address.
    250257            if ( is_email( get_post_meta( $wordcamp_id, 'Sponsor Wrangler E-mail Address', true ) ) ) {
    251                 $recipient = get_post_meta( $wordcamp_id, 'Sponsor Wrangler E-mail Address', true );
     258                $recipients[] = get_post_meta( $wordcamp_id, 'Sponsor Wrangler E-mail Address', true );
    252259            } else {
    253                 $recipient = get_post_meta( $wordcamp_id, 'Email Address', true );
    254             }
    255 
    256         } elseif ( 'wcor_send_camera_wrangler' == $send_where ) {
     260                $recipients[] = get_post_meta( $wordcamp_id, 'Email Address', true );
     261            }
     262        }
     263
     264        if ( in_array( 'wcor_send_camera_wrangler', $send_where ) ) {
    257265            $region_id = get_post_meta( $wordcamp_id, 'Multi-Event Sponsor Region', true );
    258             $recipient = MES_Region::get_camera_wranger_from_region( $region_id );
    259         } else {
     266            $recipients[] = MES_Region::get_camera_wranger_from_region( $region_id );
     267        }
     268
     269        if ( in_array( 'wcor_send_organizers', $send_where ) ) {
    260270            $email_address_key = wcpt_key_to_str( 'E-mail Address', 'wcpt_' );
    261271
     272            /*
     273             * If a WordCamp post type is being updated, use the new address in the request, rather than the old
     274             * one stored in the database
     275             */
    262276            if ( ! empty( $_POST[ $email_address_key ] ) ) {
    263                 $recipient = sanitize_email( $_POST[ $email_address_key ] );
     277                $recipients[] = sanitize_email( $_POST[ $email_address_key ] );
    264278            } else {
    265                 $recipient = sanitize_email( get_post_meta( $wordcamp_id, 'E-mail Address', true ) );
    266             }
    267         }
    268 
    269         return $recipient;
     279                $recipients[] = sanitize_email( get_post_meta( $wordcamp_id, 'E-mail Address', true ) );
     280            }
     281        }
     282
     283        return $recipients;
    270284    }
    271285
     
    299313     */
    300314    public function send_manual_email( $email, $wordcamp ) {
    301         $recipient = $this->get_recipient( $wordcamp->ID, $email->ID );
     315        $recipient = $this->get_recipients( $wordcamp->ID, $email->ID );
    302316
    303317        return $this->mail( $recipient, $email->post_title, $email->post_content, array(), $email, $wordcamp );
     
    344358
    345359            foreach ( $reminder_emails as $email ) {
    346                 $recipient = $this->get_recipient( $wordcamp->ID, $email->ID );
     360                $recipient = $this->get_recipients( $wordcamp->ID, $email->ID );
    347361               
    348362                if ( $this->timed_email_is_ready_to_send( $wordcamp, $email, $sent_email_ids ) ) {
     
    465479     */
    466480    protected function send_individual_emails( $email_id ) {
    467         $send_where = get_post_meta( $email_id, 'wcor_send_where', true );
    468 
    469         return 'wcor_send_mes' == $send_where;
     481        $send_where = get_post_meta( $email_id, 'wcor_send_where' );
     482
     483        return in_array( 'wcor_send_mes', $send_where );
    470484    }
    471485
     
    534548
    535549        foreach( $emails as $email ) {
    536             $recipient = $this->get_recipient( $wordcamp->ID, $email->ID );
     550            $recipient = $this->get_recipients( $wordcamp->ID, $email->ID );
    537551
    538552            if ( ! in_array( $email->ID, $sent_email_ids ) ) {
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-organizer-reminders/wcor-reminder.php

    r1309 r1396  
    8585     */
    8686    public function markup_reminder_details( $post ) {
    87         $send_where              = get_post_meta( $post->ID, 'wcor_send_where', true );
     87        $send_where              = get_post_meta( $post->ID, 'wcor_send_where' );
    8888        $send_custom_address     = get_post_meta( $post->ID, 'wcor_send_custom_address', true );
    8989        $send_when               = get_post_meta( $post->ID, 'wcor_send_when', true );
     
    100100            <tbody>
    101101                <tr>
    102                     <th><input id="wcor_send_organizers" name="wcor_send_where" type="radio" value="wcor_send_organizers" <?php checked( $send_where, 'wcor_send_organizers' ); ?>></th>
     102                    <th><input id="wcor_send_organizers" name="wcor_send_where[]" type="checkbox" value="wcor_send_organizers" <?php checked( in_array( 'wcor_send_organizers', $send_where ) ); ?>></th>
    103103                    <td colspan="2"><label for="wcor_send_organizers">The organizing team</label></td>
    104104                </tr>
    105105
    106106                <tr>
    107                     <th><input id="wcor_send_sponsor_wrangler" name="wcor_send_where" type="radio" value="wcor_send_sponsor_wrangler" <?php checked( $send_where, 'wcor_send_sponsor_wrangler' ); ?>></th>
     107                    <th><input id="wcor_send_sponsor_wrangler" name="wcor_send_where[]" type="checkbox" value="wcor_send_sponsor_wrangler" <?php checked( in_array( 'wcor_send_sponsor_wrangler', $send_where ) ); ?>></th>
    108108                    <td colspan="2"><label for="wcor_send_sponsor_wrangler">The Sponsor Wrangler</label></td>
    109109                </tr>
    110110
    111111                <tr>
    112                     <th><input id="wcor_send_mes" name="wcor_send_where" type="radio" value="wcor_send_mes" <?php checked( $send_where, 'wcor_send_mes' ); ?>></th>
     112                    <th><input id="wcor_send_mes" name="wcor_send_where[]" type="checkbox" value="wcor_send_mes" <?php checked( in_array( 'wcor_send_mes', $send_where ) ); ?>></th>
    113113                    <td colspan="2"><label for="wcor_send_mes">The WordCamp's Multi-Event Sponsors</label></td>
    114114                </tr>
    115115
    116116                <tr>
    117                     <th><input id="wcor_send_camera_wrangler" name="wcor_send_where" type="radio" value="wcor_send_camera_wrangler" <?php checked( $send_where, 'wcor_send_camera_wrangler' ); ?>></th>
     117                    <th><input id="wcor_send_camera_wrangler" name="wcor_send_where[]" type="checkbox" value="wcor_send_camera_wrangler" <?php checked( in_array( 'wcor_send_camera_wrangler', $send_where ) ); ?>></th>
    118118                    <td colspan="2"><label for="wcor_send_camera_wrangler">The Region's Camera Kit Wrangler</label></td>
    119119                </tr>
    120120
    121121                <tr>
    122                     <th><input id="wcor_send_custom" name="wcor_send_where" type="radio" value="wcor_send_custom" <?php checked( $send_where, 'wcor_send_custom' ); ?>></th>
     122                    <th><input id="wcor_send_custom" name="wcor_send_where[]" type="checkbox" value="wcor_send_custom" <?php checked( in_array( 'wcor_send_custom', $send_where ) ); ?>></th>
    123123                    <td><label for="wcor_send_custom">A custom address: </label></td>
    124124                    <td><input id="wcor_send_custom_address" name="wcor_send_custom_address" type="text" class="regular-text" value="<?php echo esc_attr( $send_custom_address ); ?>" /></td>
     
    367367     */
    368368    protected function save_post_meta( $post, $new_meta ) {
     369        $send_where_whitelist = array( 'wcor_send_organizers', 'wcor_send_sponsor_wrangler', 'wcor_send_mes', 'wcor_send_camera_wrangler', 'wcor_send_custom' );
     370
     371        delete_post_meta( $post->ID, 'wcor_send_where' );
    369372        if ( isset( $new_meta['wcor_send_where'] ) ) {
    370             if ( in_array( $new_meta['wcor_send_where'], array( 'wcor_send_organizers', 'wcor_send_sponsor_wrangler', 'wcor_send_mes', 'wcor_send_camera_wrangler', 'wcor_send_custom' ) ) ) {
    371                 update_post_meta( $post->ID, 'wcor_send_where', $new_meta['wcor_send_where'] );
     373            foreach( $new_meta['wcor_send_where'] as $send_where ) {
     374                if ( in_array( $send_where, $send_where_whitelist ) ) {
     375                    add_post_meta( $post->ID, 'wcor_send_where', $send_where );
     376                }
    372377            }
    373378        }
Note: See TracChangeset for help on using the changeset viewer.