Version Description
Download this release
Release Info
Developer | maxchirkov |
Plugin | Simple Login Log |
Version | 0.7 |
Comparing to | |
See all releases |
Code changes from version 0.5 to 0.7
- readme.txt +10 -1
- simple-login-log.php +132 -26
readme.txt
CHANGED
@@ -4,7 +4,7 @@ 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.
|
8 |
|
9 |
This plugin keeps a log of WordPress user logins. Offers user and date filtering, and export features.
|
10 |
|
@@ -40,6 +40,15 @@ Screen Options are available at the top of the Login Log page. Click on the *Sec
|
|
40 |
|
41 |
== Changelog ==
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
**Version 0.5**
|
44 |
|
45 |
- Bug fix: in_array() warning for hidden columns not returning an array.
|
4 |
Tags: login, log, users
|
5 |
Requires at least: 3.0
|
6 |
Tested up to: 3.3
|
7 |
+
Stable tag: 0.7
|
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.7**
|
44 |
+
|
45 |
+
- Added user role filter via link. Filter will apply only to newly registered logins, because user roles weren't recorded in versions prior to v.0.6.
|
46 |
+
|
47 |
+
**Version 0.6**
|
48 |
+
|
49 |
+
- Added new column - User Role.
|
50 |
+
- Minor PHP warning notices cleanup.
|
51 |
+
|
52 |
**Version 0.5**
|
53 |
|
54 |
- Bug fix: in_array() warning for hidden columns not returning an array.
|
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.
|
8 |
Author URI: http://SimpleRealtyTheme.com
|
9 |
*/
|
10 |
|
@@ -13,13 +13,14 @@
|
|
13 |
if( !class_exists( 'SimpleLoginLog' ) )
|
14 |
{
|
15 |
class SimpleLoginLog {
|
16 |
-
private $db_ver = "1.
|
17 |
public $table = 'simple_login_log';
|
18 |
private $log_duration = null; //days
|
19 |
private $opt_name = 'simple_login_log';
|
20 |
private $opt = false;
|
21 |
private $login_success = 1;
|
22 |
public $data_labels = array();
|
|
|
23 |
|
24 |
function __construct()
|
25 |
{
|
@@ -68,6 +69,7 @@ if( !class_exists( 'SimpleLoginLog' ) )
|
|
68 |
'id' => __('#', 'sll'),
|
69 |
'uid' => __('User ID', 'sll'),
|
70 |
'user_login' => __('Username', 'sll'),
|
|
|
71 |
'name' => __('Name', 'sll'),
|
72 |
'time' => __('Time', 'sll'),
|
73 |
'ip' => __('IP Address', 'sll'),
|
@@ -77,7 +79,9 @@ if( !class_exists( 'SimpleLoginLog' ) )
|
|
77 |
|
78 |
}
|
79 |
|
80 |
-
|
|
|
|
|
81 |
$locale = get_locale();
|
82 |
if( empty( $locale ) )
|
83 |
$locale = 'en_US';
|
@@ -86,7 +90,9 @@ if( !class_exists( 'SimpleLoginLog' ) )
|
|
86 |
load_textdomain( 'sll', $mofile );
|
87 |
}
|
88 |
|
89 |
-
|
|
|
|
|
90 |
|
91 |
//execute only on login_log page, othewise return null
|
92 |
$page = ( isset($_GET['page']) ) ? esc_attr($_GET['page']) : false;
|
@@ -119,7 +125,9 @@ if( !class_exists( 'SimpleLoginLog' ) )
|
|
119 |
$_wp_column_headers[ $current_screen->id ] = SLL_List_Table::get_columns();
|
120 |
}
|
121 |
|
122 |
-
|
|
|
|
|
123 |
//condition to check if "log failed attemts" option is selected
|
124 |
|
125 |
//Action on successfull login
|
@@ -132,16 +140,21 @@ if( !class_exists( 'SimpleLoginLog' ) )
|
|
132 |
|
133 |
}
|
134 |
|
135 |
-
|
|
|
|
|
136 |
$this->login_success = 1;
|
137 |
$this->login_action( $user_login );
|
138 |
}
|
139 |
|
140 |
-
|
|
|
|
|
141 |
$this->login_success = 0;
|
142 |
$this->login_action( $user_login );
|
143 |
}
|
144 |
|
|
|
145 |
function init_scheduled_events()
|
146 |
{
|
147 |
if ( $this->opt['log_duration'] && !wp_next_scheduled( 'truncate_log' ) )
|
@@ -155,6 +168,7 @@ if( !class_exists( 'SimpleLoginLog' ) )
|
|
155 |
}
|
156 |
}
|
157 |
|
|
|
158 |
function truncate_log()
|
159 |
{
|
160 |
global $wpdb;
|
@@ -182,6 +196,7 @@ if( !class_exists( 'SimpleLoginLog' ) )
|
|
182 |
id INT( 11 ) NOT NULL AUTO_INCREMENT ,
|
183 |
uid INT( 11 ) NOT NULL ,
|
184 |
user_login VARCHAR( 60 ) NOT NULL ,
|
|
|
185 |
time DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL ,
|
186 |
ip VARCHAR( 100 ) NOT NULL ,
|
187 |
login_result VARCHAR (1) ,
|
@@ -205,7 +220,8 @@ if( !class_exists( 'SimpleLoginLog' ) )
|
|
205 |
* Checks if the installed database version is the same as the db version of the current plugin
|
206 |
* calles the version specific function if upgrade is required
|
207 |
*/
|
208 |
-
function update_db_check()
|
|
|
209 |
if ( get_site_option( 'sll_db_ver' ) != $this->db_ver )
|
210 |
{
|
211 |
switch( $this->db_ver )
|
@@ -213,10 +229,14 @@ if( !class_exists( 'SimpleLoginLog' ) )
|
|
213 |
case "1.1":
|
214 |
$this->db_update_1_1();
|
215 |
break;
|
|
|
|
|
|
|
216 |
}
|
217 |
}
|
218 |
}
|
219 |
|
|
|
220 |
/**
|
221 |
* DB version specific updates
|
222 |
*/
|
@@ -251,6 +271,37 @@ if( !class_exists( 'SimpleLoginLog' ) )
|
|
251 |
}
|
252 |
|
253 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
|
255 |
|
256 |
//Initializing Settings
|
@@ -263,16 +314,19 @@ if( !class_exists( 'SimpleLoginLog' ) )
|
|
263 |
|
264 |
}
|
265 |
|
|
|
266 |
function sll_admin_menu()
|
267 |
{
|
268 |
add_submenu_page( 'users.php', __('Simple Login Log', 'sll'), __('Login Log', 'sll'), 'edit_users', 'login_log', array(&$this, 'log_manager') );
|
269 |
}
|
270 |
|
|
|
271 |
function sll_settings()
|
272 |
{
|
273 |
//content that goes before the fields output
|
274 |
}
|
275 |
|
|
|
276 |
function field_log_duration()
|
277 |
{
|
278 |
$duration = (null !== $this->opt['log_duration']) ? $this->opt['log_duration'] : $this->log_duration;
|
@@ -281,11 +335,14 @@ if( !class_exists( 'SimpleLoginLog' ) )
|
|
281 |
echo "<p>" . __("Leave empty or enter 0 if you don't want the log to be truncated.", 'sll') . "</p>";
|
282 |
}
|
283 |
|
284 |
-
|
|
|
|
|
285 |
$failed_attempts = ( isset($this->opt['failed_attempts']) ) ? $this->opt['failed_attempts'] : false;
|
286 |
echo '<input type="checkbox" name="simple_login_log[failed_attempts]" value="1" ' . checked( $failed_attempts, 1, false ) . ' /> ' . __('Logs failed attempts where user name and password are entered. Will not log if at least one of the mentioned fields is empty.', 'sll');
|
287 |
}
|
288 |
|
|
|
289 |
function admin_header()
|
290 |
{
|
291 |
$page = ( isset($_GET['page']) ) ? esc_attr($_GET['page']) : false;
|
@@ -304,45 +361,66 @@ if( !class_exists( 'SimpleLoginLog' ) )
|
|
304 |
echo '</style>';
|
305 |
}
|
306 |
|
|
|
307 |
//Catch messages on successful login
|
308 |
-
function login_action($user_login)
|
|
|
309 |
|
310 |
$userdata = get_user_by('login', $user_login);
|
311 |
|
312 |
-
$uid = ($userdata->ID) ? $userdata->ID : 0;
|
313 |
|
314 |
$data[$this->data_labels['Login']] = ( 1 == $this->login_success ) ? $this->data_labels['Successful'] : $this->data_labels['Failed'];
|
315 |
if ( isset( $_REQUEST['redirect_to'] ) ) { $data[$this->data_labels['Login Redirect']] = $_REQUEST['redirect_to']; }
|
316 |
$data[$this->data_labels['User Agent']] = $_SERVER['HTTP_USER_AGENT'];
|
317 |
|
318 |
$serialized_data = serialize($data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
319 |
|
320 |
$values = array(
|
321 |
'uid' => $uid,
|
322 |
-
'user_login' => $user_login,
|
|
|
323 |
'time' => current_time('mysql'),
|
324 |
'ip' => $_SERVER['REMOTE_ADDR'],
|
325 |
'login_result' => $this->login_success,
|
326 |
'data' => $serialized_data,
|
327 |
);
|
328 |
|
329 |
-
$format = array('%d', '%s', '%s', '%s', '%s', '%s');
|
330 |
|
331 |
$this->save_data($values, $format);
|
332 |
}
|
333 |
|
334 |
-
|
|
|
|
|
335 |
global $wpdb;
|
336 |
|
337 |
$wpdb->insert( $this->table, $values, $format );
|
338 |
}
|
339 |
|
340 |
-
|
|
|
|
|
341 |
$where = false;
|
342 |
if( isset($_GET['filter']) && '' != $_GET['filter'] )
|
343 |
{
|
344 |
$where['filter'] = "user_login = '{$_GET['filter']}'";
|
345 |
}
|
|
|
|
|
|
|
|
|
346 |
if( isset($_GET['result']) && '' != $_GET['result'] )
|
347 |
{
|
348 |
$where['result'] = "login_result = '{$_GET['result']}'";
|
@@ -357,7 +435,9 @@ if( !class_exists( 'SimpleLoginLog' ) )
|
|
357 |
return $where;
|
358 |
}
|
359 |
|
360 |
-
|
|
|
|
|
361 |
global $wpdb;
|
362 |
|
363 |
$limit = 20;
|
@@ -374,6 +454,7 @@ if( !class_exists( 'SimpleLoginLog' ) )
|
|
374 |
return $data;
|
375 |
}
|
376 |
|
|
|
377 |
function log_manager()
|
378 |
{
|
379 |
|
@@ -435,7 +516,8 @@ if( !class_exists( 'SimpleLoginLog' ) )
|
|
435 |
echo '</div>';
|
436 |
}
|
437 |
|
438 |
-
|
|
|
439 |
{
|
440 |
global $wpdb;
|
441 |
$sql = "SELECT DISTINCT YEAR(time) as year, MONTH(time)as month FROM {$this->table} ORDER BY YEAR(time), MONTH(time) desc";
|
@@ -463,6 +545,7 @@ if( !class_exists( 'SimpleLoginLog' ) )
|
|
463 |
return $output;
|
464 |
}
|
465 |
|
|
|
466 |
function export_to_CSV($where = false){
|
467 |
global $wpdb;
|
468 |
|
@@ -508,6 +591,7 @@ if( !class_exists( 'SimpleLoginLog' ) )
|
|
508 |
}
|
509 |
|
510 |
}
|
|
|
511 |
}
|
512 |
|
513 |
if( class_exists( 'SimpleLoginLog' ) )
|
@@ -518,9 +602,11 @@ if( class_exists( 'SimpleLoginLog' ) )
|
|
518 |
|
519 |
}
|
520 |
|
521 |
-
if(!class_exists('WP_List_Table'))
|
|
|
522 |
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
523 |
}
|
|
|
524 |
class SLL_List_Table extends WP_List_Table
|
525 |
{
|
526 |
function __construct()
|
@@ -536,22 +622,25 @@ class SLL_List_Table extends WP_List_Table
|
|
536 |
|
537 |
$this->data_labels = $sll->data_labels;
|
538 |
|
539 |
-
}
|
|
|
540 |
|
541 |
function column_default($item, $column_name)
|
542 |
{
|
543 |
$item = apply_filters('sll-output-data', $item);
|
|
|
|
|
|
|
|
|
|
|
|
|
544 |
switch($column_name){
|
545 |
case 'id':
|
546 |
case 'uid':
|
547 |
case 'time':
|
548 |
case 'ip':
|
549 |
return $item[$column_name];
|
550 |
-
case 'user_login':
|
551 |
-
//unset existing filter and pagination
|
552 |
-
$args = wp_parse_args( parse_url($_SERVER["REQUEST_URI"], PHP_URL_QUERY) );
|
553 |
-
unset($args['filter']);
|
554 |
-
unset($args['paged']);
|
555 |
return "<a href='" . add_query_arg( array('filter' => $item[$column_name]), menu_page_url('login_log', false) ) . "' title='" . __('Filter log by this name', 'sll') . "'>{$item[$column_name]}</a>";
|
556 |
case 'name';
|
557 |
$user_info = get_userdata($item['uid']);
|
@@ -559,6 +648,18 @@ class SLL_List_Table extends WP_List_Table
|
|
559 |
case 'login_result':
|
560 |
if ( '' == $item[$column_name]) return '';
|
561 |
return ( '1' == $item[$column_name] ) ? $this->data_labels['Successful'] : '<div class="login-failed">' . $this->data_labels['Failed'] . '</div>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
562 |
case 'data':
|
563 |
$data = unserialize($item[$column_name]);
|
564 |
if(is_array($data))
|
@@ -582,6 +683,7 @@ class SLL_List_Table extends WP_List_Table
|
|
582 |
}
|
583 |
}
|
584 |
|
|
|
585 |
function get_columns()
|
586 |
{
|
587 |
global $status;
|
@@ -589,8 +691,9 @@ class SLL_List_Table extends WP_List_Table
|
|
589 |
'id' => $this->data_labels['id'],
|
590 |
'uid' => $this->data_labels['uid'],
|
591 |
'user_login' => $this->data_labels['user_login'],
|
|
|
592 |
'name' => $this->data_labels['name'],
|
593 |
-
'time' => $this->data_labels['time'],
|
594 |
'ip' => $this->data_labels['ip'],
|
595 |
'login_result' => $this->data_labels['login_result'],
|
596 |
'data' => $this->data_labels['data'],
|
@@ -598,6 +701,7 @@ class SLL_List_Table extends WP_List_Table
|
|
598 |
return $columns;
|
599 |
}
|
600 |
|
|
|
601 |
function get_sortable_columns()
|
602 |
{
|
603 |
$sortable_columns = array(
|
@@ -610,6 +714,7 @@ class SLL_List_Table extends WP_List_Table
|
|
610 |
return $sortable_columns;
|
611 |
}
|
612 |
|
|
|
613 |
function get_views()
|
614 |
{
|
615 |
//creating class="current" variables
|
@@ -684,6 +789,7 @@ class SLL_List_Table extends WP_List_Table
|
|
684 |
|
685 |
return $views;
|
686 |
}
|
|
|
687 |
|
688 |
function prepare_items()
|
689 |
{
|
@@ -807,4 +913,4 @@ class SLL_List_Table extends WP_List_Table
|
|
807 |
|
808 |
}
|
809 |
|
810 |
-
}
|
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.7
|
8 |
Author URI: http://SimpleRealtyTheme.com
|
9 |
*/
|
10 |
|
13 |
if( !class_exists( 'SimpleLoginLog' ) )
|
14 |
{
|
15 |
class SimpleLoginLog {
|
16 |
+
private $db_ver = "1.2";
|
17 |
public $table = 'simple_login_log';
|
18 |
private $log_duration = null; //days
|
19 |
private $opt_name = 'simple_login_log';
|
20 |
private $opt = false;
|
21 |
private $login_success = 1;
|
22 |
public $data_labels = array();
|
23 |
+
|
24 |
|
25 |
function __construct()
|
26 |
{
|
69 |
'id' => __('#', 'sll'),
|
70 |
'uid' => __('User ID', 'sll'),
|
71 |
'user_login' => __('Username', 'sll'),
|
72 |
+
'user_role' => __('User Role', 'sll'),
|
73 |
'name' => __('Name', 'sll'),
|
74 |
'time' => __('Time', 'sll'),
|
75 |
'ip' => __('IP Address', 'sll'),
|
79 |
|
80 |
}
|
81 |
|
82 |
+
|
83 |
+
function load_locale()
|
84 |
+
{
|
85 |
$locale = get_locale();
|
86 |
if( empty( $locale ) )
|
87 |
$locale = 'en_US';
|
90 |
load_textdomain( 'sll', $mofile );
|
91 |
}
|
92 |
|
93 |
+
|
94 |
+
function screen_options()
|
95 |
+
{
|
96 |
|
97 |
//execute only on login_log page, othewise return null
|
98 |
$page = ( isset($_GET['page']) ) ? esc_attr($_GET['page']) : false;
|
125 |
$_wp_column_headers[ $current_screen->id ] = SLL_List_Table::get_columns();
|
126 |
}
|
127 |
|
128 |
+
|
129 |
+
function init_login_actions()
|
130 |
+
{
|
131 |
//condition to check if "log failed attemts" option is selected
|
132 |
|
133 |
//Action on successfull login
|
140 |
|
141 |
}
|
142 |
|
143 |
+
|
144 |
+
function login_success( $user_login )
|
145 |
+
{
|
146 |
$this->login_success = 1;
|
147 |
$this->login_action( $user_login );
|
148 |
}
|
149 |
|
150 |
+
|
151 |
+
function login_failed( $user_login )
|
152 |
+
{
|
153 |
$this->login_success = 0;
|
154 |
$this->login_action( $user_login );
|
155 |
}
|
156 |
|
157 |
+
|
158 |
function init_scheduled_events()
|
159 |
{
|
160 |
if ( $this->opt['log_duration'] && !wp_next_scheduled( 'truncate_log' ) )
|
168 |
}
|
169 |
}
|
170 |
|
171 |
+
|
172 |
function truncate_log()
|
173 |
{
|
174 |
global $wpdb;
|
196 |
id INT( 11 ) NOT NULL AUTO_INCREMENT ,
|
197 |
uid INT( 11 ) NOT NULL ,
|
198 |
user_login VARCHAR( 60 ) NOT NULL ,
|
199 |
+
user_role VARCHAR( 30 ) NOT NULL ,
|
200 |
time DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL ,
|
201 |
ip VARCHAR( 100 ) NOT NULL ,
|
202 |
login_result VARCHAR (1) ,
|
220 |
* Checks if the installed database version is the same as the db version of the current plugin
|
221 |
* calles the version specific function if upgrade is required
|
222 |
*/
|
223 |
+
function update_db_check()
|
224 |
+
{
|
225 |
if ( get_site_option( 'sll_db_ver' ) != $this->db_ver )
|
226 |
{
|
227 |
switch( $this->db_ver )
|
229 |
case "1.1":
|
230 |
$this->db_update_1_1();
|
231 |
break;
|
232 |
+
case "1.2":
|
233 |
+
$this->db_update_1_2();
|
234 |
+
break;
|
235 |
}
|
236 |
}
|
237 |
}
|
238 |
|
239 |
+
|
240 |
/**
|
241 |
* DB version specific updates
|
242 |
*/
|
271 |
}
|
272 |
|
273 |
}
|
274 |
+
|
275 |
+
|
276 |
+
function db_update_1_2()
|
277 |
+
{
|
278 |
+
/* this version adds a new field "user_role"
|
279 |
+
* check if this field exists
|
280 |
+
*/
|
281 |
+
global $wpdb;
|
282 |
+
|
283 |
+
$sql = "SELECT * FROM {$this->table}";
|
284 |
+
$fields = $wpdb->get_row($sql, 'ARRAY_A');
|
285 |
+
|
286 |
+
if( !$fields ){
|
287 |
+
$this->install();
|
288 |
+
return;
|
289 |
+
}
|
290 |
+
|
291 |
+
$field_names = array_keys( $fields );
|
292 |
+
|
293 |
+
if( !array_search('user_role', $field_names) )
|
294 |
+
{
|
295 |
+
//add the new field since it doesn't exist
|
296 |
+
$sql = "ALTER TABLE {$this->table} ADD COLUMN user_role varchar(30) NOT NULL AFTER user_login;";
|
297 |
+
$insert = $wpdb->query( $sql );
|
298 |
+
|
299 |
+
//update version record if it has been updated
|
300 |
+
if( false !== $insert )
|
301 |
+
update_option( "sll_db_ver", $this->db_ver );
|
302 |
+
|
303 |
+
}
|
304 |
+
}
|
305 |
|
306 |
|
307 |
//Initializing Settings
|
314 |
|
315 |
}
|
316 |
|
317 |
+
|
318 |
function sll_admin_menu()
|
319 |
{
|
320 |
add_submenu_page( 'users.php', __('Simple Login Log', 'sll'), __('Login Log', 'sll'), 'edit_users', 'login_log', array(&$this, 'log_manager') );
|
321 |
}
|
322 |
|
323 |
+
|
324 |
function sll_settings()
|
325 |
{
|
326 |
//content that goes before the fields output
|
327 |
}
|
328 |
|
329 |
+
|
330 |
function field_log_duration()
|
331 |
{
|
332 |
$duration = (null !== $this->opt['log_duration']) ? $this->opt['log_duration'] : $this->log_duration;
|
335 |
echo "<p>" . __("Leave empty or enter 0 if you don't want the log to be truncated.", 'sll') . "</p>";
|
336 |
}
|
337 |
|
338 |
+
|
339 |
+
function field_log_failed_attempts()
|
340 |
+
{
|
341 |
$failed_attempts = ( isset($this->opt['failed_attempts']) ) ? $this->opt['failed_attempts'] : false;
|
342 |
echo '<input type="checkbox" name="simple_login_log[failed_attempts]" value="1" ' . checked( $failed_attempts, 1, false ) . ' /> ' . __('Logs failed attempts where user name and password are entered. Will not log if at least one of the mentioned fields is empty.', 'sll');
|
343 |
}
|
344 |
|
345 |
+
|
346 |
function admin_header()
|
347 |
{
|
348 |
$page = ( isset($_GET['page']) ) ? esc_attr($_GET['page']) : false;
|
361 |
echo '</style>';
|
362 |
}
|
363 |
|
364 |
+
|
365 |
//Catch messages on successful login
|
366 |
+
function login_action($user_login)
|
367 |
+
{
|
368 |
|
369 |
$userdata = get_user_by('login', $user_login);
|
370 |
|
371 |
+
$uid = ($userdata && $userdata->ID) ? $userdata->ID : 0;
|
372 |
|
373 |
$data[$this->data_labels['Login']] = ( 1 == $this->login_success ) ? $this->data_labels['Successful'] : $this->data_labels['Failed'];
|
374 |
if ( isset( $_REQUEST['redirect_to'] ) ) { $data[$this->data_labels['Login Redirect']] = $_REQUEST['redirect_to']; }
|
375 |
$data[$this->data_labels['User Agent']] = $_SERVER['HTTP_USER_AGENT'];
|
376 |
|
377 |
$serialized_data = serialize($data);
|
378 |
+
|
379 |
+
//get user role
|
380 |
+
$user_role = '';
|
381 |
+
if( $uid ){
|
382 |
+
$user = new WP_User( $uid );
|
383 |
+
if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
|
384 |
+
$user_role = implode(', ', $user->roles);
|
385 |
+
}
|
386 |
+
}
|
387 |
+
|
388 |
|
389 |
$values = array(
|
390 |
'uid' => $uid,
|
391 |
+
'user_login' => $user_login,
|
392 |
+
'user_role' => $user_role,
|
393 |
'time' => current_time('mysql'),
|
394 |
'ip' => $_SERVER['REMOTE_ADDR'],
|
395 |
'login_result' => $this->login_success,
|
396 |
'data' => $serialized_data,
|
397 |
);
|
398 |
|
399 |
+
$format = array('%d', '%s', '%s', '%s', '%s', '%s', '%s');
|
400 |
|
401 |
$this->save_data($values, $format);
|
402 |
}
|
403 |
|
404 |
+
|
405 |
+
function save_data($values, $format)
|
406 |
+
{
|
407 |
global $wpdb;
|
408 |
|
409 |
$wpdb->insert( $this->table, $values, $format );
|
410 |
}
|
411 |
|
412 |
+
|
413 |
+
function make_where_query()
|
414 |
+
{
|
415 |
$where = false;
|
416 |
if( isset($_GET['filter']) && '' != $_GET['filter'] )
|
417 |
{
|
418 |
$where['filter'] = "user_login = '{$_GET['filter']}'";
|
419 |
}
|
420 |
+
if( isset($_GET['user_role']) && '' != $_GET['user_role'] )
|
421 |
+
{
|
422 |
+
$where['user_role'] = "user_role = '{$_GET['user_role']}'";
|
423 |
+
}
|
424 |
if( isset($_GET['result']) && '' != $_GET['result'] )
|
425 |
{
|
426 |
$where['result'] = "login_result = '{$_GET['result']}'";
|
435 |
return $where;
|
436 |
}
|
437 |
|
438 |
+
|
439 |
+
function log_get_data()
|
440 |
+
{
|
441 |
global $wpdb;
|
442 |
|
443 |
$limit = 20;
|
454 |
return $data;
|
455 |
}
|
456 |
|
457 |
+
|
458 |
function log_manager()
|
459 |
{
|
460 |
|
516 |
echo '</div>';
|
517 |
}
|
518 |
|
519 |
+
|
520 |
+
function date_filter()
|
521 |
{
|
522 |
global $wpdb;
|
523 |
$sql = "SELECT DISTINCT YEAR(time) as year, MONTH(time)as month FROM {$this->table} ORDER BY YEAR(time), MONTH(time) desc";
|
545 |
return $output;
|
546 |
}
|
547 |
|
548 |
+
|
549 |
function export_to_CSV($where = false){
|
550 |
global $wpdb;
|
551 |
|
591 |
}
|
592 |
|
593 |
}
|
594 |
+
|
595 |
}
|
596 |
|
597 |
if( class_exists( 'SimpleLoginLog' ) )
|
602 |
|
603 |
}
|
604 |
|
605 |
+
if(!class_exists('WP_List_Table'))
|
606 |
+
{
|
607 |
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
608 |
}
|
609 |
+
|
610 |
class SLL_List_Table extends WP_List_Table
|
611 |
{
|
612 |
function __construct()
|
622 |
|
623 |
$this->data_labels = $sll->data_labels;
|
624 |
|
625 |
+
}
|
626 |
+
|
627 |
|
628 |
function column_default($item, $column_name)
|
629 |
{
|
630 |
$item = apply_filters('sll-output-data', $item);
|
631 |
+
|
632 |
+
//unset existing filter and pagination
|
633 |
+
$args = wp_parse_args( parse_url($_SERVER["REQUEST_URI"], PHP_URL_QUERY) );
|
634 |
+
unset($args['filter']);
|
635 |
+
unset($args['paged']);
|
636 |
+
|
637 |
switch($column_name){
|
638 |
case 'id':
|
639 |
case 'uid':
|
640 |
case 'time':
|
641 |
case 'ip':
|
642 |
return $item[$column_name];
|
643 |
+
case 'user_login':
|
|
|
|
|
|
|
|
|
644 |
return "<a href='" . add_query_arg( array('filter' => $item[$column_name]), menu_page_url('login_log', false) ) . "' title='" . __('Filter log by this name', 'sll') . "'>{$item[$column_name]}</a>";
|
645 |
case 'name';
|
646 |
$user_info = get_userdata($item['uid']);
|
648 |
case 'login_result':
|
649 |
if ( '' == $item[$column_name]) return '';
|
650 |
return ( '1' == $item[$column_name] ) ? $this->data_labels['Successful'] : '<div class="login-failed">' . $this->data_labels['Failed'] . '</div>';
|
651 |
+
case 'user_role':
|
652 |
+
if( !$item['uid'] )
|
653 |
+
return;
|
654 |
+
|
655 |
+
$user = new WP_User( $item['uid'] );
|
656 |
+
if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
|
657 |
+
foreach($user->roles as $role){
|
658 |
+
$roles[] = "<a href='" . add_query_arg( array('user_role' => $role), menu_page_url('login_log', false) ) . "' title='" . __('Filter log by User Role', 'sll') . "'>{$role}</a>";
|
659 |
+
}
|
660 |
+
return implode(', ', $roles);
|
661 |
+
}
|
662 |
+
break;
|
663 |
case 'data':
|
664 |
$data = unserialize($item[$column_name]);
|
665 |
if(is_array($data))
|
683 |
}
|
684 |
}
|
685 |
|
686 |
+
|
687 |
function get_columns()
|
688 |
{
|
689 |
global $status;
|
691 |
'id' => $this->data_labels['id'],
|
692 |
'uid' => $this->data_labels['uid'],
|
693 |
'user_login' => $this->data_labels['user_login'],
|
694 |
+
'user_role' => $this->data_labels['user_role'],
|
695 |
'name' => $this->data_labels['name'],
|
696 |
+
'time' => $this->data_labels['time'],
|
697 |
'ip' => $this->data_labels['ip'],
|
698 |
'login_result' => $this->data_labels['login_result'],
|
699 |
'data' => $this->data_labels['data'],
|
701 |
return $columns;
|
702 |
}
|
703 |
|
704 |
+
|
705 |
function get_sortable_columns()
|
706 |
{
|
707 |
$sortable_columns = array(
|
714 |
return $sortable_columns;
|
715 |
}
|
716 |
|
717 |
+
|
718 |
function get_views()
|
719 |
{
|
720 |
//creating class="current" variables
|
789 |
|
790 |
return $views;
|
791 |
}
|
792 |
+
|
793 |
|
794 |
function prepare_items()
|
795 |
{
|
913 |
|
914 |
}
|
915 |
|
916 |
+
}
|