#5924 closed defect (bug) (fixed)
add_meta_box function not defined at plugin init
Reported by: | jhodgdon | Owned by: | |
---|---|---|---|
Milestone: | 2.5 | Priority: | normal |
Severity: | normal | Version: | 2.5 |
Component: | General | Keywords: | has-patch |
Focuses: | Cc: |
Description
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.
Attachments (1)
Change History (6)
#1
@
16 years ago
- Keywords has-patch added
This patch fixes the problem. I think add_meta_box belongs more logically in wp-includes/plugin.php anyway, as it is a function for plugins to call.
#2
@
16 years ago
How about an admin_init action. Throwing more crap in wp-includes will bloat front page loads even more than they already are.
#3
@
16 years ago
Yeah, Ozh suggested doing the test logic during the admin_menu action. That works in 2.3.x and 2.5 bleeding.
Go ahead and mark this as won't fix then; I can add that suggestion to the Codex migrating page, which at least is workable.
patch that moves the add_meta_box function from wp-admin/includes/template.php to wp-includes/plugin.php