Last update at :2024-05-10,Edit by888u
Code deployment:
Find the file wp-includes/functions.php, open it for editing, and add the following at the end of the text.
//// --------------- WordPress member registration displays the registration date and IP ------------- //// /** * add the register record. */ function get_client_ip() { if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) $ip = getenv("HTTP_CLIENT_IP"); else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) $ip = getenv("HTTP_X_FORWARDED_FOR"); else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) $ip = getenv("REMOTE_ADDR"); else if (isset ($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown")) $ip = $_SERVER['REMOTE_ADDR']; else $ip = "unknown"; Return ($ip); } //Create a new field to store the IP address when the user registers add_action('user_register', 'log_ip'); function log_ip($user_id){ $ip = get_client_ip(); Update_user_meta($user_id, 'signup_ip', $ip); } // Create new fields to store user login time and login IP add_action( 'wp_login', 'insert_last_login' ); function insert_last_login( $login ) { Global $user_id; $user = get_userdatabylogin( $login ); Update_user_meta( $user->ID, 'last_login', current_time( 'mysql' ) ); $last_login_ip = get_client_ip(); Update_user_meta( $user->ID, 'last_login_ip', $last_login_ip); } //Add additional columns add_filter('manage_users_columns', 'add_user_additional_column'); function add_user_additional_column($columns) { $columns['user_nickname'] = 'nickname'; $columns['user_url'] = 'website'; $columns['reg_time'] = 'Registration time'; $columns['signup_ip'] = 'Register IP'; $columns['last_login'] = 'Last login'; // I plan to display the registered IP and registration time, login IP and login time together, so I log out the following two lines /*$columns['signup_ip'] = 'Register IP';*/ $columns['last_login_ip'] = 'Login IP'; unset($columns['name']);//Remove the "name" column. If you need to keep it, just delete this line Return $columns; } //Display the content of the column add_action('manage_users_custom_column', 'show_user_additional_column_content', 10, 3); function show_user_additional_column_content($value, $column_name, $user_id) { $user = get_userdata( $user_id ); // Output "nickname" if ( 'user_nickname' == $column_name ) return $user->nickname; // Output the user’s website if ( 'user_url' == $column_name ) ‐‐ return ''.$user->user_url.''; // Output registration time and registration IP If('reg_time' == $column_name){ return get_date_from_gmt($user->user_registered); } // Output registration time and registration IP if('signup' == $column_name ){ return get_user_meta( $user->ID, 'signup_ip', true); } // Output the latest login time and login IP if ('last_login' == $column_name && $user->last_login){ return get_user_meta( $user->ID, 'last_login', true ); } // Output the latest login time and login IP If ('last_login_ip' == $column_name){ return get_user_meta( $user->ID, 'last_login_ip', true ); } Return $value; } // Sort by registration time by default add_filter( "manage_users_sortable_columns", 'cmhello_users_sortable_columns' ); function cmhello_users_sortable_columns($sortable_columns){ $sortable_columns['reg_time'] = 'reg_time'; Return $sortable_columns; } add_action( 'pre_user_query', 'cmhello_users_search_order' ); function cmhello_users_search_order($obj){ If(!isset($_REQUEST['orderby']) || $_REQUEST['orderby']=='reg_time' ){ If( !in_array($_REQUEST['order'],array('asc','desc')) ){ $_REQUEST['order'] = 'desc'; } $obj->query_orderby = "ORDER BY user_registered ".$_REQUEST['order'].""; } }
Renderings
Attached is also an introduction to some commonly used plug-ins:
1. Registration user name restriction - plug-in Restrict Registration
2. Access log – plug-in WP-Statistics, Slimstat Analytics (both are available)
3. User login failure (too many times) lock – plug-in Login LockDown
4. Database backup – WP Database Backup (recommended)
5. Registration verification (anti-machine registration) - plug-in SI Captcha Anti-Spam settings (recommended)
Recommended site searches: https proxy ip, free virtual host, US vps host, Ministry of Industry and Information Technology registration website, US space, query IP address, dynamic ip server, ASP host space, overseas server rental price, how long does it take for website registration, < /p>
发表评论