add_meta_box [ WordPress Functions ]
add_meta_box ( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null )
| Parameters: |
|
| Defined at: |
|
| Codex |
Similar Functions: add_meta, do_meta_boxes, link_advanced_meta_box, get_hidden_meta_boxes, add_metadata
Add a meta box to an edit form.
Source
function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {
global $wp_meta_boxes;
if ( empty( $screen ) )
$screen = get_current_screen();
elseif ( is_string( $screen ) )
$screen = convert_to_screen( $screen );
$page = $screen->id;
if ( !isset($wp_meta_boxes) )
$wp_meta_boxes = array();
if ( !isset($wp_meta_boxes[$page]) )
$wp_meta_boxes[$page] = array();
if ( !isset($wp_meta_boxes[$page][$context]) )
$wp_meta_boxes[$page][$context] = array();
foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
continue;
// If a core box was previously added or removed by a plugin, don't add.
if ( 'core' == $priority ) {
// If core box previously deleted, don't add
if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
return;
// If box was added with default priority, give it core priority to maintain sort order
if ( 'default' == $a_priority ) {
$wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
}
return;
}
// If no priority given and id already present, use existing priority
if ( empty($priority) ) {
$priority = $a_priority;
// else if we're adding to the sorted priority, we don't know the title or callback. Grab them from the previously added context/priority.
} elseif ( 'sorted' == $priority ) {
$title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
$callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
$callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
}
// An id can be in only one priority and one context
if ( $priority != $a_priority || $context != $a_context )
unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
}
}
if ( empty($priority) )
$priority = 'low';
if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
$wp_meta_boxes[$page][$context][$priority] = array();
$wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
}Examples [ wp-snippets.com ]
Top Google Search Results
- Function Reference/add meta box « WordPress Codex
Description. The add_meta_box() function was introduced in Version 2.5. It allows plugin developers to add meta boxes to the administrative interface.
codex.wordpress.org - WordPress › Support » add_meta_box callback with arguments?
Hello people,. I have a question about add_meta_box. Is there any way I can pass some arguments to the callback function. Here's what I mean: function ...
wordpress.org - How to Add a Metabox to a Custom Post Type | WP Theming
Aug 5, 2010 ... You can read the full parameters for add_meta_box in the codex. I also listed them here: <?php add_meta_box( $id, $title, $callback, $page, ...
wptheming.com - custom field - How to add add_meta_box to specific Page Template ...
Jan 21, 2013 ... Personally, I like calling this inside my add_meta_boxes_page callback, and wrapping it around the add_meta_box() call itself. function ...
wordpress.stackexchange.com
User discussions [ wordpress.org ]
- fedegonzaleznavarro on "Saving from Custom Admin Meta Box not working"
- graphicgeek on "Add Meta Boxes ignoring $context for pages"
- michael.mariart on "Blank values appearing with 'add_meta_box' function"
- bcworkz on "Blank values appearing with 'add_meta_box' function"
- DK999k on "Blank values appearing with 'add_meta_box' function"
- Sridhar Katakam on "[Plugin: Sociable] Fatal Error: Call to undefined function add_meta_box()"
- vishnu93 on "Meta box does not appear in a custom post type."
- Stefan Boonstra on "Conditional add_meta_box using get_post_meta($post->ID,'_wp_page_template', true"
- amphibious on "Adding the visual editor to my meta boxes?"
- amphibious on "Adding the visual editor to my meta boxes?"
