Adding boxes to WordPress 2.5+ Write Post panel

I have noticed few inconsistencies in the WordPress 2.6.1 code regarding the methods to add content boxes to the WordPress Write Post panel.

The old way included using

add_action('dbx_post_advanced', 'myplugin_old_custom_box' );
add_action('dbx_post_sidebar', 'myplugin_old_custom_box' );

which would add a box to the Advanced section and Sidebar.

However since version 2.5 dbx_post_sidebar actually adds a box to the end of Advanced section not the sidebar. In return dbx_post_advanced ads code to the beginning of the section.

Proper way to add admin boxes in 2.5+

WordPress 2.5 introduces another function to add the box. It is :

add_meta_box( 'myplugin_sectionid', __( 'My Post Section Title', 'myplugin_textdomain' ),
'myplugin_inner_custom_box', 'post', 'advanced', 'default' );

Parameters are id, title, callback function for drawing, type ('post', 'page' or 'link' panels), section ('normal', 'advanced') and priority ('high', 'core', 'default', 'low').

In order to add a box to the sidebar you need to use :

add_action('submitpost_box',  'myplugin_sidebar');

The best would be if add_meta_box function would be changed in the following version to also render sidebar boxes. But until then that's how we need to do it.


More like this:


Posted in: WordPress
TAGS:, , , , , , , , , , , , , , , , , ,
Both comments and trackbacks are currently closed.

2 Comments

  1. Feb 17th, 2010

    hi
    nice work Man,

    Keep it up

    Have Dream Day

  2. Aug 27th, 2008

    Thanks for this tip. I have already started using it on one of my plugins.

  • ManageWP