Wordpress

Unit test WordPress plugins like a ninja (in progress)

Unit testing a plugin can be easy, but if the plugin needs dashboard configuration or has dependencies on other plugins, it can quickly go off the tracks. And if you haven’t setup Travis integration, you’re missing out. Activate Travis CI To start with, go sign in to Travis now and activate your repos for testing. If you’re […] » about 300 words

How to identify context inside the WordPress dashboard

On wp-hackers, Haluk Karamete asked:

on admin pages, how can I detect that the current admin is dealing with a cpt?

Andrew Nacin answered:

get_current_screen()->post_type.

[But] this will also specify a post type when it’s a taxonomy being edited. To filter that out, ensure that get_current_screen()->base == 'post', which is [true] for edit.php, post-new.php, and post.php (for all post types).

Haluk didn’t elaborate on the cause of the question, but the answer is very good advice for those seeking to conditionally enqueue JS and styles only for specific post types.

Detect MySQL’s “too many connections” error

WordPress appears to continue with execution even when MySQL refuses connections/queries after init. Here’s a comment in the MySQL docs suggesting how to detect the condition in raw PHP:

$link = mysql_connect("localhost", "mysql_user", "mysql_password");
if (mysql_errno() == 1203) {
  // 1203 == ER_TOO_MANY_USER_CONNECTIONS (mysqld_error.h)
  header("Location: http://your.site.com/alternate_page.php");
  exit;
}

Just a note to myself, but I wonder if there’s opportunity here.

Speeding up MySQL joins on tables with TEXT columns, maybe

The thing about WordPress’ DB schema is that TEXT and VARCHAR content is mixed in the posts table (to say nothing of the frustrations of DATETIME columns). That’s not such a problem for a blog with a few hundred posts, but it’s a different matter when you have a few hundred thousand posts. And it wouldn’t even […] » about 500 words

Testing apply_filters() times

Testing how long it takes to assign a variable versus assigning through WordPress’ apply_filters(). Filters are core to WordPress, but I haven’t yet looked at the total number of apply_filters() calls used throughout the code. The answer to this question is that calling a non-existing filter before assignment is about 21 times more costly than […] » about 300 words

On wp_enqueue_scripts and admin_enqueue_scripts

An argument has erupted over the WordPress actions wp_enqueue_scripts and admin_enqueue_scripts vs. init. One of the points was about specificity, and how wp_enqueue_scripts and admin_enqueue_scripts can reduce ambiguity. I didn’t realize I had strong opinions on it until the issue was pressed, but it turns out I think wp_enqueue_scripts and admin_enqueue_scripts are unnecessary and unfortunate additions […] » about 300 words

Happy New Scriblio!

The most recently released, stable version of Scriblio is marked 2.9-r1 and was last updated in June 2010. You can be forgiven for thinking development had ceased in the interim. Today, however, I’m proud to introduce a completely new Scriblio, re-written from the ground up to take advantage of the latest features of WordPress and eliminate the mistakes […] » about 600 words