Custom Field Images: Version 2.1

This version adds the option to use the first attached image to a post as the displayed image.

Also, if you use get_custom_field_image() with format=html, you will get the same values that would be used by custom_field_image(). This allows you to format the image however you want.

The Insert CFI button should work with Internet Explorer again.

Monitor links to your WordPress plugins

A while ago I made a pipe that helped you see what people were saying on the support forums about your plugins. I, for one, am still using it today.

I also like to monitor links to my site. I use both Technorati and Blogsearch for this. But I noticed that some people only link to the page on Extend, rather than the page on this site. Those links never appeared on my radar.

So I made another pipe that, instead of tracking support topics, tracks links to plugin pages on WP Extend.

And here it is: WP Plugins Links

Meta tables for WordPress

For some time, there has been a debate among WordPress developers about adding additional meta tables, like wp_postmeta and wp_usermeta.

The only thing that everyone seems to agree on is that a unified API for accesing metadata is necessary.

I propose we add meta tables on demand: Have a function that adds meta tables only when required by a plugin.

For example, if a plugin needs wp_commentmeta, it could do something like this:

register_activation_hook(__FILE__, 'need_commentmeta');
function need_commentmeta() {
  enable_meta_table('comment');
}

The enable_meta_table() function would check if wp_commentmeta exists and create it if it doesn’t. After that, the plugin can use the table without worries.

Advantages of this approach:

  • no database bloat: there won’t be any meta tables that aren’t required
  • separate tables: it was noted that having a single meta table would affect performance
  • extensible: the enable_meta_table() could be made to accept new meta types

I think this approach would allow both consistency and flexibility.

The Right Way To Add Custom Quicktags

Ever since WordPress introduced quicktags, people have been wanting to customize them. Naturally, a lot of tutorials popped up, demonstrating how to do this. The problem is that all of them require that you edit quicktags.js, a file in WordPress.

But it doesn’t have to be that way now, since newer versions of WP have a script loading API. So here’s a better way to do it, without modifying any core files:

First, we make a basic plugin file, where we tell WP to load some javascript, right after loading the quicktags script:

<?php
/*
Plugin Name: My Custom Quicktags
Version: 1.0
*/
 
add_action('admin_print_scripts', 'my_custom_quicktags');
function my_custom_quicktags() {
	wp_enqueue_script(
		'my_custom_quicktags',
		plugin_dir_url(__FILE__) . 'my-custom-quicktags.js',
		array('quicktags')
	);
}

Now, instead of modifying quicktags.js, we add our quicktag code in a separate file:

edButtons[edButtons.length] = new edButton( 'sup', 'sup', '<sup>', '</sup>', '' );

Feel free to modify this to suit your needs.

The benefit of this method is that when you upgrade WordPress, your quicktag(s) will still be there.

I’ve made a .zip with these two files, which you can download and install as a regular plugin. It has been tested on WordPress 2.8.1 and 2.7.1.

Download

I’d love to know what quicktags you make with this tutorial, so feel free to share in the comments.

Update

It seems someone has taken this a step further, with the Post Edit Buttons plugin. More power to him :)

WordPress Community Appreciation

I read an interesting post today about WordPress plugin users being ungrateful.

To be honest, I don’t know what Jeff (the author of that post) is talking about. All the people that leave comments here have a grateful attitude, or are at least polite.

Actually, I want to thank them:

  • the people who report bugs or post suggestions
  • the people who make translations
  • the people who spread the good word on their sites, on twitter etc.
  • the people who simply make a small donation
  • the people who offer me paid work

You guys rock! This site would probably not even be here, if it weren’t for you. Thanks!

Custom Field Taxonomies: Version 1.3

This version adds two query options:

OR query

?fruit=apple,orange,pair

will match all posts that have the fruit field set to apple OR orange OR pair.

AND query

?color=red+orange+yellow

will match posts that have 3 color fields: one with red, one with orange and one wih yellow.

These capabilities are disabled by default. Before you enable them from Posts -> CF Taxnomies, a word of caution:

If some of your field values have commas ‘,’ character in them, don’t enable the OR query.

Also, if some of the field values have spaces ‘ ‘ in them, don’t enable the AND query.

Currently, you can’t enable both the AND query and the “Show posts that don’t match all key=value pairs” option. This will probably be fixed in the future.

Comment Autogrow: Version 1.0

I was using the autogrow script for my Front-End Editor plugin and thought it would be also useful for the comment textarea.

So I wrote this small plugin. To test it, start typing in the comment section below. Don’t press submit because that’s not the point.

Front-end Editor: Loading only on certain pages

Here is a foolproof way to make only parts of your site editable:

function front_editor_disable() {
	if ( ! is_single() )
		return true;
}
add_filter('front_end_editor_disable', 'front_editor_disable');

Just add that code in your theme’s functions.php file and you’re good to go: the plugin will work only on single posts.

Feel free to replace is_single() with whatever condition you need.

Event Pooling with WordPress

While reading an article about Event Pooling with jQuery, I realised that WP has an equivalent system, namely hooks. Here is a little map:

jQuery WordPress
.bind() add_action()
.unbind() remove_action()
.trigger() do_action()
event.type current_filter()

Of course, it’s not a perfect 1:1 match.

WordPress also has filters, besides actions, and a few other functions for controlling both. jQuery, on the other hand, gives you the possibility to bind an event to one or more elements on the page.

The important thing is that if you understand one system, you will easily comprehend the other. I guess this is another reason why jQuery is the prefered library for the WordPress admin.

7 reasons why I use bbPress

bbPress
bbPress 1.0 has finally been released last week. But why do I use it? Why would anyone use it? Here are my 7 reasons.

It’s familiar

If you have any experience with WordPress 2.7 or older, you will feel right at home using the new bbPress admin. You imediatly get a sense that you already know how to use it, which is great.

Continue reading…