January is Theme Month

In January 2009 I will be concentrating on themes and themeing.

Got a theme question, or conundrum? Let me know.

Adding settings to admin pages

I want to introduce you to a new function in 2.7 that might help to reduce the number of admin pages in your WordPress installation. The function allows plugin authors to extend the existing admin pages instead of creating new ones.

Here’s a quick example:

add_action('admin_init', 'add_my_settings_field');
 
function add_my_settings_field(){
 
// The fields are:
//the id the form field will use
//name to display on the page 
//callback function
//the name of the page
//the section of the page to add the field to
add_settings_field('my_field_id' , 'My Field Caption' ,
			'my_field_callback' , 'writing' , 'default');
 
//register the setting to make sure it gets checked
register_setting('writing','my_field_id');
}
 
function my_field_callback(){
 
//echo out the text field, drop down, or other type of field.			
echo '<input name="my_field_id" id="my_field_id" type="text"
 value="'.attribute_escape(get_option('my_field_id')).'" class="regular-text code" />';
 
}

In WordPress 2.7 admin pages are made of pages, sections and fields. In the above example I have added a new field to the writing page (Settings > Writing) in the default section.

This not only creates the table rows and table header for the form field, it also saves the value for you. The above code is everything you need to add the new question.

The value can be accessed again using get_option(’my_field_id’).

You could just as easily add it to the remote_publishing section, by changing the last attribute in the add_settings_field function in the example to ‘remote_publishing’.

If you take a look at the options-writing.php page in wp-admin you will see that beneath each section there is a function, do_settings_fields, that lists the page and the section in its arguments; i.e. do_settings_fields(’writing’, ‘remote_publishing’)

These tell you the settings you need to add fields in that part of the page.

I think this is a very important step in helping to reduce the clutter in WordPress, no longer will a new admin page be needed for a single setting if it could sit in an existing page.

Back to the future

Jeff has a written a post over at performancing about his trip back in time to WordPress 0.71. It isn’t something I would have tried but I am really interested to see the old version of WordPress.

It really does bring to mind again the question of what features are really needed in WordPress so I decided to list out the features that actually I don’t think I would use now, even if I might once have used them.

In doing this I was quite surprised to find that there are only two features that I could happily live without: Links / Blogroll and Widgets.

Links seems to be a particularly outmoded concept to me. I’m not sure I have ever used this. I know there are people that do, but I wonder how much of this functionality is replicated in a widget. Do you you this?

For me, I find Widgets actually get in the way. There are a lot of people that are not comfortable with editing the sidebar manually and for them widgets are a good idea, but if you are, or can become comfortable with it you will find that the widget system actually just gets in the way. I know a lot of people use plugins to add widgets that let them insert PHP code that could just as easily be added to the theme or sidebar.

Of course there are lots of little things that I don’t use, but these seem to be the only major things, which begs the question: why does WordPress feel like there are loads of unused features in it when there really aren’t?

What’s new and exciting?

I’ve been pretty scathing about some aspects of WordPress over the past few weeks both here and in the comments of a few other blogs. That being the case I thought it was about time I wrote about some of the things that I really like about the current development version of WordPress; the version that will become 2.7 in the next few months.

Admin Stuff

There is a new option in each post screen that allows the uselss crap you never use to be removed, leaving only a nice clean interface. The fact that drag and drop is back also means that you can order what’s left to create a start to finish workflow (or should that be WordFlow?). My entire post screen now looks something like this:

It is also now possible to reply to comments from the admin panel. choosing to reply to a comment brings up a nice floating box for your well thought out reply.

It is finally possibly, god knows why this wasn’t always available, to upload files from the media manager instead of having to create a new post.

And lastly a new quick edit option allows some of the core settings of posts and pages to be altered from the manage page. These are settings such as the page title, slug, publication status, whether it can accept comments or trackbacks, as well as categories and tags.

Development Stuff

For a long time I have thought that WordPress was missing functionality when it comes to the site menu. Every theme has one and yet the controls for it are woeful. The new function wp_page_menu() will generate the HTML for the menu including customisable home page text (if you want the home page included), the option to specify a class, change a sort order or to get the result as a string instead of echoing it.

This is a step in a direction, but it is very basic and some might want more from it. As a basic theme template tag it is the right choice though. It fits in with the rest of the WordPress theme template tags in philosophy and output and will remove some of the development burden for theme authors that aren’t really familiar with PHP.

wp_page_menu('show_home=Home&menu_class=menu);

WordPress 2.7 will support threaded comments by default and with that comes a template tag to take the work out of outputing those comments.

wp_list_comments($comment);

This is interesting to me for a few reasons. Firstly it rolls up the default comment HTML into the function, so while you can overide this I think it is likely that it will mean less variation in the way comments are marked-up. Most people tend to copy the default theme anyway but some themes do vary alot. The second reason is that to overide the comment HTML you include a function name to call instead. This means that even if you want to use different HTML it may be best placed in the functions.php file or at least in a separate file that the functions.php calls as an include. Either way it helps to keep the templates cleaner.

I have already written about the plugin uninstall mechanism so I won’t go into that again but it is interesting. Back in the days of 2.3 there was a lot of interest in this, promted by an article on weblog tools collection, and my posts on the subject still recieve a fair degree of attention.

It goes without saying that things could change either a little or a lot before 2.7 comes out, and I am sure there is more to come. In the meantime I would to hear about the things that you are most looking foward to about 2.7. What is your favourite new features?

WordPress 2.7 Admin Changes

I updated the version of WordPress running on my local installation this morning to find some interesting changes that, if they remain, could impact on your plugins.

This is the view that awaited me:

Each of the menu items on the left open and close as needed. Templates contains everything that is in the design tab now. Utilities features the new inbox (which seems to include notifications about WordPress and maybe new comments, but it doesn’t do anything yet) and some of the contents of the manage menu.

I’m not quite sure how I feel about it yet as I haven’t had much time to try it out, but there is a limit to how many admin changes people should accept so whatever happens with it lets hope they stick with it for a while. Personally I think the admin should be black (black is the new light blue).

 Page 1 of 2  1  2 »