[wp-trac] [WordPress Trac] #5924: add_meta_box function not defined
at plugin init
WordPress Trac
wp-trac at lists.automattic.com
Tue Feb 19 19:40:08 GMT 2008
#5924: add_meta_box function not defined at plugin init
----------------------+-----------------------------------------------------
Reporter: jhodgdon | Owner: anonymous
Type: defect | Status: new
Priority: normal | Milestone: 2.5
Component: General | Version: 2.5
Severity: normal | Keywords:
----------------------+-----------------------------------------------------
The API for adding sections to the post/page/link edit screens has changed
for WordPress 2.5 -- previously you would use, for instance:
{{{
add_action('dbx_page_advanced', 'your_function' );
}}}
and in 2.5 you are supposed to use the add_meta_box function.
The problem is that if you want your plugin to work in pre-2.5 and 2.5,
you need to detect which version is being used. The suggested logic is:
{{{
if( function_exists( 'add_meta_box' )) {
add_meta_box( etc. );
} else {
add_action('dbx_page_advanced', etc. );
}
}}}
The problem with this is that when the plugin is first loaded, and also
during the 'init' action, the function add_meta_box is not yet defined. It
is loaded later, from file wp-admin/includes/template.php
My suggestion is to move the add_meta_box function into a different file,
such as wp-includes/plugin.php, which is where the add_action and
add_filter functions are defined.
Tested in [6914]; I'll add a patch soon to move the function.
--
Ticket URL: <http://trac.wordpress.org/ticket/5924>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list