Making WordPress.org

Changeset 6966


Ignore:
Timestamp:
03/29/2018 01:19:10 AM (6 years ago)
Author:
coreymckrill
Message:

WordCamp tickets: Fix issues with allergy/accommodation email notifications

  • Ensure the notification email has the correct link to the attendee by waiting until the payment has completed before sending.
  • Ensure PhpMailer doesn't have extra content left over from a previous email.
Location:
sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/addons
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/addons/accommodations.php

    r6945 r6966  
    55
    66use CampTix_Plugin, CampTix_Addon;
     7use WP_Post;
     8use PHPMailer;
    79
    810/**
     
    2527        add_filter( 'camptix_form_register_complete_attendee_object', array( $this, 'populate_attendee_object' ), 10, 2 );
    2628        add_action( 'camptix_checkout_update_post_meta', array( $this, 'save_registration_field' ), 10, 2 );
     29        add_action( 'camptix_ticket_emailed', array( $this, 'after_email_receipt' ) );
    2730
    2831        // Edit info field
     
    8487     * Add the value of the new field to the attendee object during checkout processing.
    8588     *
    86      * @param \WP_Post $attendee
     89     * @param WP_Post $attendee
    8790     * @param array    $data
    8891     *
    89      * @return \WP_Post
     92     * @return WP_Post
    9093     */
    9194    public function populate_attendee_object( $attendee, $data ) {
     
    99102     *
    100103     * @param int      $post_id
    101      * @param \WP_Post $attendee
     104     * @param WP_Post $attendee
    102105     *
    103106     * @return bool|int
    104107     */
    105108    public function save_registration_field( $post_id, $attendee ) {
    106         $this->maybe_send_notification_email( $attendee->{ self::SLUG }, get_post( $post_id ) );
    107 
    108109        return update_post_meta( $post_id, 'tix_' . self::SLUG, $attendee->{ self::SLUG } );
    109110    }
    110111
    111112    /**
     113     * Initialize email notifications after the ticket receipt email has been sent.
     114     *
     115     * @param WP_Post $attendee_id
     116     */
     117    public function after_email_receipt( $attendee_id ) {
     118        $attendee = get_post( $attendee_id );
     119        $value    = get_post_meta( $attendee_id, 'tix_' . self::SLUG, true );
     120
     121        if ( $attendee instanceof WP_Post && 'tix_attendee' === $attendee->post_type ) {
     122            $this->maybe_send_notification_email( $value, $attendee );
     123        }
     124    }
     125
     126    /**
    112127     * Retrieve the stored value of the new field for use on the Edit Info form.
    113128     *
    114129     * @param array    $ticket_info
    115      * @param \WP_Post $attendee
     130     * @param WP_Post $attendee
    116131     *
    117132     * @return array
     
    127142     *
    128143     * @param array    $data
    129      * @param \WP_Post $attendee
     144     * @param WP_Post $attendee
    130145     *
    131146     * @return bool|int
     
    171186     *
    172187     * @param string   $value
    173      * @param \WP_Post $attendee
     188     * @param WP_Post $attendee
    174189     */
    175190    protected function maybe_send_notification_email( $value, $attendee ) {
     
    184199        if ( $already_sent ) {
    185200            return;
     201        }
     202
     203        global $phpmailer;
     204        if ( $phpmailer instanceof PHPMailer ) {
     205            // Clear out any lingering content from a previously sent message.
     206            $phpmailer = new PHPMailer( true );
    186207        }
    187208
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/addons/allergy.php

    r6945 r6966  
    55
    66use CampTix_Plugin, CampTix_Addon;
     7use WP_Post;
     8use PHPMailer;
    79
    810/**
     
    2527        add_filter( 'camptix_form_register_complete_attendee_object', array( $this, 'populate_attendee_object' ), 10, 2 );
    2628        add_action( 'camptix_checkout_update_post_meta', array( $this, 'save_registration_field' ), 10, 2 );
     29        add_action( 'camptix_ticket_emailed', array( $this, 'after_email_receipt' ) );
    2730
    2831        // Edit info field
     
    8487     * Add the value of the new field to the attendee object during checkout processing.
    8588     *
    86      * @param \WP_Post $attendee
     89     * @param WP_Post $attendee
    8790     * @param array    $data
    8891     *
    89      * @return \WP_Post
     92     * @return WP_Post
    9093     */
    9194    public function populate_attendee_object( $attendee, $data ) {
     
    99102     *
    100103     * @param int      $post_id
    101      * @param \WP_Post $attendee
     104     * @param WP_Post $attendee
    102105     *
    103106     * @return bool|int
    104107     */
    105108    public function save_registration_field( $post_id, $attendee ) {
    106         $this->maybe_send_notification_email( $attendee->{ self::SLUG }, get_post( $post_id ) );
    107 
    108109        return update_post_meta( $post_id, 'tix_' . self::SLUG, $attendee->{ self::SLUG } );
    109110    }
    110111
    111112    /**
     113     * Initialize email notifications after the ticket receipt email has been sent.
     114     *
     115     * @param WP_Post $attendee_id
     116     */
     117    public function after_email_receipt( $attendee_id ) {
     118        $attendee = get_post( $attendee_id );
     119        $value    = get_post_meta( $attendee_id, 'tix_' . self::SLUG, true );
     120
     121        if ( $attendee instanceof WP_Post && 'tix_attendee' === $attendee->post_type ) {
     122            $this->maybe_send_notification_email( $value, $attendee );
     123        }
     124    }
     125
     126    /**
    112127     * Retrieve the stored value of the new field for use on the Edit Info form.
    113128     *
    114129     * @param array    $ticket_info
    115      * @param \WP_Post $attendee
     130     * @param WP_Post $attendee
    116131     *
    117132     * @return array
     
    127142     *
    128143     * @param array    $data
    129      * @param \WP_Post $attendee
     144     * @param WP_Post $attendee
    130145     *
    131146     * @return bool|int
     
    171186     *
    172187     * @param string   $value
    173      * @param \WP_Post $attendee
     188     * @param WP_Post $attendee
    174189     */
    175190    protected function maybe_send_notification_email( $value, $attendee ) {
     
    184199        if ( $already_sent ) {
    185200            return;
     201        }
     202
     203        global $phpmailer;
     204        if ( $phpmailer instanceof PHPMailer ) {
     205            // Clear out any lingering content from a previously sent message.
     206            $phpmailer = new PHPMailer( true );
    186207        }
    187208
Note: See TracChangeset for help on using the changeset viewer.