Skip to content

Instantly share code, notes, and snippets.

@BoweFrankema
Created June 1, 2017 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BoweFrankema/7f48e320ed8cbb9fee50d66c768fda2f to your computer and use it in GitHub Desktop.
Save BoweFrankema/7f48e320ed8cbb9fee50d66c768fda2f to your computer and use it in GitHub Desktop.
Add random login string after login.
function jpr_generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
function jpr_login_clearing_cache( $redirect_to, $request, $user ) {
global $user;
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
if ( in_array( 'administrator', $user->roles ) ) {
return $redirect_to . '?login=' . jpr_generateRandomString();
} else {
return $redirect_to . '?login=' . jpr_generateRandomString();
}
} else {
return $redirect_to;
}
}
add_filter( 'login_redirect', 'jpr_login_clearing_cache', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment