| | 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 | |