Merging Multiple `WP_Error` Objects into One Object

Let’s say you have a function that does two things:

function my_func() {
    $a = a();
    $b = b();
    if( is_wp_error( $a ) || is_wp_error( $b ) ) { return FALSE; }
    return TRUE;
}

That’s a little cumbersome, because if it returns `FALSE`, I’m left unable to tell which failed: `$a` or `$b`, or both.

Here’s what we can do instead:

function my_func() {
	$a = a();
	$b = b();
	$maybe_errors = new WP_Multi_Error( array( $a, $b ) );
	if( $maybe_errors -> is_wp_error() ) {
		return $maybe_errors -> get_error();
	} else {
		return TRUE;
	}
}

So what happened there?

I’ve got a custom class, `WP_Multi_Error`, that extends `WP_Error`. You can pass it an array with any number of members, of any type. It loops through them and, for any that are error objects, it merges them together into one error.

Here’s the gist:

more… Merging Multiple `WP_Error` Objects into One Object

PHPUnit on MAMP: The Last Boss

I tend to get beat up really badly whenever I have to do anything involving MAMP, the command line, OSX — basically anything environmental. I get the feeling I was supposed to learn this stuff when I was fourteen. Therefore, learning to run PHPUnit on MAMP has been painful for me, and I assumed all along that I was screwing up some … command line … thing.

Turns out, code is code. My problem was in the bootstrap.php that wp-cli created all along. Once I stopped staring off into the distance wondering why phpunit wasn’t working, and got back to actually, you know, reading and writing code, I found the problems. I had to make two customizations, and I haven’t seen either one discussed in the popular tutorials for this subject. Here’s the gist:

more… PHPUnit on MAMP: The Last Boss

Let’s See if WordPress Embeds Work in 4.4…

( pastes in url, http://scottfennell.com/japan/slr-090/ )

SLR 090

The CSS3 `:not( :last-child )` Selector is the Best

I used to do stuff like this a lot:

.post > * { margin-bottom: 20px; }
.post > :last-child { margin-bottom: 0; }

But now that we’ve dropped support for IE8, I can do this:

.post > :not( :last-child ) { margin-bottom: 20px; }

Cherish these moments.

Adding a Draggable/Sortable Multi-Checkbox Control to the WordPress Customizer

Justin Tadlock has made the world an offer: Come up with an idea for a new control in the WordPress customizer, and he’ll provide some help in coding it, or suggest a contact who perhaps can. Today, he blogged about a multi-checkbox control, which I have been working on lately as well. My example incorporates a sortable/draggable interaction that I’d like to add to the discussion via a brief tutorial.

When I say draggable/sortable, I am referring to the jQueryUI interaction. Here’s how it would look when we’re done:

more… Adding a Draggable/Sortable Multi-Checkbox Control to the WordPress Customizer