Bookmark and Share

Updating wp-ban to include bad URLs

Posted: Sunday, September 6th, 2009 at 12:52 amUpdated: Friday, September 11th, 2009 at 8:20 am

Step 2. Edit wp-content/plugins/wp-ban/wp-ban.php

  1. Open wp-content/plugins/wp-ban/wp-ban.php for editing using your favorite text editor.
  2. Somewhere after the following line
    add_action('init', 'ban_textdomain');

    add the following function definition.

    ### Function: Process Banned Bad URL
    ### http://www.microshell.com/website_internet/security/updating-wp-ban-to-include-bad-urls
    function process_ban_bad_url($banned_bad_urls, $against) {
    	// We should never ban wp-admin.
    	if(!empty($banned_bad_urls) && !preg_match('/^\/wp-admin/', $against)) {
    		foreach($banned_bad_urls as $banned_bad_url) {
    			// Let's never ban wp-admin URLs.
    			if (strstr($against, $banned_bad_url) !== false) {
    				print_banned_message();
    				break;
    			}
    		}
    	}
    }
    
  3. Find the function definition for banned() and add the following PHP line near the variable definitions.
    $banned_bad_urls = get_option('banned_bad_urls');
  4. Under the same banned() function definition, under the following block:
    if (!$is_excluded)

    add the following line:

    process_ban_bad_url($banned_bad_urls, $_SERVER['REQUEST_URI']);
  5. Find the function definition for ban_init() and add the following lines. I recommend adding them on the appropriate section within the function. However, if you add them anywhere in the function, it should be fine.
    // http://www.microshell.com/website_internet/security/updating-wp-ban-to-include-bad-urls
    $banned_bad_urls = array();
    
    add_option('banned_bad_urls', $banned_bad_urls, 'Banned Bad URLs');
    
  6. That’s about it. If you have any problems, then revert back to the original installation of wp-ban. You’re welcome to contact me. I hope I can help you debug the problem.

There you have it guys. I hope this article helps your blogging experience better. Please leave comments / suggestions / questions if you have. Iā€™m looking forward to improving my solution with your comments / suggestions / questions.

Pages: 1 2 3

2 Responses to “Updating wp-ban to include bad URLs”

  1. tygern8r Says:

    AWESOME!! Thanks for the work. I\’ve been getting nailed by some Koreans constantly trying the SERVER[DOCUMENT_ROOT] over and over again. Even though I\’ve banned them by IP, WP-Ban isn\’t banning them. Hopefully this will take care of them. If not, I\’ll just have to htaccess them.

  2. Maresa Says:

    Kewl šŸ™‚ Glad you like it …

Leave a Reply

Time limit is exhausted. Please reload the CAPTCHA.