[ Index ]

MailPress 544

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

title

Body

[close]

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

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


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1