Skip to main content
Agency Program Hosting from 10% off. A dedicated account manager. Priority support. Built for growing agencies. Hosting from 10% off, a dedicated account manager and priority support for growing agencies. Speak to the team Join free
WP-Ban icon

WP-Ban

v2.0.0
by Lester Chan · 3.7 (27 reviews)

Ban users by IP, IP Range, host name, user agent and referrer url from visiting your WordPress's blog.

8K+ active installs Updated Aug 09, 2026 Tested to 7.0.9 Requires PHP 8.2
Try Demo Download
Pre-installed Ready in ~10s No card
WP-Ban

About WP-Ban

WP-Ban is a WordPress plugin that allows you to ban IP addresses, IP ranges, host names, and referrer URLs from accessing your blog. It also provides statistics on the number of attempted visits and allows for wildcard matching. You can find the plugin on GitHub for development purposes, and translations are available on the WP-Ban website.

Screenshots

WP-Ban screenshot
WP-Ban screenshot
WP-Ban screenshot
WP-Ban screenshot

Frequently asked questions

What is WP-Ban?
WP-Ban is a WordPress plugin that allows you to ban users from visiting your blog. You can ban users by IP, IP range, host name, user agent, and referrer URL.
What happens when a banned user tries to visit my blog?
When a banned IP, IP range, host name, or referrer URL attempts to visit your blog, a custom ban message will be displayed. The plugin also records statistics on how many times they try to visit.
Can I exclude certain IPs from being banned?
Yes, you can exclude specific IPs from being banned. The plugin also supports wildcard matching for banning.
Where can I find the development information for WP-Ban?
Development information for WP-Ban can be found on GitHub at https://github.com/lesterchan/wp-ban.
How do I upgrade WP-Ban?
To upgrade WP-Ban, deactivate the plugin, then replace the wp-ban folder in wp-content/plugins with the new version, and finally activate the plugin again.

Changelog

2.0.0

  • FIXED: One IP address had several spellings and the lists compare strings, so 2001:DB8::1 and 2001:db8::1 were two different ban entries, and an IPv4-mapped ::ffff:203.0.113.5 matched neither an IPv4 entry nor an IPv4 range. Where the visitor chooses the spelling that is a ban evasion; where they do not it is a silent miss, because a dual-stack server reporting REMOTE_ADDR in the mapped form never matched the plain IPv4 address its owner typed. Addresses are canonicalised now
  • FIXED: The banned message may contain a <style> element — the shipped one does — and kses has no opinion about CSS, only about markup. On multisite a site administrator holds manage_options and deliberately does not hold unfiltered_html, so they could make every banned visitor fetch a stylesheet of their choosing. @import and url() are now removed from stored CSS for anyone without that capability; everything else about the rules is left alone
  • FIXED: A forwarding header was read from the left, which is the end the visitor writes. Every proxy appends — nginx’s $proxy_add_x_forwarded_for is literally "$http_x_forwarded_for, $remote_addr" — so a banned visitor on a site that had named a header could send any address they liked and walk straight past the ban. Worse, the exclude list is an exact compare against the same value, so sending an excluded address short-circuited every list at once, host, referrer and user-agent bans included. The chain is read from the right now. A site behind more than one appending proxy says so through wp_ban_trusted_proxy_hops
  • FIXED: wp_ban_stats grew one entry per distinct address for ever, and the whole array was unserialised, incremented and written back on every banned request — so the cost of a request grew with the number of addresses ever seen, and neither half needed any authentication to reach: a visitor opts in by sending a banned user agent, which needs no IP match at all. The breakdown now remembers the five hundred addresses turned away most often, adjustable with wp_ban_max_tracked_addresses. The total count is unchanged
  • FIXED: A ban pattern with several wildcards backtracks quadratically against a long subject, and the subjects are the user agent and the referrer, which the visitor writes — and both lists are walked on every request, not only on banned ones. Subjects are capped at 2,048 characters before matching; wp_ban_max_match_length adjusts it
  • FIXED: The reverse DNS lookup for %USER_HOSTNAME% ran on every ban whether or not the message used the variable, and the shipped message does not. Whoever owns the address’s reverse zone decides how long that blocking call takes
  • BREAKING: Requires WordPress 6.8 and PHP 8.2, up from 6.0 and 7.4.
  • BREAKING: Proxy headers are no longer trusted by default. If your site is behind Cloudflare, a load balancer or any reverse proxy, name the header your proxy sets in the new Header That Contains The IP field, or define WP_BAN_TRUST_PROXY. See the FAQ.
  • BREAKING: The This site is behind a reverse proxy checkbox is removed. It trusted whichever of seven forwarding headers happened to arrive; naming the one header your proxy sets is both safer and what the four sibling plugins offer. A site that had the box ticked and no header named is migrated to HTTP_X_FORWARDED_FOR.
  • BREAKING: The ban page is now served as 403 Forbidden instead of 200 OK. Filter wp_ban_status_code to restore the old behaviour. See the FAQ.
  • BREAKING: The pre-2.0.0 global functions (banned(), ban_get_ip(), print_banned_message(), process_ban(), is_admin_ip(), preg_match_wildcard() and friends) have been removed. They were unprefixed and declared unconditionally; any code calling them must be updated.
  • BREAKING: The option rows are renamed. banned_options is now wp_ban_options, banned_stats is now wp_ban_stats, and ban_db_version is replaced by wp_ban_version. The ten pre-2.0.0 rows are folded into those three automatically and then deleted.
  • NEW: Settings moved to the Settings API, under Settings -> Ban, split across three tabs: Stats, Settings and Templates. All three write one option row, and saving one leaves the other two untouched.
  • NEW: Ban stats are now a sortable, paginated list table with bulk delete. The old table rendered every recorded address on a single page.
  • NEW: IPv6 IP ranges are supported.
  • NEW: A Header That Contains The IP setting naming the one header to trust, plus the WP_BAN_TRUST_PROXY constant and wp_ban_trust_proxy filter.
  • NEW: wp_ban_capability, wp_ban_denied, wp_ban_enabled, wp_ban_ipaddress, wp_ban_protect_self and wp_ban_status_code hooks.
  • NEW: A wp ban WP-CLI command: list, add, remove, check, stats and reset. wp ban check <ip> reports whether an address would be banned and by which list, which is the quickest way to find out what a wildcard or a range actually covers.
  • NEW: Dropped jQuery; the admin script is vanilla JavaScript.
  • NEW: The ban check no longer runs for WP-CLI or cron.
  • CHANGED: Restructured into includes/, with every class prefixed WP_Ban_.
  • CHANGED: The ban stats row is no longer autoloaded, so an unbounded list of every address ever turned away is no longer read on every page view.
  • FIXED: A malformed IP range banned every visitor. ip2long() returns false for an unparseable bound, and PHP compared the address against that boolean as true.
  • FIXED: IPv6 ranges silently matched nobody.
  • FIXED: Network activation and multisite uninstall fatalled, because wp_get_sites() was removed in WordPress 5.1. Both now page through every site rather than stopping at the hundredth.
  • FIXED: Ban entries were stored HTML-escaped, so a referrer pattern containing & could never match a real Referer header, and re-saving compounded it. Existing entries are repaired by the upgrade.
  • FIXED: The banned message was stored slashed and unslashed on every read. The upgrade corrects the stored value.
  • FIXED: Bans stopped applying entirely when proxy headers were trusted and none was present, or when the visitor’s address was on a private network.
  • FIXED: The banned message preview was readable by any logged-in user, including subscribers. It now requires manage_options and a nonce.
  • FIXED: Self-ban protection only worked if your username was literally “admin”. It now protects whoever is saving.
  • FIXED: The settings row was never removed on uninstall.
  • FIXED: The plugin no longer hardcodes its own directory name, so it works installed under any folder.
  • FIXED: Various PHP 8 warnings and deprecations.

Try other plugins

WooCommerce Shipping & Tax icon

WooCommerce Shipping & Tax

2.1 · 500K+ installs

WooCommerce Shipping & Tax offers automated tax calculation, shipping label printing, smoother payment setup, and other hosted services…