Skip to content

Instantly share code, notes, and snippets.

@jonbrockett
Created June 10, 2021 13:58
Show Gist options
  • Save jonbrockett/8042df63d9d2832f77d1e7ad0ef14d77 to your computer and use it in GitHub Desktop.
Save jonbrockett/8042df63d9d2832f77d1e7ad0ef14d77 to your computer and use it in GitHub Desktop.
Disable Enumerating Author Pages
<?php
/**
* Disables enumerating author pages
*
* This helps with security by preventing potential attackers
* from searching for login usernames by simply
* searching ?author=1, ?author=2, etc
*/
if (!is_admin()) {
// default URL format
if (preg_match('/author=([0-9]*)/i', $_SERVER['QUERY_STRING'])) die();
add_filter('redirect_canonical', 'author_check_enum', 10, 2);
}
function author_check_enum($redirect, $request) {
// permalink URL format
if (preg_match('/\?author=([0-9]*)(\/*)/i', $request)) die();
else return $redirect;
}
/** Disables enumerating author redirects to improve security */
require_once 'library/author-enumeration-disable.php';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment