prefix . 'wll_login_attempts' ; $sql = "DROP TABLE IF EXISTS `$delete_table`"; $wpdb->query( $sql ); delete_transient( 'when_last_login_add_ons_page' ); // on upgrade remove the notice save. delete_option( 'wll_notice_hide' ); delete_option( 'wll_notice_hide_1' ); delete_option( 'wll_notice_hide_2' ); // update version number to 1.0 update_option( 'wll_current_version', 1.2 ); } } public static function text_domain(){ load_plugin_textdomain( 'when-last-login', false, dirname( 'WLL_BASE_NAME' ) . '/languages' ); } public static function update_notice(){ if( get_option( 'wll_notice_hide' ) != '1' && ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'when-last-login-settings' ) ){ ?>

this link' ), 'when-last-login' ); ?>

admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'wll_hide_notice_nonce' ) ) ); } if( isset( $_GET['page'] ) && $_GET['page'] == 'when-last-login-settings' ){ wp_enqueue_style( 'wll_admin_settings_styles', plugins_url( '/css/admin.css', __FILE__ ) ); } } public static function last_login( $user_login, $users ){ global $show_login_records; //get/update user meta 'when_last_login' on login and add time() to it. update_user_meta( $users->ID, 'when_last_login', time() ); //get and update user meta 'when_last_login_count' on login for # of login counts. Thanks to Jarryd Long (@jarrydlong) for the assistance $wll_count = get_user_meta( $users->ID, 'when_last_login_count', true ); if( $wll_count === false ){ update_user_meta($users->ID, 'when_last_login_count', 1); } else { $wll_new_value = intval($wll_count); $wll_new_value = $wll_new_value + 1; update_user_meta($users->ID, 'when_last_login_count', $wll_new_value); } if( $show_login_records == true ){ $args = array( 'post_title' => $users->data->display_name . __( ' has logged in at ', 'when-last-login' ) . date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), 'post_status' => 'publish', 'post_author' => $users->ID, 'post_type' => 'wll_records' ); $post_id = wp_insert_post( $args ); } $wll_settings = get_option( 'wll_settings' ); if( isset( $wll_settings['record_ip_address'] ) && intval( $wll_settings['record_ip_address'] ) == 1 ){ // call function to anonymize here. $ip = When_Last_Login::wll_get_user_ip_address(); if ( ! empty( $post_id ) ) { update_post_meta( $post_id, 'wll_user_ip_address', $ip ); } update_user_meta( $users->ID, 'wll_user_ip_address', $ip ); } do_action( 'wll_logged_in_action', array( 'login_count' => $wll_new_value, 'user' => $users ), $wll_settings ); } public function wll_user_register( $user_id ){ $wll_settings = get_option( 'wll_settings' ); if( isset( $wll_settings['record_ip_address'] ) && $wll_settings['record_ip_address'] == 1 ){ $ip = When_Last_Login::wll_get_user_ip_address(); update_user_meta( $user_id, 'wll_user_ip_address', $ip ); } do_action( 'wll_register_action', $user_id, $wll_settings ); } public static function login_record_cp(){ global $show_login_records; $settings = get_option( 'wll_settings' ); $show = (!empty($settings['show_all_login_records']) AND $settings['show_all_login_records'] === 1); $show_login_records = apply_filters( 'when_last_login_show_records_table', $show ); if( $show_login_records != true ){ return; } $labels = array( 'name' => __( 'Login Records', 'when-last-login' ), 'singular_name' => __( 'Login Record', 'when-last-login' ), 'menu_name' => __( 'Login Records', 'when-last-login' ), 'name_admin_bar' => __( 'Login Record', 'when-last-login' ), 'add_new' => __( 'Add New', 'when-last-login' ), 'add_new_item' => __( 'Add New Login Record', 'when-last-login' ), 'new_item' => __( 'New Login Record', 'when-last-login' ), 'edit_item' => __( 'Edit Login Record', 'when-last-login' ), 'view_item' => __( 'View Login Record', 'when-last-login' ), 'all_items' => __( 'All Login Records', 'when-last-login' ), 'search_items' => __( 'Search Login Records', 'when-last-login' ), 'parent_item_colon' => __( 'Parent Login Records:', 'when-last-login' ), 'not_found' => __( 'No login records found.', 'when-last-login' ), 'not_found_in_trash' => __( 'No login records found in Trash.', 'when-last-login' ) ); $args = array( 'labels' => $labels, 'description' => __( 'Description.', 'when-last-login' ), 'public' => false, 'publicly_queryable' => false, 'show_ui' => true, 'show_in_menu' => 'when-last-login-settings', 'query_var' => true, 'rewrite' => array( 'slug' => 'when-last-login-records' ), 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => false, 'menu_position' => null, 'supports' => array( 'title', 'author' ), 'capabilities' => array( 'create_posts' => false, ), 'map_meta_cap' => true, ); register_post_type( 'wll_records', $args ); } /** * Setup admin backend to display custom meta box for login count for admins */ public static function admin_dashboard_widget(){ global $show_widget; $show_widget = apply_filters( 'when_last_login_show_admin_widget', true ); //only show for administrators if( current_user_can( 'manage_options' ) && $show_widget ){ wp_add_dashboard_widget( 'when_last_login_top_users', __( 'Most Frequent Logins', 'when-last-login' ), array( 'When_Last_Login', 'admin_dashboard_widget_display' ) ); } } public static function admin_dashboard_widget_display(){ global $show_widget, $show_login_records; if( $show_widget != true ){ return; } if( is_network_admin() ){ $sites = get_sites(); if( is_array( $sites ) ){ foreach( $sites as $site ){ $blog_id = $site->blog_id; $blog_details = get_blog_details( $blog_id ); ?> 'when_last_login_count', 'meta_value' => 0, 'meta_compare' => '!=', 'order' => 'DESC', 'orderby' => 'meta_value_num', 'number' => apply_filters( 'wll_top_widget_user_count', 3 ), 'blog_id' => $blog_id, 'role__not_in' => array( 'administrator' ) ) ); $topusers = $user_query->get_results(); if( $topusers ){ ?> '; echo ''; echo ''; echo ''; $count++; } } else { echo ''; } ?>
blogname ) .' ('. esc_html( $blog_details->siteurl ) . ')'; ?>
#
' . intval( $count ) . '' . esc_html( $wllusers->display_name ) . '' . get_user_meta( $wllusers->ID, 'when_last_login_count', true ) . '' . date_i18n( 'Y-m-d H:i:s', get_user_meta( $wllusers->ID, 'when_last_login', true ) ) . '
'. esc_html__('No data yet', 'when-last-login').'

'when_last_login_count', 'meta_value' => 0, 'meta_compare' => '!=', 'order' => 'DESC', 'orderby' => 'meta_value_num', 'number' => apply_filters( 'wll_top_widget_user_count', 3 ), 'role__not_in' => array( 'administrator' ) ) ); $topusers = $user_query->get_results(); if( $topusers ){ ?> '; echo ''; echo ''; echo ''; $count++; } } else { echo ''; } ?>
#
' . intval( $count ) . '' . $wllusers->display_name . '' . get_user_meta( $wllusers->ID, 'when_last_login_count', true ) . '' . date_i18n( 'Y-m-d H:i:s', get_user_meta( $wllusers->ID, 'when_last_login', true ) ) . '
'. esc_html__( 'No data yet', 'when-last-login' ).'

" . esc_html( $when_last_login_ip_address ) . ""; } else { return esc_html__( 'IP Address Not Recorded', 'when-last-login' ); } } return $value; } public static function column_sortable( $columns ){ $columns['when_last_login'] = 'when_last_login'; return $columns; } public static function sort_by_login_date( $query ) { if ( 'when_last_login' == $query->get( 'orderby' ) ) { $query->set( 'orderby', 'meta_value_num' ); $query->set( 'meta_key', 'when_last_login' ); } } /* * Support for Paid Memberships Pro * TODO: use existing PMPro usermeta if installed */ public static function pmpro_memberlist_add_header( $users ){ if( !defined( 'PMPRO_VERSION' ) ){ return; } ?> when_last_login ) ){ echo human_time_diff( $users->when_last_login ); }else{ return esc_html_e( 'Never', 'when-last-login' ); } ?>

posts p LEFT JOIN $wpdb->postmeta pm ON pm.post_id = p.ID WHERE p.post_type = 'wll_records'"; if ( isset( $_REQUEST['remove_all_wll_records'] ) ) { $nonce = $_REQUEST['wll_remove_all_records_nonce']; if ( wp_verify_nonce( $nonce, 'wll_remove_all_records_nonce' ) ) { if ( $wpdb->query( $sql ) > 0 ) { add_action( 'admin_notices', array( $this, 'wll_remove_records_notice__success' ) ); } else { add_action( 'admin_notices', array( $this, 'wll_remove_records_notice__warning' ) ); } } else { die( 'nonce not valid.' ); } } if ( isset( $_REQUEST['remove_wll_records'] ) ) { $nonce = $_REQUEST['wll_remove_records_nonce']; if ( wp_verify_nonce( $nonce, 'wll_remove_records_nonce' ) ) { $date = apply_filters( 'wll_automatically_remove_logs_date', date( 'Y-m-d', strtotime( '-3 months' ) ) ); $sql .= " AND p.post_date <= '$date'"; if ( $wpdb->query( $sql ) > 0 ) { add_action( 'admin_notices', array( $this, 'wll_remove_records_notice__success' ) ); } else { add_action( 'admin_notices', array( $this, 'wll_remove_records_notice__warning' ) ); } } else { die( 'nonce not valid.' ); } } if ( isset( $_REQUEST['remove_wll_ip_addresses'] ) ) { $nonce = $_REQUEST['wll_remove_ip_nonce']; if ( wp_verify_nonce( $nonce, 'wll_remove_ip_nonce' ) ) { $sql = "DELETE FROM $wpdb->usermeta WHERE meta_key = 'wll_user_ip_address'"; if ( $wpdb->query( $sql ) > 0 ) { add_action( 'admin_notices', array( $this, 'wll_remove_records_notice__success' ) ); } else { add_action( 'admin_notices', array( $this, 'wll_remove_records_notice__warning' ) ); } } else { die( 'nonce not valid.' ); } } } public function wll_records_columns( $columns ){ return array_merge( $columns, array( 'wll-ip-address' => __( 'IP Address', 'when-last-login' ) ) ); } public function wll_records_column_contents( $column, $post_id ){ switch ( $column ) { case 'wll-ip-address': $ip_address = get_post_meta( $post_id, 'wll_user_ip_address', true ); if ( ! empty( $ip_address ) && $ip_address != "" ) { echo "" . esc_html( $ip_address ) . ""; } else { esc_html_e( 'IP Address Not Recorded', 'when-last-login' ); } break; } } public function wll_plugin_action_links( $links ) { $new_links = array( '' . __( 'Settings', 'when-last-login' ) . '' ); $new_links = apply_filters( 'wll_plugin_action_links', $new_links ); return array_merge( $new_links, $links ); } public function wll_plugin_row_meta( $links, $file ) { if ( strpos( $file, 'when-last-login.php' ) !== false ) { $new_links = array( '' . __( 'Settings', 'when-last-login' ) . '', '' . esc_html__( 'Docs', 'when-last-login' ) . '', '' . esc_html__( 'Support', 'when-last-login' ) . '', ); $new_links = apply_filters( 'wll_plugin_row_meta', $new_links ); $links = array_merge( $links, $new_links ); } return $links; } public static function wll_get_user_ip_address(){ if( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ){ $ip = $_SERVER['HTTP_CLIENT_IP']; } else if ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ){ $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } $ip = apply_filters( 'wll_user_ip_address', $ip ); if ( apply_filters( 'wll_force_anon_ip', false ) ) { return $ip; } else { return IpAnonymizer::anonymizeIp( $ip ); } return IpAnonymizer::anonymizeIp( $ip ); } } // end class When_Last_Login::get_instance();