Front-end Editor: Version 2.2

Editable groups

It’s now possible to create arbitrary groups of editable elements. This opens the door for a lot of possibilities. For example, you can now edit all fields of a post at once, instead of one at a time. Go to the FEE settings page to enable it.

Post creation

One feature that was often requested was the ability to create posts from the front-end, not just to edit them. This is now possible by using the fee_inject_dummy_post() template tag.

Aloha 0.20

This release features the most recent version of Aloha Editor available, 0.20.0-RC9. This fixes the jQuery compatibility issues, as well as a bunch of other bugs. Thanks again to Jotschi for lending a hand with this.

Thanks to AppThemes and Jason Buksh for supporting this release financially.

Happy holidays!

The Magic of WP_User

In previous versions of WordPress, when you called get_userdata() or get_user_by(), you got a plain stdClass object, filled with all the fields from both wp_users and wp_usermeta tables. This had two disadvantages:

  • dashes were removed, so that ‘my-custom-field’ became ‘mycustomfield’
  • all fields were loaded and kept in memory, wasting precious resources

Since WordPress 3.3, all user-related functions return WP_User instances. This class has some magic methods that make it behave as if it contained all the custom fields.

Accessing a single custom field

For example, let’s try to display the user description of the currently logged in user:

$current_user = wp_get_current_user();
 
if ( isset( $current_user->bio ) )
	echo '<p>' . $current_user->bio . '</p>';

This code works fine both in WP 3.2 and in WP 3.3. The difference is that in WP 3.3 that code is equivalent to this:

if ( $current_user->__isset( 'bio' ) ) )
	echo '<p>' . $current_user->__get( 'bio' ) . '</p>';

Internally, the __isset() and __get() methods call get_user_meta().

If you have a variable key or a key with dashes, there are prettier aliases which you can use:

if ( $current_user->has_prop( 'my-field' ) ) )
	echo '<p>' . $current_user->get( 'my-field' ) . '</p>';

Accessing all custom fields

Unfortunately, iterating over all the custom fields by casting to an array isn’t possible anymore:

foreach ( (array) $user as $key => $value ) {
	var_dump( $key, $value );
}

It will have to be replaced with this:

foreach ( get_user_meta( $user->ID ) as $key => $values ) {
	var_dump( $key, $values );
}

Note that, in the later case, $values is an array.

When economists base their models on their fantasies of an “economic man” motivated only by self-interest, they forget community – the all-important web of meaning we spin around each other – the inescapable context within which anything truly human has taken place

Christopher Ryan and Cacilda Jetha

Easier way to update submodules in git

I love using git submodules to avoid duplicating common code. Unfortunately, updating a submodule reference to the lastest revision is a chore:

cd framework
git checkout master
git pull
git submodule update --init --recursive
cd ..

However, we can store all of those commands using a git alias:

git config --global alias.up-sub '!f() { cd $1 && git checkout master && git pull && git submodule update --init --recursive; }; f'

Now, to update the ‘framework’ submodule, we can just do:

git up-sub framework

I picked up the trick for running multiple commands in an alias from this article on the Mozilla blog.

Update Use && instead of ; to prevent losing work when you mistype the submodule name.

Posts 2 Posts: Version 1.1

I’m pleased to announce that the Posts 2 Posts plugin now also supports posts-to-users connections. (It supports users-to-users connections as well, but there’s no UI for them).

This is made possible by a new p2p_type column on the wp_p2p table, with which we can clearly distinguish between user ids and post ids. If you’re upgrading from a previous version of Posts 2 Posts, all the existing connections will be automatically updated to have the correct value for this column.

For the next version, I’m thinking of supporting connections between posts on different blogs in a multisite network.