[ Index ]

MailPress 7.1

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-content/add-ons/ -> MailPress_delete_inactive_users.php (source)

   1  <?php
   2  if ( class_exists( 'MailPress' ) && !class_exists( 'MailPress_delete_inactive_users' ) )
   3  {
   4  /*
   5  Plugin Name: MailPress_delete_inactive_users
   6  Plugin URI: http://blog.mailpress.org/tutorials/add-ons/delete_inactive_users/
   7  Description: Users : delete inactive/bounced/unsubscribed mp users
   8  Version: 7.1
   9  */
  10  
  11  class MailPress_delete_inactive_users
  12  {
  13      const option_name = 'MailPress_delete_inactive_users';
  14  
  15      const process_name        = 'mp_process_delete_inactive_users';
  16  
  17      const bt = 132;
  18  
  19  	function __construct()
  20      {
  21          add_action( self::process_name,                 array( $this, 'process' ) );
  22  
  23          $config = get_option( self::option_name );
  24          if ( 'wpcron' == $config['batch_mode'] )
  25          {    
  26              add_action( 'MailPress_schedule_delete_inactive_users',     array( __CLASS__, 'schedule' ) );
  27          }
  28  
  29          if ( is_admin() )
  30          {
  31          // for install
  32              register_activation_hook( plugin_basename( __FILE__ ),     array( __CLASS__, 'install' ) );
  33              register_deactivation_hook( plugin_basename( __FILE__ ),    array( __CLASS__, 'uninstall' ) );
  34          // for link on plugin page
  35              add_filter( 'plugin_action_links',                 array( __CLASS__, 'plugin_action_links' ), 10, 2 );
  36  
  37          // for settings
  38              add_filter( 'MailPress_scripts',                 array( __CLASS__, 'scripts' ), 8, 2 );
  39              add_filter( 'MailPress_settings_tab',             array( __CLASS__, 'settings_tab' ), 20, 1 );
  40          // for settings batches
  41              add_filter( 'MailPress_settings_batches_help',        array( __CLASS__, 'settings_batches_help' ), 20, 1 );
  42              add_action( 'MailPress_settings_batches_update',    array( __CLASS__, 'settings_batches_update' ), 20 );
  43              add_action( 'MailPress_settings_batches_form',        array( __CLASS__, 'settings_batches_form' ), 20 );
  44          }    
  45      }
  46  
  47  // process
  48  	public static function process()
  49      {
  50          self::schedule();
  51  
  52          global $wpdb;
  53  
  54          $config = get_option( self::option_name );
  55          if ( !$config ) return false;
  56  
  57          MP_::no_abort_limit();
  58  
  59          $date = date( 'Y-m-d', current_time( 'timestamp' ) - ( $config['days'] * 86400 ) );
  60  
  61          $ids = $wpdb->get_results( $wpdb->prepare( "SELECT id FROM $wpdb->mp_users WHERE status in ( 'waiting', 'inactive', 'unsubscribed' ) AND DATE( laststatus ) < %s;", $date ) );
  62  
  63          foreach( $ids as $id ) MP_User::delete( $id->id );
  64      }
  65  
  66  // schedule
  67  	public static function schedule()
  68      {
  69          $config = get_option( self::option_name );
  70          $now4cron = current_time( 'timestamp', 'gmt' );
  71  
  72          if ( !wp_next_scheduled( self::process_name ) ) 
  73              wp_schedule_single_event( $now4cron + $config['every'] * 86400, self::process_name );
  74      }
  75  
  76  ////  ADMIN  ////
  77  ////  ADMIN  ////
  78  ////  ADMIN  ////
  79  ////  ADMIN  ////
  80  
  81  // for install
  82  	public static function install() 
  83      {
  84          self::uninstall();
  85  
  86          do_action( 'MailPress_schedule_delete_inactive_users' );
  87      }
  88  
  89  	public static function uninstall() 
  90      {
  91          wp_clear_scheduled_hook( self::process_name );
  92      }
  93  
  94  // for link on plugin page
  95  	public static function plugin_action_links( $links, $file )
  96      {
  97          return MailPress::plugin_links( $links, $file, plugin_basename( __FILE__ ), 'batches' );
  98      }
  99  
 100  // for settings
 101  	public static function scripts( $scripts, $screen ) 
 102      {
 103          if ( $screen != MailPress_page_settings ) return $scripts;
 104  
 105          wp_register_script( 'mp-delete-inactive-users',     '/' . MP_PATH . 'mp-admin/js/settings_delete_inactive_users.js', array(), false, 1 );
 106          $scripts[] = 'mp-delete-inactive-users';
 107          return $scripts;
 108      }
 109  
 110  	public static function settings_tab( $tabs )
 111      {
 112          $tabs['batches'] = __( 'Batches', 'MailPress' );
 113          return $tabs;
 114      }
 115  
 116  // for settings batches
 117  	public static function settings_batches_help( $content )
 118      {
 119          include  ( MP_ABSPATH . 'mp-admin/includes/settings/batches/delete_inactive_users/help.php' );
 120          return $content;
 121      }
 122  
 123  	public static function settings_batches_update()
 124      {
 125          include  ( MP_ABSPATH . 'mp-admin/includes/settings/batches/delete_inactive_users/update.php' );
 126      }
 127  
 128  	public static function settings_batches_form()
 129      {
 130          include  ( MP_ABSPATH . 'mp-admin/includes/settings/batches/delete_inactive_users/form.php' );
 131      }
 132  
 133  }
 134  new MailPress_delete_inactive_users();
 135  }


Generated: Mon Mar 11 18:33:33 2019 Cross-referenced by PHPXref 0.7.1