Skip to navigation | Skip to content



Blog

WordCamp UK 2010

I’m just back from WordCamp UK 2010 in Manchester. Another inspiring gathering of WordPress people, from the curious to the obsessed, with a fantastic, vibrant city as the backdrop.

I’m too exhausted now for a detailed write-up, but I want to jot some things down while they’re fresh. Here’s the main things that stick in my mind…

Themes

There was a lot about themes. Much discussion of the debate about the Thesis premium theme’s apparent flaunting of the WP GPL license (check Mark Jaquith’s post for the best overview of this heated debate).

WP stalwarts Michael Kimb Jones and Jonny Allbut took us around the world of premium themes, free themes, theme frameworks… and on that last note, introduced the beta of their new WP theme framework, Wonderflux.

I’m still agnostic about theme frameworks. Myself, I have a basic “theme foundation”, which I keep improving and tweaking, and is my lightweight starting point for all my custom themes.

There’s been a great discussion on theme frameworks at digwp.com, and I was interested to see how many people concur with my approach (don’t we all like loads of people agreeing with us? ;-). That said, there were some good arguments for frameworks. Most framework advocates seemed to favour Justin Tadlock’s Hybrid, which is definitely something I’m looking at. Justin’s code and attitude are usually impeccable, and everyone says his premium support rocks.

Wonderflux seems like another possible contender to check out—Jonny Allbut likewise is a fully-fledged WP believer with a great attitude and a good head for code. If I start doing larger projects more regularly for clients who are keen on easily upgrading their theme to support the latest WP features, I’ll start building with one of these frameworks. There’s a bit of a learning curve involved, but really there’s only one way to find out if it’s worth it…

One thing for my own stripped-down theme foundation, though. Jonny stressed that even if you’re not using frameworks, you should definitely be using child themes (the mechanism at the root of most theme frameworks). I suspect he’s right. I’ll be looking into this soon.

Plugins

Michael Kimb Jones’ session on good plugins was very informative, although it was a shame there wasn’t time for the audience to chip their suggestions in. The best summary is a list of the ones I thought stood out:

  • Import HTML Pages. A nifty way to quickly convert a flat HTML site to WordPress.
  • WP Table Reloaded. Apparently imperfect (of course) but much-needed improvement on the hideous table editing with TinyMCE.
  • Mingle. Seems like “BuddyPress Lite”—social networking features for a single-site installation of WP.
  • White Label CMS. Allows some client-friendly mods to the WP admin area (logos, hiding unused menus, etc.).
  • WP CMS Post Control. More control over the WP admin area, configuring what boxes appear for different users.
  • Gravity Forms. You pay for it, but there was a lot of positive feeling for this powerful but very user-friendly forms plugin.

BackPress

I missed lead WP developer Peter Westwood’s session on BackPress, but it sounds like a great project. It’s seems to be a library of functionality for web applications, based on WP, but stripped-down. The beauty of this is that you can now build your own apps making use of your knowledge of mega-useful WP stuff like the wpdb class, user management, taxonomies, etc.

WordCamp UK?

Unfortunately things ended on a bit of a sour note during the final discussion.

Last year in Cardiff there was a discussion about whether there should be a more “corporate” element to the gathering, with paid training sessions and seminars. WordCamp regulars rightly objected strongly, while stressing that they had nothing against this kind of thing happening—just not under the “WordCamp” banner. There was talk of splitting off some sort of “WordCon”, but I’ve not heard anything more of this.

This year, the heated debate came when we started discussing WordCamp UK 2011. Jane Wells, who’s been doing some amazing user interface work on WordPress at Automattic over the past few years, chimed in to remind us that the ethos of WordCamps is about being local and decentralized, and that a WordCamp UK is going against this. There was the strong suggestion that they (the WordPress Foundation I guess, who own the WordCamp trademark) might crack down and stop such a national gathering using the WordCamp name. There was, to put it mildly, a lot of resistance, from the eminently reasonable to the rather annoyed (thankfully the arguments never actually got ugly, just pointless).

Now, I think everyone’s intentions here are good, and I think it should all work out in the end, despite that thing about the road to Hell. Jane genuinely wants to keep a local flavour to WordCamps, a philosophy which has a tremendous amount going for it. However, I think there’s an element here of the sociogeography of America being applied in a very different country with inappropriate rigour.

WordCamp USA would indeed be a humungous thing, which would tend towards becoming depersonalized, and alienate a lot of people purely through the vast distances involved. City-based WordCamps are the obvious, natural format. Jane mentioned—to stress that this wasn’t just being down on the UK—that they have similar situations in India, China and Australia. Again, I can’t see how these countries’ geographic dynamics can be applied on this little island.

WordCamp UK has so far been held in Birmingham, Cardiff and Manchester. It’s kind of nice it not being in London. I live in London, but this is the other factor that, together with the island’s small size, changes things a bit. London dominates, often too much. Touring a nice little conference around other parts of the country seems to be a great way of bringing a good WordPress vibe to these places. And it really doesn’t feel like it’s some “central” authority bestowing itself upon the poor provinces. It feels like a localized event, infused with other parts of the country in the way that is possible in this dense, small country, and which makes it what it is.

Anyway, I don’t want to press this. I think the worst-case scenario is that what is now WordCamp UK gets “rebranded”. Hopefully if it has to break with the WordCamp trademark, it won’t break with the “semi-organized BarCamp” ethos. I actually think this is next to impossible, as the core organizers are so committed to this. If we have to “fork” WordCamp to create a touring national WordPress event, it would be entirely wrong to see it as a break with the open and informal attitude of WordCamp—they don’t have a trademark on that. There’s no reason why we can’t mix this attitude with a healthy cross-pollination of people from many different places. There were quite a few Scandinavians there this weekend, because the WordPress community there hasn’t kicked off any meetups or WordCamps yet. There’s room for this kind of thing in the UK, in Europe, because it’s good and it’s possible.

Jane seemed set in the idea that having a WordCamp UK was placing this event as “bigger” and “better” than any city-based WordCamp that was set up in the UK. I think this was her major mistake. I don’t think a soul in the room had ever even thought like this. I can immediately see what’s “better” about a completely localized meetup (which, strangely, we don’t have in London). I can also see what’s “better” about a national event. When two things are both “better”, neither’s better—they’re just different. Wouldn’t stopping one of them reduce diversity? I think it would, so it’ll probably carry on, by whatever name necessary.

Solving WordPress problems

I periodically get queries about WordPress issues through this site, often in relation to code I’ve posted here. These days I’m usually far too busy to go into deep, free coding consultation; and usually when I do help out I’m just Googling and using the same resources available to everyone.

I totally appreciate that I might have much more experience than some people, and I’ll have a few little hints that could save a lot of time. But sometimes people emailing me seem to be doing something that I fully confess to being guilty of, in the past and even now: shouting out for help too soon instead of stepping back and tackling the problem properly.

So, here’s a little guide I can point people to, partly in lieu of an email reply template. If you’re facing a WordPress coding problem that either looks daunting right from the start, or is driving you insane after hours of trying, the following hints can help a lot.

Read more »

Enforce strong WordPress passwords

Here we go with some more nifty code for you WordPress developers… As ever, this code is roughly tested but probably not for novices. It’s designed to drop into a custom theme’s functions.php file. It probably should be a plugin, and it might make it one day when it’s thoroughly tested and I get time…

Anyway, it’s a solution to a problem that I’m very surprised isn’t built into the WP core (as an option at least), and isn’t addressed by any easily found plugin or code already out there. As we know, WP provides a good “password strength meter” on the user profile page, which is great as strong passwords are (or should be) one of the first lines of defence against attacks on your site. But it’s just an indicator—there’s nothing stopping someone using “password” as their password, or something dumb like that. All you need is one Administrator or Editor with a dumb password, and the whole site is highly vulnerable.

How about a little enforcement?

Read more »

Compare the WordPress post date

I find PHP’s date handling a bit confusing. It’s easy when you know how, of course; but even at the same time as appreciating that it’s good in the end that it offers a lot of flexibility, it’s sometimes seemed like there are too many hoops to jump through to do some simple date operations.

Anyway, I’ve just cracked a minor issue I’m working on thanks to this post and this thread. I’m posting the solution here for my quick reference as much as anything…

Problem: how to check if a WordPress post_date (from a $post object) is from a day in the future? Solution:

$postDate = strtotime( $post->post_date );
$todaysDate = strtotime( date( 'Y-m-d' ) );
if ( $postDate > $todaysDate ) {
	[ post is from the future! ]
} else {
	[ post is from today or the past]
}

Adding scripts to the WordPress login or registration form

Most WP developers know by now that the right way to add script libraries from a plugin or theme is to use the wp_enqueue_script function. It makes sure scripts aren’t loaded more than once, and so on.

However, I just had some problems getting some jQuery to run on the login / registration form. I used wp_enqueue_script like a good WP developer but… no go. Where’s my jQuery?

It seems the answer lies in the fact that after scripts are enqueued in a normal WP page, they get spit out by something inside the call to wp_head(). I guess you could add wp_head() to the login header, but who wants all those redundant plugin scripts and styles that (presumably) aren’t even meant to be there.

After a bit of diggiing around it seems that the solution is the wp_print_scripts() function. So, to get jQuery working on the login form, put these lines in the code you hook onto login_head:

wp_enqueue_script( 'jquery' );
wp_print_scripts();

Easy child page creation for WordPress

Here’s a quickie that can help with WordPress sites that have a lot of pages. If some of the pages have longish titles, the “Parent Page” drop-down on the edit page screen can get unwieldy. The scroller for the drop-down can run off the right side of the screen.

OK, it’s fine (often easier) to use the keyboard to navigate drop-downs. But not everyone knows how to, and even so, with a large amount of pages, selecting the right parent can become a pain.

I think I adapted the following code from a plugin or someone else’s post. Thanks whoever you are, but frankly I’m so busy at the moment I’ve forgotten where it came from! Anyway, if you drop the following into your custom theme’s functions.php, you’ll get a new “Create child” link under every page listed in WP admin, when you hover over the title:

function slt_childPageAction( $actions, $page ) {
	$actions["create-child"] = '<a href="/wp-admin/page-new.php?parent_id=' . $page->ID . '" title="Create a new page with this page as its parent">Create child</a>';
	return $actions;
}
add_filter( 'page_row_actions', 'slt_childPageAction', 10, 2 );
function slt_setChildPage() {
	global $post;
	if ( $post->post_type == "page" && $post->post_parent == 0 && isset( $_GET["parent_id"] ) && is_numeric( $_GET["parent_id"] ) )
		echo '<script type="text/javascript">jQuery( document ).ready( function($) { $("#parent_id").val("' . $_GET["parent_id"] . '"); } );</script>';
}
add_action( 'edit_page_form', 'slt_setChildPage' );

The first bit adds the page action link. The second bit adds some jQuery to the right edit screen to set the specified parent, if it’s been passed. I couldn’t find another way to set the drop-down… Well, it works!

Formatting a string with optional elements

I’ve often found myself writing little bits of code to format strings with optional elements. The classic example is outputting the company someone works for, together with their position in that company—if the position is given. The format if both are given is:

[position], [company]

If the position isn’t given, you just output the company. Without, obviously, the comma. It’s a trivial thing to code, but on a current project I’ve found myself doing it in several different places. Of course, this suggests there should be a function written for it.

Ideally the function should be able to cope with any number of optional elements. With PHP’s func_get_args(), it’s easy:

function formatOptionalText( $delimiter ) {
	$elements = array_slice( func_get_args(), 1 );
	$text = "";
	$i = 0;
	foreach ( $elements as $element ) {
		if ( trim ( $element ) ) {
			if ( $i && $text ) $text .= $delimiter;
			$text .= $element;
		}
		$i++;
	}
	return $text;
}

Note that you have to pass a delimiter first, and you should include a space if necessary (e.g. ", "). After that, pass any number of strings and they’ll be output without gaps.

Control your own WordPress custom fields

I’m currently working on a client’s WordPress site where there’s quite a few bits of custom functionality in my custom theme that rely on them entering values for posts or pages using WP’s custom fields.

Custom fields are really flexible. However, they’re not perfectly user-friendly. For instance, if no post or page is currently using a custom field that you’ve built functionality on, the user has to enter the name as well as the value of the field the first time it’s used. The drop-down of field names is dynamically gathered from the fields currently in use. Also, sometimes you want to make things easier for clients by having inline tips, and inputs that suit the field (e.g. a checkbox or select drop-down instead of just a plain text entry).

So, I set about piecing together a way to take over the Custom Fields meta box…

Read more »

Get WordPress users by role

There’s a few posts around that reveal a nifty use of the WP_User_Search class that’s part of WordPress’ core code, in order to select all users that have a specific role (the trick seems to have originated with John Kolbert).

But… WP_User_Search is only loaded when you’re inside the WP admin area. What about front-end template code?

Read more »

New WordPress plugin: Lock Pages

I’m very please to announce my first WordPress plugin! It’s called Lock Pages.

The idea came from work with various clients where certain pages started to get moved around, or just vanished. A page can “move” by having its parent page or the slug changed. Sometimes clients would delete a page and replace it with an updated version which had a slightly different slug.

Of course, many of these things just stem from usually harmless habits picked up from working with files on a computer. But on a website, you want to persist your URLs as long as possible. Unless absolutely necessary, pages should be kept with the same permalink, to avoid breaking links and to maximize PageRank and such like.

Read more »

Archives