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.
See also:
- Best practice for adding JavaScript code to WordPress plugins
- Improving security in Wordpress plugins using Nonces
- Wordpress plugin recommendations
Posted in: WordPress
TAGS:content boxes wordpress, custom post panel wordpress, myplugin_textdomain wordpress, wordpress add admin codex, wordpress add content box, wordpress add section, wordpress add_meta_box, wordpress api, wordpress boxes, wordpress content box plugin, wordpress contentboxes, wordpress custom write panels, wordpress developer, wordpress post panel, wordpress write codex, wordpress write panel, write panel functions wordpress, write panel wordpress, write post page wordpress
Hi! My name is 
2 Comments
hi
nice work Man,
Keep it up
Have Dream Day
Thanks for this tip. I have already started using it on one of my plugins.