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.


Please also check out ManageWP, One dashboard to manage all WordPress sites.

Related Articles:


Posted in: WordPress
TAGS:, , , , , , , , , , , , , , , , , ,
Leave a comment

Comments:

2 Comments

  1. sam
    Feb 17th, 2010

    hi
    nice work Man,

    Keep it up

    Have Dream Day

  2. scribu
    Aug 27th, 2008

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

Have your say

Your email is never published nor shared. Required fields are marked *

*
*

Subscribe without commenting

About

vladimir prelovac Vladimir Prelovac is CEO of Prelovac Media, a computer engineer by profession and an adventurer by state of mind. more +


"I would love to change the world, I just don't have the source code yet."

Services

Manage multiple WordPress sites

Built for WordPress enthusiasts, ManageWP helps you manage all your WordPress sites from one central location.

Books

WordPress Plugin Devleopment Book Read my book WordPress Plugin Development: Beginner's Guide

Published by Packt Publishing, available online through Amazon.