WordPress License Plates

I moved my “IM STIG” license plates over to my Dodge Viper so I had to get new plates for my Ford Mustang. What to get on my plates this time around seemed like an obvious choice! :)

WordPress License Plates

UPDATE: It looks like I’m the fifth sixth person to get WordPress license plates! Ryan Duff (Pennsylvania), Jonathan Dingman (California), Michael Torbert (North Carolina), AJ Morris (Michigan), and Jesse Friedman (Rhode Island) also have them. Awesome. :cool:

JW FLV Player Removed From My “Viper’s Video Quicktags” Plugin

JW FLV Player has been removed from the latest version of my Viper’s Video Quicktags plugin. The player is not compatible with the GPL license and as a result cannot be included in plugins that are hosted in the WordPress.org plugin repository. I shouldn’t have added the player to my plugin in the first place but it was the only decent player at the time oh so many years ago. Today I have rectified that mistake by removing it from my plugin’s download.

However do not fear — I have not actually removed the functionality, I just no longer bundle it with my plugin. If you wish to continue to use the player to embed .flv and .mp4 files after upgrading to version 6.4.0 of my plugin, you will need to download this ZIP file and extract it to your wp-content folder, resulting in /wp-content/jw-flv-player/player.swf. I’m hosting the ZIP file since my plugin uses an old version of the player that is no longer available for download from the official site.

This is a temporary band-aid fix. The eventual plan is to switch to the GPL-licensed Flowplayer but that won’t happen until I complete the latest recode of my plugin which introduces many much-needed features. Whether I’ll actually ever finish version 7.0 of my plugin is another matter though.

If you have any questions or need any help, please post over on the Viper’s Video Quicktags page.

Calling iPhone App “Gas Cubby” Users — I Need Your Help!

Do you use Gas Cubby on your iPhone? If so, would you mind helping me out by sending me an export of your data?

I’m writing a new WordPress plugin that will allow you display data similar to Gas Cubby’s data on your website. You’ll have the option to manually enter gas fillups and such, but you’ll also be able to import from the Gas Cubby app. I’ve been using my data as a test and it’s working great but I’d appreciate being able to use a larger sample size.

If you’d like to help me out, here’s how:

  1. Open up Gas Cubby and press the left arrow until you get to “All Vehicles” shown at the bottom.
  2. Tab the magnifying glass in the upper-left so that it says “Search” at the top.
  3. An “Export” button will now be shown in the upper-right. Press it.
  4. An e-mail prompt will show up. Send the e-mail to “gascubby” at this domain (viper007bond.com).

While there isn’t really any personal data in the export file other than perhaps your gas station location if you fill that in, I still promise not to share this information with anyone. I’ll only be using it for testing in my local machine’s WordPress installation.

Thanks!

wp_list_pluck() Is An Awesome WordPress Function

If you’re a WordPress developer and you don’t know about wp_list_pluck(), then listen up!

Say you have an array called $posts that contains this:

[0] => stdClass Object
	[ID] => 675
	[post_author] => 5
	[post_date] => 2010-07-25 19:40:01
	[post_date_gmt] => 2010-07-25 19:40:01
	[post_content] => This site is using the standard ...
	[post_title] => About The Tests

[1] => stdClass Object
	[ID] => 501
	[post_author] => 6
	[post_date] => 2010-08-01 09:42:26
	[post_date_gmt] => 2010-08-01 16:42:26
	[post_content] => The last item in this page's content ...
	[post_title] => Clearing Floats

[2] => stdClass Object
	[ID] => 174
	[post_author] => 5
	[post_date] => 2007-12-11 16:25:40
	[post_date_gmt] => 2007-12-11 06:25:40
	[post_content] => Level 1 of the reverse hierarchy test ...
	[post_title] => Level 1
	)

[3] => stdClass Object
	[ID] => 173
	[post_author] => 5
	[post_date] => 2007-12-11 16:23:33
	[post_date_gmt] => 2007-12-11 06:23:33
	[post_content] => Level 2 of the reverse hierarchy test.
	[post_title] => Level 2

How would you go about getting all of the post_title values? Well obviously you could do something like this:

$post_titles = array();
foreach ( $posts as $key => $post ) {
	$post_titles[$key] = $post->post_title;
}

Sure, it’s not that complicated but that can get repetitive in your code. So how about this instead?

$post_titles = wp_list_pluck( $posts, 'post_title' );

Much easier, right? :)

Thanks Michael Fields for reminding me about this great function!

How To Remove (Or Change) “Private” Or “Protected” From WordPress Post Titles

If you make a post private in WordPress, the post’s title with be prefixed with “Private”. The same will happen if you password protect the post, although it will be prefixed with “Protected”. If you’d like to remove these, just add the following code to your theme’s functions.php file:

add_filter( 'private_title_format', 'yourprefix_private_title_format' );
add_filter( 'protected_title_format', 'yourprefix_private_title_format' );

function yourprefix_private_title_format( $format ) {
	return '%s';
}

The above code will remove the prefix by changing the format from Private: %s and Protected: %s to just %s where %s is the existing post title.

If you’d like to change it to something else, you can just change what the function in my example returns. If you want to change them independently of each other, then you’ll need to use two separate callback functions.

How To Create Custom WordPress Cron Intervals

This is mostly a reminder for myself so I can stop tracking it down every time I forget, but here’s how to have WordPress code execute on a different schedule than the default intervals of hourly, twicedaily, and daily. This specific example is for weekly execution.

<?php

// Add a new interval of a week
// See http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules
add_filter( 'cron_schedules', 'myprefix_add_weekly_cron_schedule' );
function myprefix_add_weekly_cron_schedule( $schedules ) {
	$schedules['weekly'] = array(
		'interval' => 604800, // 1 week in seconds
		'display'  => __( 'Once Weekly' ),
	);

	return $schedules;
}

// Schedule an action if it's not already scheduled
if ( ! wp_next_scheduled( 'myprefix_my_cron_action' ) ) {
	wp_schedule_event( time(), 'weekly', 'myprefix_my_cron_action' );
}

// Hook into that action that'll fire weekly
add_action( 'myprefix_my_cron_action', 'myprefix_function_to_run' );
function myprefix_function_to_run() {
	// Add some code here
}

?>

On a side note, I believe this must go in a plugin and not your theme’s functions.php which I hear loads too late.

Help Me Name My Latest Plugin

I’m having trouble coming up with a good name for my latest WordPress plugin so I thought I’d crowd source it. :)

My other WordPress-powered site, FinalGear.com, receives very large traffic spikes. I used to just run WP Super Cache to prevent the site from going down but Apache would still actually die under the load even though it was just serving static content. Since the site has no comments or other often changing content, the easiest solution at the time was just to throw a reverse proxy called Varnish in front it with a decent cache time (5-10 minutes per page). I’ve since switched from Apache to nginx which solves that issue but it’s still easiest to just leave Varnish there.

Varnish is set up to ignore cookies on the front end of the site. That means I get served the exact same version of the site that you (a guest) sees — no admin bar, no post edit links, and so forth. Getting to the admin area is easy thanks to an absolutely positioned hidden link in the bottom left of the site (hover over it, you’ll find it) so lack of an admin bar is no problem for me.

What is a problem though is the lack of easy way to edit a post. I currently have to go into the admin area and then browse to the post in order to edit it. So I wrote a plugin that outputs the edit post link even for people who aren’t logged in. However the link is hidden using CSS and then re-shown using Javascript only if you have a logged in cookie.

It works perfect but what to call it? My working title was “Javascript Edit Links” but that seems so bland and locks me a bit into a corner. What if I someday want to add other features to the plugin, such as even showing the full admin bar? Do you have any better ideas?

Translating Strings In WordPress Containing Multiple Placeholders

I really often see a common mistake made when translating strings in WordPress so I thought I’d write a blog post in order to shed more light on the issue.

But first, here’s a quick refresher on how to internationalize code in WordPress:

<?php _e( 'Welcome to my blog!', 'my-plugin-text-domain' ); ?>

For dynamic strings, it’d be something like this:

<?php printf(
	__( 'Welcome to my blog, %s!', 'my-plugin-text-domain' ),
	$name
); ?>

But what about when you have multiple variables to use in your string? A common mistake is to do something like this:

<?php printf(
	__( 'Welcome to my blog, %s! Today\'s date is %s.', 'my-plugin-text-domain' ),
	$name,
	$date
); ?>

The issue with this is that you’re requiring the person’s name to always come before the date. If for internationalization reasons it needs to be in a different order, then it won’t work. You’ll end up with something like Today's date is Alex. Welcome to my blog, November 2nd!.

The solution is to use standard sprintf() argument swapping parameters:

<?php printf(
	__( 'Welcome to my blog, %1$s! Today\'s date is %2$s.', 'my-plugin-text-domain' ),
	$name,
	$date
); ?>

Now translators are free to re-order the string to whatever makes the most sense for the language in question without having to worry the order of the variables.

For a more in-depth review of this, check out the WordPress Codex where many real world examples can be found.