PHP snippet · Security

Block user enumeration

Stops the ?author=1 probe and the REST users endpoint handing out your login names to anyone who asks. Real author archives keep working.

About this php snippet

Requesting /?author=1 makes WordPress redirect to that user's archive, which exposes their login slug. Walking the numbers gives an attacker a list of real usernames, which is half of a brute-force attempt already solved. The REST endpoint /wp-json/wp/v2/users hands over the same list in a single request.

This closes both without taking away anything you use. Author archives at /author/name/ keep working, and logged-in users are unaffected, so the block editor's author pickers behave exactly as before.

What it does

  • Redirects the ?author=N probe to your home page before WordPress can reveal the slug
  • Removes the public /wp/v2/users REST endpoints for logged-out visitors
  • Leaves real author archives working normally
  • Skips the admin entirely, so nothing inside wp-admin changes

Good to know

  • Priority is what makes this work, and it is the part most versions of this snippet get wrong. Core's own canonical redirect is what turns ?author=1 into /author/admin/, and at the same priority it runs first, so the slug leaks anyway. This runs ahead of it.
  • Named archives are told apart from the numbered probe deliberately. WordPress resolves /author/admin/ to the same author id, so checking the author number alone would block the archive along with the probe.
  • Logged-in visitors keep the users endpoint, which is what the editor needs
  • The one thing to watch is a headless front end or third-party service that reads the users endpoint anonymously. Authenticated requests are unaffected.

More php snippets

Your EMCP guide

Answers from our docs

YOUR CHAT, YOUR CHOICE

Before we chat

MSR Builds processes your question and up to four recent messages on our server to answer from the EMCP docs. AI is optional and needs your separate permission.

The chat is kept in this page's memory, not saved as a conversation in our database or browser storage. Our hosting and security services process connection information, such as your IP address, to prevent abuse.

Cloudflare Turnstile checks your browser and connection to prevent automated abuse when you send a question. No login is required.

Please leave out personal, sensitive or confidential information, passwords and API keys.

You can withdraw consent and clear this page's chat at any time. This cannot undo a request already sent or erase provider/security records.

Chat privacy, retention & your rights ↗ · Privacy contact

Starting chat consents to this processing. You can browse our docs without using the chat.