[ Index ]

MailPress 7.2

[ 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: 7.2
   9  */
  10  
  11  class MailPress_delete_old_mails
  12  {
  13      const option_name = 'MailPress_delete_old_mails';
  14  
  15      const process_name        = 'mp_process_delete_old_mails';
  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_old_mails',     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_settings_tab',                 array( __CLASS__, 'settings_tab' ), 20, 1 );
  39          // for settings batches
  40              add_filter( 'MailPress_settings_batches_help',        array( __CLASS__, 'settings_batches_help' ), 20, 1 );
  41              add_action( 'MailPress_settings_batches_update',    array( __CLASS__, 'settings_batches_update' ), 20 );
  42              add_action( 'MailPress_settings_batches_form',        array( __CLASS__, 'settings_batches_form' ), 20 );
  43          }    
  44      }
  45  
  46  // process
  47  	public static function process()
  48      {
  49          self::schedule();
  50  
  51          global $wpdb;
  52  
  53          $config = get_option( self::option_name );
  54          if ( !$config ) return false;
  55  
  56          MP_::no_abort_limit();
  57  
  58          $date = date( 'Y-m-d', current_time( 'timestamp' ) - ( $config['days'] * DAY_IN_SECONDS ) );
  59  
  60          $ids = $wpdb->get_results( $wpdb->prepare( "SELECT id FROM $wpdb->mp_mails WHERE status =  'sent' AND DATE( sent ) < %s;", $date ) );
  61  
  62          foreach( $ids as $id ) MP_Mail::delete( $id->id );
  63      }
  64  
  65  // schedule
  66  	public static function schedule()
  67      {
  68          $config = get_option( self::option_name );
  69          $now4cron = current_time( 'timestamp', 'gmt' );
  70  
  71          if ( !wp_next_scheduled( self::process_name ) ) 
  72              wp_schedule_single_event( $now4cron + $config['every'] * DAY_IN_SECONDS, self::process_name );
  73      }
  74  
  75  ////  ADMIN  ////
  76  ////  ADMIN  ////
  77  ////  ADMIN  ////
  78  ////  ADMIN  ////
  79  
  80  // for install
  81  	public static function install() 
  82      {
  83          self::uninstall();
  84  
  85          do_action( 'MailPress_schedule_delete_old_mails' );
  86      }
  87  
  88  	public static function uninstall() 
  89      {
  90          wp_clear_scheduled_hook( self::process_name );
  91      }
  92  
  93  // for link on plugin page
  94  	public static function plugin_action_links( $links, $file )
  95      {
  96          return MailPress::plugin_links( $links, $file, plugin_basename( __FILE__ ), 'batches' );
  97      }
  98  
  99  // for settings
 100  	public static function settings_tab( $tabs )
 101      {
 102          $tabs['batches'] = __( 'Batches', 'MailPress' );
 103          return $tabs;
 104      }
 105  
 106  // for settings batches
 107  	public static function settings_batches_help( $content )
 108      {
 109          include  ( MP_ABSPATH . 'mp-admin/includes/settings/batches/delete_old_mails/help.php' );
 110          return $content;
 111      }
 112  
 113  	public static function settings_batches_update()
 114      {
 115          include  ( MP_ABSPATH . 'mp-admin/includes/settings/batches/delete_old_mails/update.php' );
 116      }
 117  
 118  	public static function settings_batches_form()
 119      {
 120          include  ( MP_ABSPATH . 'mp-admin/includes/settings/batches/delete_old_mails/form.php' );
 121      }
 122  
 123  }
 124  new MailPress_delete_old_mails();
 125  }


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1