PluginProbe
When Last Login / 1.1
When Last Login v1.1
trunk 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.2.1 1.2.2 1.2.3
when-last-login / when-last-login.php

when-last-login.php in When Last Login 1.1, at when-last-login.php

713 lines 26.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: When Last Login
4 Plugin URI: https://wordpress.org/plugins/when-last-login/
5 Description: See when a user logs into your WordPress site.
6 Version: 1.1
7 Author: Yoohoo Plugins
8 Author URI: https://yoohooplugins.com
9 Text Domain: when-last-login
10 Domain Path: /languages
11 */
12
13 use geertw\IpAnonymizer\IpAnonymizer;
14
15 class When_Last_Login {
16
17 /** Refers to a single instance of this class. */
18 private static $instance = null;
19
20 /**
21 * Initializes the plugin by setting localization, filters, and administration functions.
22 */
23 private function __construct() {
24
25 define( 'WLL_BASENAME', plugin_basename( __FILE__ ) );
26 define( 'WLL_DIR_PATH', plugin_dir_path( __FILE__ ) );
27 define( 'WLL_PLUGIN', WP_PLUGIN_URL . '/when-last-login' );
28
29 $settings = get_option( 'wll_settings' );
30
31 include WLL_DIR_PATH . '/includes/lib/IpAnonymizer.php';
32 include WLL_DIR_PATH . '/includes/privacy-policy.php';
33
34 add_action( 'admin_init', array( $this, 'admin_init' ) );
35 add_action( 'plugins_loaded', array( $this, 'text_domain' ) );
36 add_action( 'admin_enqueue_scripts', array( $this, 'load_js_for_notice' ) );
37
38 //Create the custom meta upon login
39 add_action( 'wp_login', array( $this, 'last_login'), 10, 2 );
40 add_action( 'user_register', array( $this, 'wll_user_register' ), 10, 1 );
41
42 //Admin actions
43 add_action( 'wp_dashboard_setup', array( $this, 'admin_dashboard_widget' ) );
44 add_action( 'admin_notices', array( $this, 'update_notice' ) );
45
46 add_action( 'wp_ajax_wll_hide_subscription_notice', array( $this, 'wll_hide_subscription_notice' ) );
47 add_action( 'wp_ajax_wll_subscribe_user_newsletter', array( $this, 'wll_subscribe_user_newsletter_callback' ) );
48
49
50 //Setting up columns.
51 add_filter( 'manage_users_columns', array( $this, 'column_header'), 10, 1 );
52 add_action( 'manage_users_custom_column', array( $this, 'column_data'), 15, 3 );
53 add_filter( 'manage_users_sortable_columns', array( $this, 'column_sortable' ) );
54 add_action( 'pre_get_users', array( $this, 'sort_by_login_date') );
55
56 //Integration for Paid Memberships Pro
57 //TODO: Improve integration with Member List and Paid Memberships Pro
58 add_action( 'pmpro_memberslist_extra_cols_header', array( $this, 'pmpro_memberlist_add_header' ) );
59 add_action( 'pmpro_memberslist_extra_cols_body', array( $this, 'pmpro_memberlist_add_column_data' ) );
60 add_action( 'init', array( $this, 'login_record_cp' ) );
61
62 add_action( 'admin_menu', array( $this, 'wll_settings_page' ), 9 );
63 add_action( 'admin_head', array( $this, 'wll_settings_page_head' ) );
64 add_action( 'admin_init', array( $this, 'wll_automatically_remove_logs' ) );
65
66 add_filter( 'plugin_row_meta', array( $this, 'wll_plugin_row_meta' ), 10, 2 );
67 add_filter( 'plugin_action_links_' . WLL_BASENAME, array( $this, 'wll_plugin_action_links' ), 10, 2 );
68
69 add_filter( 'manage_wll_records_posts_columns' , array( $this, 'wll_records_columns'), 10, 1 );
70 add_action( 'manage_wll_records_posts_custom_column' , array( $this, 'wll_records_column_contents' ), 10, 2 );
71
72 /**
73 * Multisite support
74 */
75 add_action( 'wp_network_dashboard_setup', array( $this, 'admin_dashboard_widget' ) );
76 add_filter( 'wpmu_users_columns', array( $this, 'column_header'), 10, 1 );
77 add_action( 'wpmu_users_custom_column', array( $this, 'column_data'), 15, 3 );
78 }
79
80 /**
81 * Creates or returns an instance of this class.
82 *
83 * @return When_Last_Login A single instance of this class.
84 */
85 public static function get_instance() {
86 if ( null == self::$instance ) {
87 self::$instance = new self;
88 }
89 return self::$instance;
90 } // end get_instance;
91
92 /**
93 * When Last plugin functions.
94 */
95 public static function admin_init(){
96 //init function
97 if ( ! current_user_can( 'manage_options' ) ) {
98 return;
99 }
100
101 do_action( 'wll_upgrade_check' );
102
103 $current_version = floatval( get_option( 'wll_current_version' ) );
104
105 // Clean up stuff for version 1.0
106 if( $current_version < 1.0 || empty( $current_version ) ) {
107
108 global $wpdb;
109
110 $delete_table = $wpdb->prefix . 'wll_login_attempts' ;
111 $sql = "DROP TABLE IF EXISTS `$delete_table`";
112 $wpdb->query( $sql );
113
114 delete_transient( 'when_last_login_add_ons_page' );
115
116 // on upgrade remove the notice save.
117 delete_option( 'wll_notice_hide' );
118 delete_option( 'wll_notice_hide_1' );
119 delete_option( 'wll_notice_hide_2' );
120
121 // update version number to 1.0
122 update_option( 'wll_current_version', 1.0 );
123 }
124 }
125
126 public static function text_domain(){
127 load_plugin_textdomain( 'when-last-login', false, dirname( 'WLL_BASE_NAME' ) . '/languages' );
128 }
129
130 public static function update_notice(){
131
132 if( get_option( 'wll_notice_hide' ) != '1' ){
133 ?>
134 <div class="notice notice-success wll-update-notice-newsletter is-dismissible" >
135 <h3><?php _e('When Last Login', 'when-last-login'); ?></h3>
136 <p><?php _e( 'Sign up for our newsletter to get the latest product news and promotions, plus get 20% off of your next add-on purchase!', 'when-last-login' ); ?> <?php printf( __('Browse through our add-ons %s', 'when-last-login'), '<a href="'.admin_url( '?page=when-last-login-settings&tab=add-ons' ) .'">'.__('here', 'when-last-login').'</a>' ); ?></p>
137 <p><input type='email' style='width: 250px;' name='wll_user_subscribe_to_newsletter' id='wll_user_subscribe_to_newsletter' value='<?php echo get_option('admin_email'); ?>' /><button class='button button-primary' id='wll_subscribe_user'><?php _e('Subscribe Me!', 'when-last-login'); ?></button></p>
138 </div>
139 <?php
140 }
141 }
142
143 public function wll_hide_subscription_notice(){
144 update_option( 'wll_notice_hide', '1' );
145 }
146
147 public function wll_subscribe_user_newsletter_callback(){
148
149 if( isset( $_POST['action'] ) && $_POST['action'] == 'wll_subscribe_user_newsletter' ){
150
151 if( isset( $_POST['email'] ) && $_POST['email'] != "" ){
152
153 $request = wp_remote_post( 'https://yoohooplugins.com/api/mailing_list/subscribe.php', array( 'body' => array( 'action' => 'subscribe_newsletter', 'email' => $_POST['email'] ) ) );
154
155 if( !is_wp_error( $request ) ){
156 $request_body = wp_remote_retrieve_body( $request );
157
158 if( $request_body == 'subscribed' ){
159 echo '1';
160 update_option( 'wll_notice_hide', '1' );
161 }
162
163 } else {
164
165 }
166
167 } else {
168
169 _e( 'Please enter in an email address to subscribe to our mailing list and receive your coupon', 'when-last-login' );
170
171 }
172
173 }
174
175 wp_die();
176
177 }
178
179 public static function load_js_for_notice(){
180 if( get_option( 'wll_notice_hide' ) !== '1'){
181 wp_enqueue_script( 'wll_notice_update', plugins_url( 'js/notice-update.js', __FILE__ ), array( 'jquery' ), '1.0', false );
182 }
183 if( isset( $_GET['page'] ) && $_GET['page'] == 'when-last-login-settings' ){
184 wp_enqueue_style( 'wll_admin_settings_styles', plugins_url( '/css/admin.css', __FILE__ ) );
185 }
186 }
187
188 public static function last_login( $user_login, $users ){
189
190 global $show_login_records;
191
192 //get/update user meta 'when_last_login' on login and add time() to it.
193 update_user_meta( $users->ID, 'when_last_login', time() );
194
195 //get and update user meta 'when_last_login_count' on login for # of login counts. Thanks to Jarryd Long (@jarrydlong) from Code Cabin (@code_cabin) for the assistance
196 $wll_count = get_user_meta( $users->ID, 'when_last_login_count', true );
197
198 if( $wll_count === false ){
199 update_user_meta($users->ID, 'when_last_login_count', 1);
200 } else {
201 $wll_new_value = intval($wll_count);
202 $wll_new_value = $wll_new_value + 1;
203
204 update_user_meta($users->ID, 'when_last_login_count', $wll_new_value);
205 }
206 if( $show_login_records == true ){
207 $args = array(
208 'post_title' => $users->data->display_name . __( ' has logged in at ', 'when-last-login' ) . date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
209 'post_status' => 'publish',
210 'post_author' => $users->ID,
211 'post_type' => 'wll_records'
212 );
213
214 $post_id = wp_insert_post( $args );
215
216 }
217
218 $wll_settings = get_option( 'wll_settings' );
219
220 if( isset( $wll_settings['record_ip_address'] ) && $wll_settings['record_ip_address'] == 1 ){
221
222 // call function to anonymize here.
223 $ip = When_Last_Login::wll_get_user_ip_address();
224
225 if ( ! empty( $post_id ) ) {
226 update_post_meta( $post_id, 'wll_user_ip_address', $ip );
227 }
228
229 update_user_meta( $users->ID, 'wll_user_ip_address', $ip );
230 }
231
232 do_action( 'wll_logged_in_action', array( 'login_count' => $wll_new_value, 'user' => $users ), $wll_settings );
233
234 }
235
236 public function wll_user_register( $user_id ){
237
238 $wll_settings = get_option( 'wll_settings' );
239
240 if( isset( $wll_settings['record_ip_address'] ) && $wll_settings['record_ip_address'] == 1 ){
241
242 $ip = When_Last_Login::wll_get_user_ip_address();
243 update_user_meta( $user_id, 'wll_user_ip_address', $ip );
244
245 }
246
247 do_action( 'wll_register_action', $user_id, $wll_settings );
248
249 }
250
251 public static function login_record_cp(){
252
253 global $show_login_records;
254
255 $settings = get_option( 'wll_settings' );
256
257 $show = $settings['show_all_login_records'];
258
259 if( 1 === $show ) {
260 $show = true;
261 }else{
262 $show = false;
263 }
264
265 $show_login_records = apply_filters( 'when_last_login_show_records_table', $show );
266
267 if( $show_login_records != true ){
268 return;
269 }
270
271 $labels = array(
272 'name' => __( 'Login Records', 'when-last-login' ),
273 'singular_name' => __( 'Login Record', 'when-last-login' ),
274 'menu_name' => __( 'Login Records', 'when-last-login' ),
275 'name_admin_bar' => __( 'Login Record', 'when-last-login' ),
276 'add_new' => __( 'Add New', 'when-last-login' ),
277 'add_new_item' => __( 'Add New Login Record', 'when-last-login' ),
278 'new_item' => __( 'New Login Record', 'when-last-login' ),
279 'edit_item' => __( 'Edit Login Record', 'when-last-login' ),
280 'view_item' => __( 'View Login Record', 'when-last-login' ),
281 'all_items' => __( 'All Login Records', 'when-last-login' ),
282 'search_items' => __( 'Search Login Records', 'when-last-login' ),
283 'parent_item_colon' => __( 'Parent Login Records:', 'when-last-login' ),
284 'not_found' => __( 'No login records found.', 'when-last-login' ),
285 'not_found_in_trash' => __( 'No login records found in Trash.', 'when-last-login' )
286 );
287
288 $args = array(
289 'labels' => $labels,
290 'description' => __( 'Description.', 'when-last-login' ),
291 'public' => false,
292 'publicly_queryable' => false,
293 'show_ui' => true,
294 'show_in_menu' => 'when-last-login-settings',
295 'query_var' => true,
296 'rewrite' => array( 'slug' => 'when-last-login-records' ),
297 'capability_type' => 'post',
298 'has_archive' => true,
299 'hierarchical' => false,
300 'menu_position' => null,
301 'supports' => array( 'title', 'author' ),
302 'capabilities' => array(
303 'create_posts' => false,
304 ),
305 'map_meta_cap' => true,
306 );
307
308 register_post_type( 'wll_records', $args );
309 }
310
311 /**
312 * Setup admin backend to display custom meta box for login count for admins
313 */
314 public static function admin_dashboard_widget(){
315
316 global $show_widget;
317
318 $show_widget = apply_filters( 'when_last_login_show_admin_widget', true );
319 //only show for administrators
320 if( current_user_can( 'manage_options' ) && $show_widget ){
321 wp_add_dashboard_widget( 'when_last_login_top_users', __( 'Top 3 Users', 'when-last-login' ), array( 'When_Last_Login', 'admin_dashboard_widget_display' ) );
322 }
323 }
324
325 public static function admin_dashboard_widget_display(){
326
327 global $show_widget, $show_login_records;
328
329 if( $show_widget != true ){
330 return;
331 }
332
333 if( is_network_admin() ){
334
335 $sites = get_sites();
336
337 if( is_array( $sites ) ){
338
339 foreach( $sites as $site ){
340
341 $blog_id = $site->blog_id;
342 $blog_details = get_blog_details( $blog_id );
343
344 ?><table width="100%" text-align="center" class='wp-list-table striped widefat'>
345 <tr>
346 <th colspan='4' style='text-align: center;'><strong><?php echo $blog_details->blogname .' (<a href="'.$blog_details->siteurl.'" target="_BLANK">'.$blog_details->siteurl.')</a>'; ?></strong></th>
347 </tr>
348 <?php
349
350 $user_query = new WP_User_Query( array( 'meta_key' => 'when_last_login_count', 'meta_value' => 0, 'meta_compare' => '!=', 'order' => 'ASC', 'oderby' => 'meta_value', 'number' => 3, 'blog_id' => $blog_id ) );
351
352 $topusers = $user_query->get_results();
353
354 if( $topusers ){
355 ?>
356 <tr>
357 <th><strong>#</strong></th>
358 <th><strong><?php _e( 'Users', 'when-last-login' ); ?></strong></th>
359 <th><strong><?php _e( 'Login Count', 'when-last-login' ); ?></strong></th>
360 <th><strong><?php _e( 'Last Logged In', 'when-last-login' ); ?></strong></th>
361 </tr>
362 <?php
363
364 $count = 1;
365
366 foreach($topusers as $wllusers){
367 echo '<tr><td>' . $count . '</td>';
368 echo '<td>' . $wllusers->display_name . '</td>';
369 echo '<td>' . get_user_meta( $wllusers->ID, 'when_last_login_count', true ) . '</td>';
370 echo '<td>' . date( 'Y-m-d H:i:s', get_user_meta( $wllusers->ID, 'when_last_login', true ) ) . '</td></tr>';
371 $count++;
372 }
373
374 } else {
375
376 echo '<tr><td colspan="4">'.__('No data yet', 'when-last-login').'</td></tr>';
377
378 }
379
380 ?></table><br/><?php
381
382 }
383
384 ?>
385
386 <a href="<?php echo admin_url( 'users.php?orderby=when_last_login&order=desc' ); ?>"><?php _e( 'View All Users', 'when-last-login' ); ?></a>
387
388 <?php if( $show_login_records == true ){ ?>
389 <a style="float:right" href="<?php echo admin_url( 'edit.php?post_type=wll_records' ); ?>"><?php _e( 'View Login Records', 'when-last-login' ); } //end the if filter check here ?></a>
390 <?php
391
392 }
393
394 } else {
395
396 ?><table width="100%" text-align="center" class='wp-list-table striped widefat'>
397
398 <?php
399
400 $user_query = new WP_User_Query( array( 'meta_key' => 'when_last_login_count', 'meta_value' => 0, 'meta_compare' => '!=', 'order' => 'ASC', 'oderby' => 'meta_value', 'number' => 3 ) );
401
402 $topusers = $user_query->get_results();
403
404 if( $topusers ){
405 ?>
406 <tr>
407 <th><strong>#</strong></th>
408 <th><strong><?php _e( 'Users', 'when-last-login' ); ?></strong></th>
409 <th><strong><?php _e( 'Login Count', 'when-last-login' ); ?></strong></th>
410 <th><strong><?php _e( 'Last Logged In', 'when-last-login' ); ?></strong></th>
411 </tr>
412 <?php
413
414 $count = 1;
415
416 foreach($topusers as $wllusers){
417 echo '<tr><td>' . $count . '</td>';
418 echo '<td>' . $wllusers->display_name . '</td>';
419 echo '<td>' . get_user_meta( $wllusers->ID, 'when_last_login_count', true ) . '</td>';
420 echo '<td>' . date( 'Y-m-d H:i:s', get_user_meta( $wllusers->ID, 'when_last_login', true ) ) . '</td></tr>';
421 $count++;
422 }
423
424 } else {
425
426 echo '<tr><td colspan="4">'.__('No data yet', 'when-last-login').'</td></tr>';
427
428 }
429
430 ?></table><br/><?php
431
432 ?>
433
434 <a href="<?php echo admin_url( 'users.php?orderby=when_last_login&order=desc' ); ?>"><?php _e( 'View All Users', 'when-last-login' ); ?></a>
435
436 <?php if( $show_login_records == true ){ ?>
437 <a style="float:right" href="<?php echo admin_url( 'edit.php?post_type=wll_records' ); ?>"><?php _e( 'View Login Records', 'when-last-login' ); } //end the if filter check here ?></a>
438 <?php
439
440 }
441
442 }
443
444 /**
445 * Setup Column and data for users page with sortable
446 */
447 public static function column_header( $column ){
448 $settings = get_option( 'wll_settings' );
449
450 $column['when_last_login'] = __( 'Last Login', 'when-last-login' );
451
452 if ( ! empty( $settings['record_ip_address'] ) ) {
453 $column['when_last_login_ip_address'] = __( 'IP Address', 'when-last-login' );
454 }
455
456
457 return $column;
458 }
459
460 public static function column_data( $value, $column_name, $id ){
461
462 $settings = get_option( 'wll_settings' );
463
464 if ( $column_name == 'when_last_login' ){
465
466 $when_last_login_meta = get_the_author_meta( 'when_last_login', $id );
467
468 if( ! empty( $when_last_login_meta ) ){
469 return human_time_diff( $when_last_login_meta );
470 }else{
471
472 if(get_the_author_meta( 'when_last_login', $id ) === 0 ){
473 return __( 'Never', 'when-last-login' );
474 }else{
475 update_user_meta( $id, 'when_last_login', 0 );
476 return __( 'Never', 'when-last-login' );
477 }
478
479 }
480 } else if( $column_name == 'when_last_login_ip_address' ){
481
482 $when_last_login_ip_address = get_user_meta( $id, 'wll_user_ip_address', true );
483
484 if ( $when_last_login_ip_address && $when_last_login_ip_address != "" && $settings['record_ip_address'] != "") {
485 return "<a href='http://www.ip-adress.com/ip_tracer/".$when_last_login_ip_address."' target='_BLANK' title='".__( 'Lookup', 'when-last-login' )."'>".$when_last_login_ip_address."</a>";
486 } else {
487 return __( 'IP Address Not Recorded', 'when-last-login' );
488 }
489
490
491 }
492 return $value;
493 }
494
495 public static function column_sortable( $columns ){
496 $columns['when_last_login'] = 'when_last_login';
497 return $columns;
498 }
499
500 public static function sort_by_login_date( $query ) {
501 if ( 'when_last_login' == $query->get( 'orderby' ) ) {
502 $query->set( 'orderby', 'meta_value_num' );
503 $query->set( 'meta_key', 'when_last_login' );
504 }
505 }
506
507 /*
508 * Support for Paid Memberships Pro
509 * TODO: use existing PMPro usermeta if installed
510 */
511 public static function pmpro_memberlist_add_header( $users ){
512 if( !defined( 'PMPRO_VERSION' ) ){
513 return;
514 }
515 ?>
516 <th><?php _e( 'Last Login', 'when-last' );?></th>
517 <?php
518 }
519
520 public static function pmpro_memberlist_add_column_data( $users ){
521 if( !defined( 'PMPRO_VERSION' ) ){
522 return;
523 }
524 ?>
525 <td>
526 <?php
527 if( ! empty( $users->when_last_login ) ){
528 echo human_time_diff( $users->when_last_login );
529 }else{
530 return _e( 'Never', 'when-last-login' );
531 }
532 ?>
533 </td>
534 <?php
535 }
536
537 public function wll_settings_page(){
538
539 add_menu_page( __('When Last Login', 'when-last-login'), __('When Last Login', 'when-last-login'), 'manage_options', 'when-last-login-settings', array( $this, 'wll_settings_callback' ), 'dashicons-visibility');
540
541 add_submenu_page( 'when-last-login-settings', __('Settings', 'when-last-login'), __('Settings', 'when-last-login'), 'manage_options', 'when-last-login-settings', array( $this, 'wll_settings_callback' ) );
542
543 add_submenu_page( 'when-last-login-settings', __('Extensions', 'when-last-login'), __('Extensions', 'when-last-login'), 'manage_options', 'admin.php?page=when-last-login-settings&tab=add-ons' );
544
545 do_action( 'wll_settings_admin_menu_item' );
546
547 }
548
549 public function wll_settings_callback(){
550
551 include WLL_DIR_PATH . '/includes/settings.php';
552
553 }
554
555 public function wll_settings_page_head(){
556
557 $wll_settings = array();
558
559 if( isset( $_POST['wll_save_settings'] ) ){
560
561 $wll_settings['user_access'] = isset( $_POST['wll_login_record_user_access'] ) ? $_POST['wll_login_record_user_access'] : "";
562 $wll_settings['record_ip_address'] = isset( $_POST['wll_record_user_ip_address'] ) && $_POST['wll_record_user_ip_address'] == '1' ? 1 : 0;
563 $wll_settings['show_all_login_records'] = isset( $_POST['wll_all_login_records'] ) && $_POST['wll_all_login_records'] == '1' ? 1 : 0;
564
565 $wll_settings = apply_filters( 'wll_settings_filter', $wll_settings );
566
567 if ( update_option( 'wll_settings', $wll_settings ) ) {
568 //show admin notice here.
569 add_action( 'admin_notices', array( $this, 'wll_admin_notices' ) );
570 }
571
572 }
573
574 }
575
576 public function wll_admin_notices() {
577 ?>
578 <div class="notice notice-success is-dismissible">
579 <p><?php _e( 'Settings saved successfully.', 'when-last-login' ); ?></p>
580 </div>
581 <?php
582 }
583
584 public function wll_remove_records_notice__success() {
585 ?>
586 <div class="notice notice-success is-dismissible">
587 <p><?php _e( 'Records have been removed successfully.', 'when-last-login' ); ?></p>
588 </div>
589 <?php
590 }
591
592 public function wll_remove_records_notice__warning() {
593 ?>
594 <div class="notice notice-warning is-dismissible">
595 <p><?php _e( 'No old records to remove.', 'when-last-login' ); ?></p>
596 </div>
597 <?php
598 }
599
600 /**
601 * Function to remove logs automatically older than 3 months.
602 * @since 1.0.0
603 */
604 public function wll_automatically_remove_logs() {
605 global $pagenow;
606
607 // Bail if not on our settings page.
608 if ( 'admin.php' == $pagenow && 'when-last-login-settings' != $_GET['page'] ) {
609 return;
610 }
611
612 global $wpdb;
613
614 $sql = "DELETE p, pm FROM $wpdb->posts p LEFT JOIN $wpdb->postmeta pm ON pm.post_id = p.ID WHERE p.post_type = 'wll_records'";
615
616 if ( isset( $_REQUEST['remove_all_wll_records'] ) ) {
617 if ( $wpdb->query( $sql ) > 0 ) {
618 add_action( 'admin_notices', array( $this, 'wll_remove_records_notice__success' ) );
619 } else {
620 add_action( 'admin_notices', array( $this, 'wll_remove_records_notice__warning' ) );
621 }
622
623 }
624
625 if ( isset( $_REQUEST['remove_wll_records'] ) ) {
626
627 $date = apply_filters( 'wll_automatically_remove_logs_date', date( 'Y-m-d', strtotime( '-3 months' ) ) );
628
629 $sql .= " AND p.post_date <= '$date'";
630
631 if ( $wpdb->query( $sql ) > 0 ) {
632 add_action( 'admin_notices', array( $this, 'wll_remove_records_notice__success' ) );
633 } else {
634 add_action( 'admin_notices', array( $this, 'wll_remove_records_notice__warning' ) );
635 }
636 }
637
638 if ( isset( $_REQUEST['remove_wll_ip_addresses'] ) ) {
639 $sql = "DELETE FROM $wpdb->usermeta WHERE meta_key = 'wll_user_ip_address'";
640
641 if ( $wpdb->query( $sql ) > 0 ) {
642 add_action( 'admin_notices', array( $this, 'wll_remove_records_notice__success' ) );
643 } else {
644 add_action( 'admin_notices', array( $this, 'wll_remove_records_notice__warning' ) );
645 }
646
647 }
648 }
649
650
651 public function wll_records_columns( $columns ){
652
653 return array_merge( $columns, array( 'wll-ip-address' => __( 'IP Address', 'when-last-login' ) ) );
654
655 }
656
657 public function wll_records_column_contents( $column, $post_id ){
658
659 switch ( $column ) {
660 case 'wll-ip-address':
661 $ip_address = get_post_meta( $post_id, 'wll_user_ip_address', true );
662 if ( ! empty( $ip_address ) && $ip_address != "" ) {
663 echo "<a href='http://www.ip-adress.com/ip_tracer/".$ip_address."' target='_BLANK' title='".__( 'Lookup', 'when-last-login' )."'>".$ip_address."</a>";
664 } else {
665 _e( 'IP Address Not Recorded', 'when-last-login' );
666 }
667 break;
668
669 }
670 }
671
672 public function wll_plugin_action_links( $links ) {
673 $new_links = array(
674 '<a href="' . admin_url('admin.php?page=when-last-login-settings') . '" title="' . esc_attr( __( 'View Settings', 'when-last-login' ) ) . '">' . __( 'Settings', 'when-last-login' ) . '</a>'
675 );
676
677 $new_links = apply_filters( 'wll_plugin_action_links', $new_links );
678
679 return array_merge( $new_links, $links );
680 }
681
682 public function wll_plugin_row_meta( $links, $file ) {
683 if ( strpos( $file, 'when-last-login.php' ) !== false ) {
684 $new_links = array(
685 '<a href="' . admin_url('admin.php?page=when-last-login-settings') . '" title="' . esc_attr( __( 'View Settings', 'when-last-login' ) ) . '">' . __( 'Settings', 'when-last-login' ) . '</a>',
686 '<a href="' . esc_url( 'https://yoohooplugins.com/?s=when+last+login' ) . '" title="' . esc_attr( __( 'View Documentation', 'when-last-login' ) ) . '">' . __( 'Docs', 'when-last-login' ) . '</a>',
687 '<a href="' . esc_url( 'https://yoohooplugins.com/support/' ) . '" title="' . esc_attr( __( 'Visit Customer Support Forum', 'when-last-login' ) ) . '">' . __( 'Support', 'when-last-login' ) . '</a>',
688 );
689
690 $new_links = apply_filters( 'wll_plugin_row_meta', $new_links );
691 $links = array_merge( $links, $new_links );
692 }
693 return $links;
694 }
695
696 public static function wll_get_user_ip_address(){
697
698 if( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ){
699 $ip = $_SERVER['HTTP_CLIENT_IP'];
700 } else if ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ){
701 $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
702 } else {
703 $ip = $_SERVER['REMOTE_ADDR'];
704 }
705
706 $ip = apply_filters( 'wll_user_ip_address', $ip );
707
708 return IpAnonymizer::anonymizeIp( $ip );
709 }
710
711 } // end class
712 When_Last_Login::get_instance();
713