In: , , ,
On: 2008 / 06 / 30
Shorter URL for this post: http://ozh.in/in

Stephen, on his geek blog Nerdaphernalia, is running a series of excellent posts giving advices to plugin authors for neat subtle effects: adding a "Configure" link right next to the "Activate" link on the Plugins page, or how to give credit to your plugin without cluttering the page (I'm a big fan of the "Configure" link trick, that I've added to my latest release of Better Feed and will definitely implement in all my plugins now)

What's coming next on Stephen's blog is what seems to be my biggest pet peeve regarding plugins: saving plugin settings without cluttering the option table. I've had a draft post here for about 18 months about plugin coding tips and guidelines, and for sure its main point would be: "for f*ck sake, why don't you save all your options into just one array into just one entry??"

Taken from an actual plugin (slightly changed for anonymity) randomly found on my test blog (warning: NSFW)

  1. /*Lets add some default options if they don't exist*/
  2. add_option('xxx_email', get_option('admin_email'));
  3. add_option('xxx_subject', 'From Website');
  4. add_option('xxx_success_msg', 'Thanks, your email has been sent!');
  5. add_option('xxx_error_msg', 'Please fill in the required fields');
  6. add_option('xxx_error_msg_2', 'You have not entered a valid email address');
  7. add_option('xxx_error_msg_3', 'That destination does not appear to exist');
  8. add_option('xxx_redirect_loc', get_option('siteurl'));
  9. add_option('xxx_redirect_time', '3');
  10. add_option('xxx_css_inject', '1');
  11. add_option('xxx_cc_myself', '1');
  12. add_option('xxx_user_subject', '1');

Arrrgh. When I look at a plugin for the first time, the very first thing I do is literally count the occurrences of "add_option". More than 3 and the plugin is a no-no on my blog.

Executive summary: read Nerdaphernalia (I mean, if you're not a subscriber of Planet WordPress already). And wait a few more months for my "10 stuff to do to write proper plugins" article :Þ

Shorter URL

Want to share or tweet this post? Please use this short URL: http://ozh.in/in

Metastuff

This entry "WordPress Plugin Coding Tips" was posted on 30/06/2008 at 9:57 pm and is tagged with , , ,
Watch this discussion : Comments RSS 2.0.

3 Blablas

  1. Stephen R says:

    NSFW??? Must be all that "xxx" material.

  2. […] a single nanosecond reading files it doesn't need. But most of all, the plugin fails with my main coding concern: add all your options into one single database entry, damnit! I totally hate it when doing some DB […]

  3. Thibauld says:

    add_option('xxx_email', get_option('admin_email'));

    Oh god, WHY?!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar and sign for a free account
Spam: Various spam plugins may be activated. I'll put pins in a Voodoo doll if you spam me.

Read more ?