Handy redirect for WordPress

This is a handy little wrapper around wp_redirect I use in functions.php. Most of the time when using wp_redirct I want PHP to exit, so thats what the following function does, and while we’re at it why not throw in the ability to accept a post ID or a uri for the location.

/**
 * A handy wrapper to wp_redirect which exits after calling wp_redirect.
 * $location can be a url or a post id.
 *
 * @param string|integer
 * @return bool False if $location is not set
 */
function wptf_redirect( $location = '', $status = 302 ) {
	$permalink = false;

	if( is_int( $location ) ) {
		$permalink = true;
		$location = get_permalink( $location );
	}

	if ( ! $location ) {
		return false;
	}

	if( ! $permalink ) {
		$location = ltrim( $location, '/' );
		$location = '/'.trailingslashit( $location );
		$location = get_bloginfo( 'url' ).$location;
	}

	wp_redirect( $location, $status );
	exit;
}

Mute Screamer 1.0 released

Following the latest release of WordPress comes the latest version of Mute Screamer.

Get your copy or update via the WordPress admin.

The biggest change in this release is ip banning and attack throttling.

You can configure Mute Screamer to ban clients when an attack is over the specified ban threshold. For attack throttling clients will be banned after a specified number of repeated attacks.

New features

  • IP banning
  • The ability to add fields to the exclusion list while on the intrusions page
  • Email spam prevention

Other updates include:

  • i18n support
  • Updated 500.php template

Have a look at the change log for the full list of improvements and enhancements.

Snow Leopard 10.6.5 and apachectl

I just upgraded to 10.6.5 and noticed that apachectl stops working properly. When I run apacheclt now it gives me this error:

/usr/sbin/apachectl: line 82: ulimit: open files: cannot modify limit: Invalid argument

The problem seems to be with the ULIMIT variable in the shell script:

ULIMIT_MAX_FILES="ulimit -S -n `ulimit -H -n`"

I think the problem is that ulimit returns “unlimited” which cannot be used in the command ulimit -S -n, so I just changed the ULIMIT back to what it was before upgrading to 10.6.5:

ULIMIT_MAX_FILES=""

Mute Screamer 0.58

This release added support for automatic updates from phpids.org, this means you don’t have to wait for Mute Screamer to be updated to get the latest rules and converter for PHPIDS.

The update process will check phpids.org for changes to default_filter.xml and Converter.php. If an update is found it will be displayed on the Updates page in the WordPress admin.

As we are updating Mute Screamer core files we want to be very careful about what is to be updated. That is why when going through the update process you will be shown a diff of the changes to be applied to either default_filter.xml and/or Converter.php.

This lets you see exactly what is going to be changed and gives you a chance to review the changes to make sure they are legit. It was also a good excuse to use the diff engine included in WordPress that is used for comparing post revisions. As always have a backup of your site before running any updates.

Download Mute Screamer

Install PHP 5.3 with Homebrew on 10.6 Snow Leopard

Update
adamv’s homebrew-alt repository is a good source for duplicate formulae and has a PHP formula, much like this one.
The great thing about homebrew-alt is that you can find other useful formulae and they are all in the one place.

Here are some notes on installing PHP 5.3.3 (the latest version at time of writing) with Homebrew, an awesome package manager for OS X.

  1. If you haven’t done so already, install Hombrew. Check out the installation instructions over at the Hombrew wiki.
  2. Grab the latest copy of my PHP brew and copy it into your Homebrew Formula directory.
    curl -O https://raw.github.com/ampt/homebrew/php/Library/Formula/php.rb
    mv php.rb `brew --prefix`/Library/Formula
  3. To see the available options:
    brew options php
  4. Run the brew install php command. The following will install PHP with Apache and MySQL support.
    brew install php --with-apache --with-mysql

    Or if you want to install php-fpm:

    brew install php --with-fpm

    Update: You can also just:

    # How much do you trust me...
    brew install https://raw.github.com/ampt/homebrew/php/Library/Formula/php.rb --with-apache --with-mysql

Once thats done you should be good to go.

Note: Depending on your setup you may want to add the following to your .bash_profile:

echo 'export PATH='`brew --prefix php`'/bin:$PATH' >> .bash_profile

This will ensure that BASH has the correct path to the PHP you just installed.

Bonus Points: xdebug

Install xdebug (there’s a brew for that) a great tool to help debug your PHP code:

brew install xdebug