Simple Login Log - Version 0.9.2

Version Description

Download this release

Release Info

Developer maxchirkov
Plugin Icon wp plugin Simple Login Log
Version 0.9.2
Comparing to
See all releases

Code changes from version 0.9 to 0.9.2

Files changed (2) hide show
  1. readme.txt +6 -2
  2. simple-login-log.php +50 -14
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: Max Chirkov
3
  Donate link: http://www.ibsteam.net/donate
4
  Tags: login, log, users
5
  Requires at least: 3.0
6
- Tested up to: 3.3
7
- Stable tag: 0.9
8
 
9
  This plugin keeps a log of WordPress user logins. Offers user and date filtering, and export features.
10
 
@@ -40,6 +40,10 @@ Screen Options are available at the top of the Login Log page. Click on the *Sec
40
 
41
  == Changelog ==
42
 
 
 
 
 
43
  **Version 0.9**
44
 
45
  - Changed access to the log for users with capability to "list_users".
3
  Donate link: http://www.ibsteam.net/donate
4
  Tags: login, log, users
5
  Requires at least: 3.0
6
+ Tested up to: 3.3.2
7
+ Stable tag: 0.9.2
8
 
9
  This plugin keeps a log of WordPress user logins. Offers user and date filtering, and export features.
10
 
40
 
41
  == Changelog ==
42
 
43
+ **Version 0.9.2**
44
+
45
+ - Daily cron job with log truncation didn't work.
46
+
47
  **Version 0.9**
48
 
49
  - Changed access to the log for users with capability to "list_users".
simple-login-log.php CHANGED
@@ -4,7 +4,7 @@
4
  Plugin URI: http://simplerealtytheme.com
5
  Description: This plugin keeps a log of WordPress user logins. Offers user filtering and export features.
6
  Author: Max Chirkov
7
- Version: 0.9
8
  Author URI: http://SimpleRealtyTheme.com
9
  */
10
 
@@ -54,7 +54,8 @@ if( !class_exists( 'SimpleLoginLog' ) )
54
  add_action( 'admin_head', array(&$this, 'admin_header') );
55
 
56
  //Initialize scheduled events
57
- add_action( 'wp', array(&$this, 'init_scheduled_events') );
 
58
 
59
  //Load Locale
60
  add_action('init', array(&$this, 'load_locale'), 10 );
@@ -77,6 +78,9 @@ if( !class_exists( 'SimpleLoginLog' ) )
77
  'data' => __('Data', 'sll'),
78
  );
79
 
 
 
 
80
  }
81
 
82
 
@@ -91,6 +95,12 @@ if( !class_exists( 'SimpleLoginLog' ) )
91
  }
92
 
93
 
 
 
 
 
 
 
94
  function screen_options()
95
  {
96
 
@@ -109,7 +119,7 @@ if( !class_exists( 'SimpleLoginLog' ) )
109
  if( isset($_REQUEST['wp_screen_options']) && isset($_REQUEST['wp_screen_options']['value']) )
110
  {
111
  update_option( $per_page_option, esc_html($_REQUEST['wp_screen_options']['value']) );
112
- }
113
 
114
  //prepare options for display
115
 
@@ -156,27 +166,46 @@ if( !class_exists( 'SimpleLoginLog' ) )
156
 
157
 
158
  function init_scheduled_events()
159
- {
160
- if ( $this->opt['log_duration'] && !wp_next_scheduled( 'truncate_log' ) )
161
- {
162
- wp_schedule_event(time(), 'daily', 'truncate_log');
163
- }elseif( !$this->opt['log_duration'] || 0 == $this->opt['log_duration'])
 
 
 
 
164
  {
165
- $timestamp = wp_next_scheduled( 'truncate_log' );
166
- (!$timestamp) ? false : wp_unschedule_event($timestamp, 'truncate_log');
167
 
168
  }
169
  }
170
 
171
 
 
 
 
 
 
 
 
 
 
172
  function truncate_log()
173
  {
174
  global $wpdb;
175
 
176
- if( 0 < (int) $this->opt['log_duration'] ){
177
- $sql = $wpdb->prepare( "DELETE FROM {$this->table} WHERE time < DATE_SUB(CURDATE(),INTERVAL %d DAY)", array($this->opt['log_duration']));
178
- $wpdb->query($sql);
 
 
 
 
 
179
  }
 
180
  }
181
 
182
 
@@ -332,7 +361,13 @@ if( !class_exists( 'SimpleLoginLog' ) )
332
  $duration = (null !== $this->opt['log_duration']) ? $this->opt['log_duration'] : $this->log_duration;
333
  $output = '<input type="text" value="' . $duration . '" name="simple_login_log[log_duration]" size="10" class="code" /> days and older.';
334
  echo $output;
335
- echo "<p>" . __("Leave empty or enter 0 if you don't want the log to be truncated.", 'sll') . "</p>";
 
 
 
 
 
 
336
  }
337
 
338
 
@@ -449,6 +484,7 @@ if( !class_exists( 'SimpleLoginLog' ) )
449
  $where = 'WHERE ' . implode(' AND ', $where);
450
 
451
  $sql = "SELECT * FROM $this->table $where ORDER BY time DESC LIMIT $limit";
 
452
  $data = $wpdb->get_results($sql, 'ARRAY_A');
453
 
454
  return $data;
4
  Plugin URI: http://simplerealtytheme.com
5
  Description: This plugin keeps a log of WordPress user logins. Offers user filtering and export features.
6
  Author: Max Chirkov
7
+ Version: 0.9.2
8
  Author URI: http://SimpleRealtyTheme.com
9
  */
10
 
54
  add_action( 'admin_head', array(&$this, 'admin_header') );
55
 
56
  //Initialize scheduled events
57
+ add_action( 'wp', array(&$this, 'init_scheduled_events') );
58
+ add_action('truncate_sll', array(&$this, 'cron') );
59
 
60
  //Load Locale
61
  add_action('init', array(&$this, 'load_locale'), 10 );
78
  'data' => __('Data', 'sll'),
79
  );
80
 
81
+ //Deactivation hook
82
+ register_deactivation_hook(__FILE__, array(&$this, 'deactivation') );
83
+
84
  }
85
 
86
 
95
  }
96
 
97
 
98
+ function cron()
99
+ {
100
+ SimpleLoginLog::truncate_log();
101
+ }
102
+
103
+
104
  function screen_options()
105
  {
106
 
119
  if( isset($_REQUEST['wp_screen_options']) && isset($_REQUEST['wp_screen_options']['value']) )
120
  {
121
  update_option( $per_page_option, esc_html($_REQUEST['wp_screen_options']['value']) );
122
+ }
123
 
124
  //prepare options for display
125
 
166
 
167
 
168
  function init_scheduled_events()
169
+ {
170
+
171
+ $log_duration = get_option('simple_login_log');
172
+
173
+ if ( $log_duration && !wp_next_scheduled( 'truncate_sll' ) )
174
+ {
175
+ $start = time();
176
+ wp_schedule_event($start, 'daily', 'truncate_sll');
177
+ }elseif( !$log_duration || 0 == $log_duration)
178
  {
179
+ $timestamp = wp_next_scheduled( 'truncate_sll' );
180
+ (!$timestamp) ? false : wp_unschedule_event($timestamp, 'truncate_sll');
181
 
182
  }
183
  }
184
 
185
 
186
+ function deactivation(){
187
+ wp_clear_scheduled_hook('truncate_sll');
188
+
189
+ //clean up old cron jobs that no longer exist
190
+ wp_clear_scheduled_hook('truncate_log');
191
+ wp_clear_scheduled_hook('SimpleLoginLog::truncate_log');
192
+ }
193
+
194
+
195
  function truncate_log()
196
  {
197
  global $wpdb;
198
 
199
+ $opt = get_option('simple_login_log');
200
+ $log_duration = (int)$opt['log_duration'];
201
+
202
+ $table = $wpdb->prefix . 'simple_login_log';
203
+
204
+ if( 0 < $log_duration ){
205
+ $sql = $wpdb->prepare( "DELETE FROM {$table} WHERE time < DATE_SUB(CURDATE(),INTERVAL %d DAY)", $log_duration);
206
+ $wpdb->query($sql);
207
  }
208
+
209
  }
210
 
211
 
361
  $duration = (null !== $this->opt['log_duration']) ? $this->opt['log_duration'] : $this->log_duration;
362
  $output = '<input type="text" value="' . $duration . '" name="simple_login_log[log_duration]" size="10" class="code" /> days and older.';
363
  echo $output;
364
+ echo "<p>" . __("Leave empty or enter 0 if you don't want the log to be truncated.", 'sll') . "</p>";
365
+
366
+ //since we're on the General Settings page - update cron schedule if settings has been updated
367
+ if( isset($_REQUEST['settings-updated']) ){
368
+ wp_clear_scheduled_hook('truncate_sll');
369
+ //$this->init_scheduled_events();
370
+ }
371
  }
372
 
373
 
484
  $where = 'WHERE ' . implode(' AND ', $where);
485
 
486
  $sql = "SELECT * FROM $this->table $where ORDER BY time DESC LIMIT $limit";
487
+ $sql = "SELECT * FROM $this->table $where ORDER BY time DESC";
488
  $data = $wpdb->get_results($sql, 'ARRAY_A');
489
 
490
  return $data;