WordPress 1.5 Developers' Primer

WordPress 1.5 is not just cool and suave on the outside, there are quite a few programming enhancements and added features for coders, hackers, plugin developers and enthusiasts. Some of these are obvious while others are more difficult to track down without digging through the code. This is a highly technical post, so feel free to skip it if that’s not your bag.

  • Transparent serializing and deserializing of objects and arrays when using add, update, and get_option.
    So for example, consider the following code:

    $this = array(array(), blah, blah, blah);
    update_option('xfnbl_data', $this);
    $newthis = get_option('xfnbl_data');

    The update_option function will transparently serialize the data. If you save an option as an array, the option is returned as an array.
  • If you update_option an option that doesn’t exist, it’ll create it: If the option did not exist when it was updated, it is created transparently. If the option did not exist when it was requested using get_option, the code degrades gracefully and does not error out, returning an empty variable.
  • Lots of hooks, including these tasty ones
    • You can dynamically modify any option returned without changing the option in the DB: There are two new hooks to help with this.

      add_filter('pre_option_' . $option_name, 'function_name');
      add_filter('all_options', 'function_name');
    • You can create and modify any XML-RPC call through the xmlrpc.php interface: Another cool new tool. If you need to add functions to the xmlrpc class (IXR) and then handle them as you like, just do something like the following:

      add_filter('xmlrpc_methods', 'Add_XBN_Stuff');
      function Add_XBN_stuff($args) {
      $args['demo.somefunction'] = 'somefunction';
      return $args;
      function somefunction($stuff) {

      For a better look at a plugin developed with this functionality, look at this plugin.
  • You can create pages in the admin interface: There are a bunch of functions that allow manipulation of the managment menus and create new pages.

    add_menu_page('Page Title', 'Menu Title', $access_level, 'PHP_File_to_Display')
    add_submenu_page('Parent_Page', 'Page Title', 'Menu Title', $access_level, 'PHP_File_to_Display', 'function_name')
    add_options_page('Page Title', 'Menu Title', $access_level, 'PHP_File_to_Display','function_name')
    add_management_page('Page Title', 'Menu Title', $access_level, 'PHP_File_to_Display','function_name')

    For an example see cache-images: http://svn.wp-plugins.org/cache-images/trunk/:
  • There’s a new hook for caching plugins that is called before everything is loaded, though you do have to edit wp-config.php to activate it.
  • A whole bunch of hooks to help plugin developers get more creative: Some of these are new, some have existed through 1.2. There are too many hooks to list here. Just do a search within the wordpress folder for the data item you are dealing with and ‘apply_filter’ or ‘do_action’. You are sure to find something that works for you.

Get the Latest Updates

WP Briefing — The WordPress Podcast

Join Josepha Haden and Matt Mullenweg to learn about where WordPress is going and how you can get involved.