I'm disabling user enumeration for security purposes in order to prevent usernames from being revealed by looking up the user IDs. Instead, whenever someone tried to find out the username by their ID, such as visiting the following:
http://example.com?author=1
It will redirect them to the homepage. After searching around, I've found two plugins which have this function, but both of them use slightly different logics to check if someone is trying to enumerate:
Logic #1
if ( preg_match( '/(wp-comments-post)/', $_SERVER['REQUEST_URI'] ) === 0 && ! empty( $_REQUEST['author'] ) ) {
# Redirect to homepage...
}
Logic #2
if ( ! preg_match( '/(wp-comments-post)/', $_SERVER['REQUEST_URI'] ) && ! empty( $_REQUEST['author'] ) && ( int ) $_REQUEST['author'] ) {
# Redirect to homepage...
}
Both logics work, but I'm wondering which one is more effective and what they are doing differently.
Also, before I discovered this logic, I've already implemented the following functions to redirect author links to the homepage, which gives em the same result:
# Redirect author page to homepage
add_action( 'template_redirect', 'author_page' );
function author_page() {
# If the author archive page is being accessed, redirect to homepage
if ( is_author() ) {
wp_safe_redirect( get_home_url(), 301 );
exit;
}
}
Is this function enough to prevent user enumeration? Or should I still apply one fo the following logics above?