Making WordPress.org

Ticket #595: 595.patch

File 595.patch, 6.9 KB (added by nvwd, 11 years ago)
  • addons/require-login.php

     
    4747
    4848                // Misc
    4949                add_filter( 'camptix_attendees_shortcode_query_args',         array( $this, 'hide_unconfirmed_attendees' ) );
     50                add_action( 'tix_scheduled_daily',                            array( $this, 'remind_unconfirmed_attendees' ) );
    5051        }
    5152
    5253        /**
     
    307308         */
    308309        public function get_attendee_search_meta( $attendee_search_meta ) {
    309310                $attendee_search_meta[] = 'tix_username';
    310                
     311
    311312                return $attendee_search_meta;
    312313        }
    313314
     
    352353                        'callback_method' => 'field_textarea',
    353354                );
    354355
     356                $templates['email_template_unconfirmed_attendee_reminder'] = array(
     357                        'title'           => __( 'Multiple Purchase Reminder (to unconfirmed attendees)', 'camptix' ),
     358                        'callback_method' => 'field_textarea',
     359                );
     360
     361                $templates['email_template_unknown_attendee_reminder'] = array(
     362                        'title'           => __( 'Multiple Purchase Reminder (for unknown attendees)', 'camptix' ),
     363                        'callback_method' => 'field_textarea',
     364                );
     365
    355366                return $templates;
    356367        }
    357368
     
    367378                $options['email_template_multiple_purchase_unconfirmed_attendee']          = __( "Hi there!\n\nA ticket to [event_name] has been purchased for you by [buyer_full_name].\n\nPlease visit the following page and fill in your information to complete your registration:\n\n[ticket_url]\n\nLet us know if you have any questions!", 'camptix' );
    368379                $options['email_template_multiple_purchase_unknown_attendee']              = __( "Hi there!\n\nThis e-mail is for the unknown attendee that you purchased a ticket for. When you decide who will be using the ticket, please forward the link below to them so that they can complete their registration.\n\n[ticket_url]\n\nLet us know if you have any questions!", 'camptix' );
    369380
     381                // TODO: populate reminder templates with appropriate content
     382                $options['email_template_unconfirmed_attendee_reminder']                   = __( "Hi there!\n\nA ticket to [event_name] has been purchased for you.\n\nTo complete your registration, please confirm your ticket by visiting the following page:\n\n[ticket_url]\n\nLet us know if you have any questions!", 'camptix' );
     383                $options['email_template_unknown_attendee_reminder']                       = __( "Hi there!\n\nThis e-mail is for the unknown attendee that you purchased a ticket for. When you decide who will be using the ticket, please forward the link below to them so that they can complete their registration.\n\n[ticket_url]\n\nLet us know if you have any questions!", 'camptix' );
     384
    370385                return $options;
    371386        }
    372387
     
    394409                                }
    395410
    396411                                break;
     412                        case 'email_template_unconfirmed_reminder':
     413                                $unknown_attendee_info = $this->get_unknown_attendee_info();
     414
     415                                if ( $unknown_attendee_info['email'] == get_post_meta( $attendee->ID, 'tix_email', true ) ) {
     416                                        $template = 'email_template_unknown_attendee_reminder';
     417                                } elseif ( self::UNCONFIRMED_USERNAME == get_post_meta( $attendee->ID, 'tix_username', true ) ) {
     418                                        $template = 'email_template_unconfirmed_attendee_reminder';
     419                                }
     420
     421                                break;
    397422                }
    398423
    399424                return $template;
     
    760785
    761786                return $query_args;
    762787        }
    763 } // CampTix_Require_Login
    764788
     789        /**
     790         * send reminders to the unconfirmed attendees
     791         *
     792         * TODO:
     793         * - get proper text for the subject and body for each situation;
     794         *
     795         * @return array
     796         */
     797        public function remind_unconfirmed_attendees() {
     798                global $shortcode_tags, $camptix;
     799
     800                // get Camp date
     801                $wordcamp = get_wordcamp_post();
     802
     803                // set up a couple dates to use for calculations
     804                $wordcamp_date = strtotime( $wordcamp->meta['Start Date (YYYY-mm-dd)'][0] );
     805                $days_until_camp = floor( ( $wordcamp_date - $now ) / DAY_IN_SECONDS );
     806                $now = strtotime( 'now' );
     807
     808                // only remind unconfirmed attendees within the 24 days prior to the Camp
     809                // NOTE: may want to set the days before camp to be a constant - using 24 for now
     810                if ( $now >= $wordcamp_date || $days_until_camp > 24 ) {
     811                        return;
     812                }
     813
     814                // set things up now that we are within a month before the Camp
     815
     816                // if Camp is 7 days or more away set the interval to 7 days for at most weekly reminders.
     817                // if Camp is less than 7 days away sneak in another reminder at about 3 days out
     818                if ( 7 <= $days_until_camp ) {
     819                        $max_date_for_notification = strtotime( 'now - 7 days' );
     820                } else {
     821                        $max_date_for_notification = strtotime( 'now - 4 days' );
     822                }
     823
     824                // Remove all shortcodes before sending the e-mails, but bring them back later.
     825                $this->removed_shortcodes = $shortcode_tags;
     826                remove_all_shortcodes();
     827
     828                // setup shortcodes for these email templates
     829                do_action( 'camptix_init_email_templates_shortcodes' );
     830
     831                $default_attendee_values = $this->get_unknown_attendee_info();
     832
     833                $query_args = array(
     834                        'post_type'                     => 'tix_attendee',
     835                        'post_status'           => 'publish',
     836                        'posts_per_page'        => -1,
     837                        'meta_query'            => array(
     838                                array(
     839                                        'key'           => 'tix_username',
     840                                        'value'         => self::UNCONFIRMED_USERNAME,
     841                                        'compare'       => '='
     842                                )
     843                        ),
     844                );
     845
     846                $unconfirmed_attendees = get_posts( $query_args );
     847
     848                $subject = sprintf( __( "%s Unconfirmed Ticket Reminder", 'camptix' ), $wordcamp->post_title );
     849
     850                foreach( $unconfirmed_attendees AS $attendee ) {
     851
     852                        // set camptix attendee ID
     853                        $camptix->tmp( 'attendee_id', $attendee->ID );
     854
     855                        // get attendee meta
     856                        $attendee_meta = get_post_custom( $attendee->ID );
     857                        $last_reminder_sent_date = empty( $attendee_meta['tix_last_unconfirmed_reminder_date(YYYY-mm-dd)'] ) ? 0 : strtotime( $attendee_meta['tix_last_unconfirmed_reminder_date(YYYY-mm-dd)'] );
     858
     859                        // check last reminder sent - if set, make sure at least 7 days have passed before sending another
     860                        if ( $last_reminder_sent_date > $max_date_for_notification ) {
     861                                continue;
     862                        }
     863
     864                        // set notification vars
     865                         $camptix->tmp( 'ticket_url', $camptix->get_edit_attendee_link( $attendee->ID, $attendee_meta['tix_edit_token'] ) );
     866
     867                        // if there is an email address for the unconfirmed attendee use it, else use the receipt email address
     868                        if ( $default_attendee_values['email'] !== $attendee_meta['tix_email'] ) {
     869                                $send_to = $attendee_meta['tix_email'];
     870                        } else {
     871                                $send_to = $attendee_meta['tix_receipt_email'];
     872                        }
     873                        $email_template = apply_filters( 'camptix_email_tickets_template', 'email_template_unconfirmed_reminder', $attendee );
     874                        $content = do_shortcode( $camptix->options[ $email_template ] );
     875
     876                        // send message
     877                        if ( $camptix->wp_mail( $send_to, $subject, $content ) ) {
     878                                // if mail successfull set last reminder sent date meta
     879                                update_post_meta( $attendee->ID, 'tix_last_unconfirmed_reminder_date(YYYY-mm-dd)', date( 'Y-m-d' ) );
     880                        }
     881
     882                }
     883
     884                // Bring the original shortcodes back.
     885                $shortcode_tags = $this->removed_shortcodes;
     886                $this->removed_shortcodes = array();
     887
     888        }
     889
     890} // CampTix_Require_Login
     891
    765892camptix_register_addon( 'CampTix_Require_Login' );