Plugin to avoid sharing username in Wordpress

Is there a way to prohibit the use of a username (based on IP address or login at the same time in another place) for Wordpress? If there is a plugin for tracking IP address and login time, this should be good too. Thanks

+5
source share
3 answers

you can add this to your functions.php file or plugin.

    //set the most current user to have a cookie matching a unique value    
add_action("set_logged_in_cookie", "one_cookie", 10, 5);
function one_cookie($logged_in_cookie, $expire, $expiration, $user_id, $logged_in) {
    $secure = apply_filters('secure_logged_in_cookie', false, $user_id, is_ssl());
    $cookie = uniqid();
    update_user_meta($user_id, "one_cookie", $cookie);
    setcookie("one_cookie", $cookie, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure, true);
    return;
}
//check requests from users to ensure they have this cookie
add_action("init", "check_one_cookie", 1);
function check_one_cookie() {
    $user = wp_get_current_user();
    if ($user->ID == 0) { return; }
    $storedcookie = get_user_meta($user->ID, 'one_cookie');
    print_r(array('$storedcookie'=>$storedcookie));
  if (!empty($storedcookie) && $_COOKIE['one_cookie'] != $storedcookie) {
    /*if the user doesn't have the same cookie as we have stored, log them out.*/
        wp_logout();
        //auth_redirect() may have a more desired effect
    }
}
//unset a users cookie
add_action('wp-logout', 'one_cookie_logout');
function one_cookie_logout() {
    setcookie("one_cookie", "", 1);
}

This will only work in one direction. Each time a new login is processed, it blocks the old one. If you want to undo this, you probably need to write a lot more code so that the user can break the lock, etc.

, 'wp-includes/pluggable.php'

WordPress 3.1.

+2

3.6.1 , , "check_one_cookie" ​​ :

add_action("init", "check_one_cookie", 1);
    function check_one_cookie() {
    $user = wp_get_current_user();
    if ($user->ID == 0) { return; }
    $storedcookie = get_user_meta($user->ID, 'one_cookie');
    // print_r(array('$storedcookie'=>$storedcookie));
    if (!empty($storedcookie) && $_COOKIE['one_cookie'] != $storedcookie[0]) {
    /*if the user doesn't have the same cookie as we have stored, log them out.*/
        wp_logout();
        //auth_redirect() may have a more desired effect
    }
}

$storedcookie $storedcookie [0] ( COOKIEPATH, COOKIE_DOMAIN )

+1
0

All Articles