PluginProbe
When Last Login / 1.0
When Last Login v1.0
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.0, at when-last-login.php

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