WordPress.org

WordPress 1.5 Developers' Primer

Posted February 28, 2005 by Laughinglizard. Filed under Documentation.

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) {
      do_stuff($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.

See Also:

Want to follow the code? There’s a development P2 blog and you can track active development in the Trac timeline that often has 20–30 updates per day.

Want to find an event near you? Check out the WordCamp schedule and find your local Meetup group!

For more WordPress news, check out the WordPress Planet or subscribe to the WP Briefing podcast.

Categories

Subscribe to WordPress News

Join 1,931,388 other subscribers

Archives

%d bloggers like this: