Plugin Directory

Changeset 1449435


Ignore:
Timestamp:
07/05/2016 06:08:44 PM (10 years ago)
Author:
harshit_ps
Message:

Added asu boolean to user meta, so if the user unsubscribes manually, we don't auto subscribe that user next time the user registers new site.

Location:
auto-subscribe-users/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • auto-subscribe-users/trunk/README.txt

    r1445482 r1449435  
    55Requires at least: 3.0.1
    66Tested up to: 4.5.3
    7 Stable tag: 0.0.5
     7Stable tag: 0.0.6
    88License: GPLv3 or later
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    7474== Changelog ==
    7575
     76= 0.0.6 =
     77* If user manually auto subscribes, won't be auto subscribed when that user creates new site in multisite.
     78
    7679= 0.0.5 =
    7780* Updated readme.
  • auto-subscribe-users/trunk/auto-subscribe-users.php

    r1442774 r1449435  
    66Author: Harshit Sanghvi
    77Author URI: https://sanghviharshit.com
    8 Version: 0.0.5
     8Version: 0.0.6
    99License: GNU General Public License (Version 3 - GPLv3)
    1010*/
     
    3838class Auto_Subscribe_Users {
    3939
     40
     41        private $sbe_key;
     42        private $esn_key;
     43
    4044    /**
    4145     * Constructor.
    4246     */
    4347    function __construct() {
     48            $this->sbe_key = 'asu_sbe';
     49            $this->esn_key = 'asu_esn';
     50
    4451        add_action( 'init', array( $this, 'init' ), 1 );
    4552    }
     
    139146        }
    140147
    141         if( function_exists( 'es_sync_registereduser') ) {
    142             // If Email Subscribers & Newsletter Plugin is active on the main site
    143             $es_c_emailsubscribers = get_option('es_c_emailsubscribers', 'norecord');
    144             self::write_log("es_c_emailsubscribers" . $es_c_emailsubscribers);
     148            $user_esn = get_user_meta($user_id, $this->esn_key, $single = true);
     149
     150        // Check if Email Subscribers & Newsletter Plugin is active on the main site
     151        if( $user_esn != '' && $user_esn != 'true' ) {
     152            if( function_exists( 'es_sync_registereduser') ) {
     153               
     154                $es_c_emailsubscribers = get_option('es_c_emailsubscribers', 'norecord');
     155            //self::write_log("es_c_emailsubscribers" . $es_c_emailsubscribers);
    145156            if($es_c_emailsubscribers == 'norecord' || $es_c_emailsubscribers == "" || (!empty($es_c_emailsubscribers['es_registered']) && $es_c_emailsubscribers['es_registered'] <> "YES"))  {
    146157                $es_c_emailsubscribers_bak = $es_c_emailsubscribers;
     
    151162                es_sync_registereduser($user_id);
    152163                update_option('es_c_emailsubscribers', $$es_c_emailsubscribers_bak);
    153             }
    154164           
    155         } else if ( class_exists( 'Incsub_Subscribe_By_Email' ) && method_exists( 'Incsub_Subscribe_By_Email', 'subscribe_user' ) && method_exists( 'Incsub_Subscribe_By_Email', 'send_confirmation_mail' ) ) {
    156             // The Subscription plugin has to be active on the main site. If WPMYU's Subscribe by Email plugin is not active, there's nothing to do.
    157             $user_info = get_userdata($user_id);
    158             //Force email confirmation
    159             $subscription_id = Incsub_Subscribe_By_Email::subscribe_user( $user_info->user_email, __( 'Auto Subscribe', INCSUB_SBE_LANG_DOMAIN ), __( 'Auto Subscribed on Create Site Action', INCSUB_SBE_LANG_DOMAIN ), true );
    160             //Incsub_Subscribe_By_Email::send_confirmation_mail( $subscription_id, $force = true );
    161         }
     165                //Add auto subscribed boolean to user meta, so if the user unsubscribes, we don't auto subscribe that user next time the user registers new site.
     166                update_user_meta( $user_id, $this->esn_key, 'true' );
     167            }
     168          }
     169        }
     170
     171            $user_sbe = get_user_meta($user_id, $this->sbe_key, $single = true);
     172           
     173                if( $user_sbe != '' && $user_sbe != 'true' ) {
     174            // Check if WPMU Subscribe By Email plugin is active
     175            if ( class_exists( 'Incsub_Subscribe_By_Email' ) && method_exists( 'Incsub_Subscribe_By_Email', 'subscribe_user' ) && method_exists( 'Incsub_Subscribe_By_Email', 'send_confirmation_mail' ) ) {
     176                // The Subscription plugin has to be active on the main site. If WPMYU's Subscribe by Email plugin is not active, there's nothing to do.
     177                $user_info = get_userdata($user_id);
     178                //Force email confirmation
     179                $subscription_id = Incsub_Subscribe_By_Email::subscribe_user( $user_info->user_email, __( 'Auto Subscribe', INCSUB_SBE_LANG_DOMAIN ), __( 'Auto Subscribed on Create Site Action', INCSUB_SBE_LANG_DOMAIN ), true );
     180                //ToDo: settings page
     181                //Incsub_Subscribe_By_Email::send_confirmation_mail( $subscription_id, $force = true );
     182
     183                //Add auto subscribed boolean to user meta, so if the user unsubsribes, we don't auto subscribe that user next time the user registers new site.
     184              update_user_meta( $user_id, $this->sbe_key, 'true' );
     185            }
     186          }
    162187
    163188    }
Note: See TracChangeset for help on using the changeset viewer.