Query Multiple Taxonomies: Version 1.1

This version finally brings something you can sink your teeth into, so to speak. I’m talking about the new taxonomy drill-down widget:

drill-down navigation

As you might notice from the screenshot, it works with hierarchical taxonomies too and lets you do queries like this:

?ingredients=flour+sugar&flavour=sweet

I would like to thank Matthew Porter for coming with the initiative and for sponsoring this release.

GSoC Proposal: Enhanced Admin Pages

I’m planning on applying as a GSoC 2010 volunteer for WordPress. This is a working draft of my proposal.

Introduction

One of the key features missing from the list-type administration screens is the ability to view items sorted by a certain column. For example, on the posts screen, you should be able to view posts sorted by number of comments, in descending or ascending order.

Besides this, when you view the next page of items, the entire page is reloaded, when the list of items could be updated via AJAX.

So, my proposal has two parts:

Sorting by column

All list-type screens in WordPress are paginated. In other words, only a small subset of all the items are loaded at a time. This throws JavaScript sorting scripts like DataTable out the window. The sorting has to be done on the server-side.

This is not a big problem, since WordPress already has support for sorting most types of items.

In terms of UI, I won’t go with the regular clickable column headers approach because it has a 3-click cycle:

  1. sorted-ascending
  2. sorted descending
  3. unsorted

Unlike with JavaScript sorting, each click would be expensive, since it would require a new request to the server.

Instead, I plan on adding a dropdown to the Screen Options section, where the user could select the column to sort by. There would also be two radio buttons for the order: ASC / DESC. This way, the user can choose the sorting and the order in one request.

Either that, or add two buttons on each column, one for ASC and one for DESC sorting (hidden until the user hovers over that column).

AJAX Loading

After sorting is done, I can concentrate on speeding things up with AJAX. Whenever a user wants to see a different page of items, they will be fetched via an AJAX request and be inserted in place of the old items.

This should also work when: changing the sorting, changing the number of items per page.

Feedback

What do you think? Thoughts, ideas, suggestions etc. are very welcome. Use the comment form bellow.

Front-end Editor: Version 1.8

Tooltip

The new tooltip appears whenever you hover over an editable area.

Jason G. Lemieux was kind enough to help position it and define it’s appearance.

If you don’t need it, you can disable it from the settings page.

Restyled buttons

This is also Jason’s doing. Aren’t they pretty? :)

Extendable JavaScript

The ability to define your own editable fields was present from the beginning. However, you weren’t able to extend the built-in field types, since they were defined in JavaScript.

Developers now have access to the FrontEndEditor JavaScript object which contains all the field type definitions, as well as additional data.

scbFramework: Version 1.5

I’ve recently learned that register_uninstall_hook() allows a single callback per plugin. This meant that if you were using both scbOptions and scbTable, for example, when a user uninstalled that plugin, either the option wasn’t deleted or the table wasn’t dropped.

This is now fixed by using a new method, scbUtil::add_uninstall_hook(). It also prevents multiple UPDATE queries to execute on each page load.

This also means that scbOptions, scbTable and scbBoxesPage now require scbUtil to work.

Other improvements:

  • new methods for scbOptions: get_defaults(); cleanup(); __isset();
  • new method for scbAdminPage: page_help();
  • scbAdminPage::submit_button() accepts an array of arguments
  • scbAdminPage can create top level menus
  • scbBoxesPage can assign the same handler to multiple boxes, with different arguments
  • debug() outputs at the end of the page, only for administrators

Here is the full changeset.

Smarter Navigation: Version 1.2

Two template tags have been added:

If you have posts in multiple categories, you can use get_referrer_category() to retrieve the category object, based on the referrer url.

get_referrer_url() returns the full URL of the referrer.

Also, there are two extra arguments for previous_post_smart() and next_post_smart(): $in_same_cat and $excluded_categories.

This is how the function prototype looks like:

previous_post_smart(
	$format = '« %link',
	$title = '%title',
	$fallback = true,
	$in_same_cat = false,
	$excluded_categories = ''
);

Front-end Editor: Common Mistakes In Themes

Although Front-end Editor tries to be compatible with as many themes as possible, there’s only so much it can do.

No wp_footer() call

Lots of plugins, including this one, rely on the wp_footer() call to include their JavaScript files. Open your theme’s footer.php file and make sure you have this line somewhere:

<?php wp_footer(); ?>

Using custom versions of jQuery

Some themes, for one reason or another, use their own jQuery file. When a new version of WordPress is launched, the bundled jQuery library is also updated, but the theme is stuck using it’s own, outdated version.

View the HTML source and make sure the path to jQuery looks like this: wp-includes/js/jquery/jquery.js.

Using the_title() in the wrong places

A mistake I see in a lot of themes is code like this:

<a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>

This causes all sorts of problems. You should use the_title_attribute() instead:

<a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>

No id & class attributes for dynamic sidebars

If you want to have editable widgets, you’ll have to change code like this:

register_sidebar(array('name' => 'My Sidebar',
	'before_widget' => '',
	'after_widget' => '',
	'before_title' => '<h4>',
	'after_title' => '</h4>',
));

to this:

register_sidebar(array('name' => 'My Sidebar',
	'before_widget' => '<div id="%1$s" class="widget %2$s">',
	'after_widget' => '</div>',
	'before_title' => '<h4>',
	'after_title' => '</h4>',
));

The important part is id="%1$s" class="widget %2$s".

Front-end Editor: Version 1.7

Let’s get right into it:

Post thumbnail switching

If your theme supports native thumbnails (introduced in WordPress 2.9), you will be able to change them by double-clicking on them.

Editable options

Similarly to editable_images(), you can now have editable bits of text anywhere in your theme. For example:

<?php editable_option('blurb'); ?>
 
[...]
 
Today's mood: <?php editable_option('mood'); ?>

It’s like text widgets, without the widgets. :-)

No more autogrow

If you’ve been using the basic text editor, you’ve probably had your share of frustration with the autogrow script. After switching from Autogrow to Growfield without much improvement, I’ve decided to stick to a normal textarea with a scrollbar.

The rich editor is not affected by this.

Configurable nicEdit

I’ve added two buttons to the rich editor panel: font-family and font-color. More importantly, you can now select which buttons you want to use. Just paste this code in your theme’s functions.php:

function configure_fee_nicedit($config) {
	$config['buttonList'] = array(
		'bold', 'italic', 'strikethrough',
		'left','center', 'right',
	);
	return $config;
}
add_filter('front_end_editor_nicedit', 'configure_fee_nicedit');

See the available configuration options.

Upgrade instructions

If you have custom code written for the plugin, read on:

Renamed hooks:

front_ed_fields -> front_end_editor_fields
front_ed_allow -> front_end_editor_allow
front_ed_disable -> front_end_editor_disable

Renamed CSS classes:

.front-ed -> .fee-field
.front-ed-{filter} -> .fee-filter-{filter}
.front-ed-container -> .fee-form

WP-UserOnline: Version 2.60

Last month, Lester Chan, one of the most respected plugin authors in the WordPress world, has announced that he will no longer be able to continue development on his plugins.

Since I use WP-UserOnline on all of my sites, I adopted it (along with WP-PageNavi) and will continue to support it.

Version 2.60 has a few noticeable enhancements:

When viewing the list of online users, admin pages will also have pretty titles, instead of URLs.

Clicking on a user’s IP addresses now takes you to a much more helpful page on domaintools.com instead of arin.net. As such, I decide to removed the country flag icons, since they slowed down page loads and were a hassle to set up.

Finally, to completely uninstall the plugin, it’s enough to delete it through the WordPress admin.

How to load JavaScript like a WordPress Master

Update: See Conditional Script Loading Revisited for WordPress 3.3 and newer.

If you’re involved in WordPress development, a challenge that you’re going to face sooner or later is how to include JavaScript files efficiently.

In this tutorial, I’m going to show you the best way to do that.

Let’s say you have a plugin that adds a custom shortcode. The shortcode needs some JavaScript code which requires jQuery.

If you’re just starting out with WordPress development, you might be tempted to write something like this:

Continue reading…

Smart Archives Reloaded: Advanced Tweaking

Since version 1.9, you can make modifications to the plugin output, without having to modify the plugin code. This way, your tweaks won’t be lost when you upgrade the plugin.

Custom styling

If you want to customize the appearance of the archives using your own CSS, here’s how you do it:

  1. Add this code to your theme’s functions.php file:
  2. add_filter('smart_archives_load_default_styles', '__return_false');
  3. Copy everything from smart-archives-reloaded/inc/styles.dev.css into your theme’s style.css file.
  4. Change the CSS in your theme’s style.css file, as needed.

Custom markup

If you want to go one step further and change the generated HTML markup, you can do that too (understanding of object inheritance is required).

First, take a look at the SAR_Generator class (in smart-archives-reloaded/generator.php).

In your theme’s functions.php file, you can extend that class, like so:

class SAR_Custom_Generator extends SAR_Generator {
 
	protected function generate_fancy() {
		// your custom code here
	}
 
	protected function generate_block() {
		// more of your custom code here
	}
 
	...
}

Then, all you have to do is add the ‘generator’ argument to the template tag:

<?php smart_archives('generator=SAR_Custom_Generator'); ?>