Plugin Directory

Changeset 2103858


Ignore:
Timestamp:
06/11/2019 10:26:35 AM (7 years ago)
Author:
ehsantikweb
Message:

Used MailPoet API to add/update the subscriber and Fixed sign-up confirmation bug, tagging 1.3.10

Location:
add-on-contact-form-7-mailpoet
Files:
4 edited
12 copied

Legend:

Unmodified
Added
Removed
  • add-on-contact-form-7-mailpoet/trunk/add-on-contact-form-7-mailpoet.php

    r2089733 r2103858  
    33 * Plugin Name:       Add-on Contact Form 7 - Mailpoet 3
    44 * Description:       Add a MailPoet 3 signup field to your Contact Form 7 forms.
    5  * Version:           1.3.10
     5 * Version:           1.3.11
    66 * Author:            Tikweb
    77 * Author URI:        http://www.tikweb.dk/
  • add-on-contact-form-7-mailpoet/trunk/changelog.txt

    r2089733 r2103858  
    11== Changelog ==
     2
     3= 1.3.11 – 2019-06-10 =
     4* Used MailPoet API to add/update the subscriber
     5* Fixed "sign-up confirmation" bug
    26
    37= 1.3.10 – 2019-05-17 =
  • add-on-contact-form-7-mailpoet/trunk/includes/class-mailpoet-cf7-submit-form.php

    r2089733 r2103858  
    1414}
    1515
     16
    1617// use MailPoet\Models\Segment;
    1718use MailPoet\Models\Subscriber;
    18 use MailPoet\Subscribers\ConfirmationEmailMailer;
    1919use MailPoet\Models\CustomField;    #get all custom field info without value
     20use MailPoet\Settings\SettingsController; #get mailpoet settings
    2021
    2122if ( ! class_exists( 'MailPoet_CF7_Submit_Form' ) ) {
     
    145146                                        if ( $subscriber ) {
    146147                                            $subscriber->withSubscriptions();
    147                                             $old_lists = $subscriber->subscriptions;
    148 
    149                                             foreach ( $old_lists as $key => $value ) {
     148                                            $current_lists = $subscriber->subscriptions;
     149
     150                                            foreach ( $current_lists as $key => $value ) {
    150151                                                $list_ids[] = $value['segment_id'];
    151152                                            }
     
    155156                                        $new_list_ids = $form_data['fieldVal'];
    156157
    157                                         $str_to_array = explode( ",", $new_list_ids );
    158 
    159                                         $list_ids = array_merge( $list_ids, $str_to_array );
     158                                        $current_list = explode( ",", $new_list_ids );
     159
     160                                        $list_ids = array_merge( $list_ids, $current_list );
    160161                                    }
    161162                                }
     
    176177
    177178
     179                // Check mailpoet sign-up confirmation
     180                $mp_signup_settings     = new SettingsController();
     181                $mp_signup_confirmation = $mp_signup_settings->get('signup_confirmation.enabled');
     182                if ( $mp_signup_confirmation ) {
     183                    $signup_confirm_state = 'unconfirmed';
     184                } else {
     185                    $signup_confirm_state = 'subscribed';
     186                }
     187
    178188                if ( ! empty( $list_ids ) && is_array( $list_ids ) ) {
    179189                    $subscribe_data = array(
    180190                        'email'      => $email,
    181                         'segments'   => $list_ids,
    182191                        'first_name' => $firstname,
    183192                        'last_name'  => $lastname,
    184                         'status'     => 'unconfirmed',
     193                        'status'     => $signup_confirm_state,
    185194                    );
    186195
     
    202211                    }
    203212
    204                     //Save subcriber data
    205                     $subscriber = Subscriber::createOrUpdate( $subscribe_data );
    206                     if ( ! $subscriber ) {
    207                         return;
    208                     }
    209 
    210                     //Send subscriber a welcome mail
    211                     $sender = new ConfirmationEmailMailer();
    212                     $sender->sendConfirmationEmail( $subscriber );
     213                    $options = array(
     214                        'send_confirmation_email'      => $signup_confirm_state === 'unconfirmed' ? true : false,
     215                        'skip_subscriber_notification' => true //fixing double "New subscriber" email
     216                    );
     217                    //Saving new subscriber
     218                    try {
     219                        $subscriber = \MailPoet\API\API::MP( 'v1' )->addSubscriber( $subscribe_data,
     220                            array_unique( $list_ids ), $options );
     221                    } catch ( Exception $exception ) {
     222                        //If subscriber is already subscribed once and unsubscribed later, then again subscribed to any list, change the status to subscribed and add to the list
     223                        if ( 'This subscriber already exists.' == $exception->getMessage() ) {
     224                            //Change subscriber status to subscribed
     225                            $subscribe_data['status'] = 'subscribed';
     226                            //Update the status
     227                            Subscriber::createOrUpdate( $subscribe_data );
     228                            //Now subscribe to the new list
     229                            try {
     230                                $subscriber = \MailPoet\API\API::MP( 'v1' )->subscribeToLists( $subscribe_data['email'],
     231                                    array_unique( $current_list ) );
     232
     233                            } catch ( Exception $exception ) {
     234
     235                            }
     236                        } else {
     237
     238                        }
     239                    }
     240
    213241
    214242                }
  • add-on-contact-form-7-mailpoet/trunk/readme.txt

    r2089760 r2103858  
    44Donate link: http://www.tikweb.dk/donate/
    55Requires at least: 4.6
    6 Tested up to: 5.2
     6Tested up to: 5.2.1
    77Requires PHP: 5.2
    8 Stable tag: 1.3.10
     8Stable tag: 1.3.11
    99
    1010Add a MailPoet 3 signup field to your Contact Form 7 forms.
     
    3939https://i.imgur.com/fHrpedY.png
    4040
    41 4. Now create any field in contact form 7 same as the custom field that you created in mailpoet. In "Name" field, put the mailpoet’s custom field id number which you copied in earlier step.
     414. Now create any field in contact form 7 same as the custom field that you created in mailpoet. In "Name" field, put the mailpoets custom field id number which you copied in earlier step.
    4242https://i.imgur.com/HpuufxY.png
    4343
Note: See TracChangeset for help on using the changeset viewer.