WordPress 2.5 Plugin Style Guide
Written by Alex on March 31 2008
Listed under: Tutorials, WordPress

The New WordPress 2.5 Style GuideAs I’ve been running the 2.5 release candidates on this blog, I thought it was the perfect opportunity to upgrade my plugin New User Email Setup to make it display in line with the new admin interface being implemented.

Now that the full 2.5 has been released, it is even more important that other plugin authors also update their plugins to fit the new admin style.

Hopefully, this is fairly conclusive, so should act as a good guide for all the different ways of displaying data. Some of this might be a bit trivial, but it wouldn’t be conclusive without it! (NB – This post does not deal with any of the changes to hooks etc)

Main Page ‘Frame’

As with previous versions of WordPress, 2.5 wraps all of the options page in a div as follows:

<div class="wrap">
     <!-- Put all your plugin options here -->
</div>

The Form Tag

As all the plugin options need to be submitted, the plugin options page needs to be a form, therefore, we need to add this element in too. Thanks Stephen.

<div class="wrap">
<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
     <!-- Put all your plugin options here -->
</form>
</div>

Titles

There is only one title that has a style rule in 2.5, which is your main page title:

<h2>My Plugin Options</h2>

You can of course use h3 etc too, and the browser styling will be used, but with the new layout, individual titles for individual options have kind of been replaced:

Layout

The main layout used for plugin options is, unfortunately, tables, but it is easy to use, the structure is as follows, below that, I have listed all the different types of input that you can use.

<table class="form-table">
  <tbody>
    <tr valign="top">
      <th scope="row">Option 1</th><!-- this is like your title -->
      <td><input type="text" size="40" value="" id="Option_1" 
                                 name="Option_1"/>
        <br />
        This is where you put a short description of this option field
      </td>
    </tr>
  </tbody>
</table>

This looks like this:
The New Text Input

Now, to change the type of input, you can use the following (I’ve assumed that you already have your th scope=”row” in place for each one, just to save me writing it every time):

Text Area

<td>
<textarea name="Option_1" cols="60" rows="4" style="width: 98%; 
font-size: 12px;" id="Option_1">
This is where you would put your PHP options call, so that text is 
displayed in the text area
<textarea>
</td>

An example text area:
The New Textarea

Checkbox

<td> 
  <label for="Option_2">
    <input type="checkbox" value="" id="Option_2" name="Option_2"/>
    The description for the first checkbox
  </label><br/>
  <label for="Option_3">
    <input type="checkbox" value="" id="Option_3" name="Option_3"/>
    This is the next description
  </label>
</td>

An Example checkbox:
The New Checkbox

Dropdown Box

<td>
<label for="Option_4">
  <select id="Option_4" name="Option_4">
    <option value="">First Value Name</option>
    <option value="">All Values are...</option>
    <option value="">Where you put your PHP options</option>
    <option value="">That are saved in the Database</option>
    <option value="">Enjoy</option>
  </select>
</label>
</td>

An example dropdown box:
The New Dropdown Box

Radio Buttons

<td>
<p> <!-- Note the extra p -->
  <label>
    <input type="radio" value="" name="Option_5"/>
    This describes the first radio button
  </label><br/>
  <label>
    <input type="radio" value="" name="Option_6"/>
    This describes the next radio button
  </label>
</p>
</td>

Example radio buttons:
The New Radio Buttons

Submit Button

What you put in ‘value’ here will be the text on the button. Make sure to put this OUTSIDE the ‘table’.

<div class="submit">
  <input type="submit" value="Update Settings" name="submit"/>
</div>

An example submit button:
The New Submit Button

I hope that this covers all of the options that are available, if I discover any more I’ll add them on.

See also:
Joost de Valk’s Style Guide
Migrating Plugins and Themes

Submit to Digg! | Add to Del.icio.us! | Add to Technorati Faves! | |

10 Comments
Leave a Comment »

  • Sorry about the poor quality of the images, i’ll try and get some better ones done.

    Comment by Alex — March 31 2008 @ 12:12 pm
  • i found your site when i was looking for a way to change the sidebar for different pages in wordpress… but i don’t see that tutorial here. is it somewhere in a secret cave? nice site btw… good info regardless.

    Comment by Rob Rush — April 9 2008 @ 10:21 pm
  • Thanks for the Info. Got here from Volk’s post. Just try put some better images up. Thanks again. M

    Comment by Foxinni — May 3 2008 @ 11:32 am
  • I think you’re going to confuse a lot of people by leaving out the <form> tag.

    Beyond that, excellent article. (Though, yes — please do update the images!)

    Comment by Stephen R — June 7 2008 @ 5:39 pm
  • I would suggest the following for the Submit button value — closer to the WP 2.5 standard:

    value="<?php _e('Save Changes') ?>"

    Comment by Stephen R — June 8 2008 @ 9:38 pm
  • @Stephen – Thanks for the feedback! You’re right, ‘Save Changes’ is more the standard on the built in options/settings pages, and I suppose it is also more generic than update settings.

    In terms of the <form> tag, I decided to leave it out because I considered it more a part of the plugin ‘coding’ than ‘design’ if that makes sense, but since you’ve raised it, and since a plugin settings page doesn’t display properly without it, I’ll add it to the post! Thanks again.

    @all – New images coming in 10 mins!

    Comment by Alex — June 9 2008 @ 12:39 pm
  • Hi,
    I am, Michael
    Nice site, very informative

    Comment by elursefluxult — October 21 2008 @ 5:01 am
  • Great article. Nice blog. Keep it coming. Mike

    Comment by Deutschland spot — March 12 2009 @ 8:15 pm
  • Hi Alex,

    one question, because i got some problems. Did you update your “new user creation”-E-Mail-Plugin to Wp 2.7(.1)? I simply canĀ“t send/receive(?) any E-Mails with this. Or have you got any similar reports about this issue?

    Thanks!

    Comment by Herr Kaiser — April 21 2009 @ 12:47 am

RSS feed for comments on this post.

Send To Twitter

Back to top

Popular Posts

Latest Commenters