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;
}

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=""

Install PHP 5.3 with Homebrew on 10.6 Snow Leopard

Update
Please use the PHP formula at homebrew-php. This formula is updated and tested by many more users, and should be considered the go to forumla for PHP. You can also find additional PHP related formulae over at the homebrew-php repository.

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