Separate meta box context into page and context to accommodate postbox API changes. see #5798

git-svn-id: http://svn.automattic.com/wordpress/trunk@6762 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-02-08 21:06:15 +00:00
parent bc817d2a2e
commit 7f78733f6b
4 changed files with 30 additions and 9 deletions

View File

@ -219,7 +219,7 @@ else
</div>
</div>
<?php do_meta_boxes('edit_post', $post); ?>
<?php do_meta_boxes('post', 'normal', $post); ?>
<?php do_action('edit_form_advanced'); ?>
@ -318,7 +318,7 @@ if ( $authors && count( $authors ) > 1 ) :
</div>
<?php endif; ?>
<?php do_meta_boxes('edit_post_advanced', $post); ?>
<?php do_meta_boxes('post', 'advanced', $post); ?>
<?php do_action('dbx_post_sidebar'); ?>

View File

@ -99,6 +99,8 @@ function xfn_check($class, $value = '', $deprecated = '') {
</div>
</div>
<?php do_meta_boxes('link', 'normal', $link); ?>
<h2><?php _e('Advanced Options'); ?></h2>
<div id="linktargetdiv" class="postbox <?php echo postbox_classes('linktargetdiv', 'link'); ?>">
@ -274,6 +276,8 @@ function xfn_check($class, $value = '', $deprecated = '') {
</div>
</div>
<?php do_meta_boxes('link', 'advanced', $link); ?>
<?php if ( $link_id ) : ?>
<input type="hidden" name="action" value="save" />
<input type="hidden" name="link_id" value="<?php echo (int) $link_id; ?>" />

View File

@ -133,6 +133,8 @@ if ( ('edit' == $action) && current_user_can('delete_page', $post_ID) )
</p>
<?php do_meta_boxes('post', 'normal', $post); ?>
<?php do_action('edit_page_form'); ?>
<h2><?php _e('Advanced Options'); ?></h2>
@ -224,6 +226,8 @@ if ( $authors && count( $authors ) > 1 ) :
</div>
<?php endif; ?>
<?php do_meta_boxes('page', 'advanced', $post); ?>
</div>
</div>

View File

@ -853,22 +853,30 @@ function wp_remember_old_slug() {
* @param string $id String for use in the 'id' attribute of tags.
* @param string $title Title of the meta box
* @param string $callback Function that fills the box with the desired content. The function should echo its output.
* @param string $context The context in which the box should be displayed. edit_post, edit_page, edit_link, edit_post_advanced...
* @param string $page The type of edit page on which to show the box (post, page, link)
* @param string $context The context within the page where the boxes should show ('normal', 'advanced')
*/
function add_meta_box($id, $title, $callback, $context) {
function add_meta_box($id, $title, $callback, $page, $context = 'advanced') {
global $wp_meta_boxes;
$wp_meta_boxes[$context][] = array('id' => $id, 'title' => $title, 'callback' => $callback);
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();
$wp_meta_boxes[$page][$context][] = array('id' => $id, 'title' => $title, 'callback' => $callback);
}
function do_meta_boxes($context, $object) {
function do_meta_boxes($page, $context, $object) {
global $wp_meta_boxes;
if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$context]) )
if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
return;
foreach ( (array) $wp_meta_boxes[$context] as $box ) {
echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id']) . '">' . "\n";
foreach ( (array) $wp_meta_boxes[$page][$context] as $box ) {
echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . '">' . "\n";
echo "<h3>{$box['title']}</h3>\n";
echo '<div class="inside">' . "\n";
call_user_func($box['callback'], $object);
@ -877,4 +885,9 @@ function do_meta_boxes($context, $object) {
}
}
function test_box($post) {
echo "Hello $post->ID";
}
add_meta_box('test', 'Test', 'test_box', 'post');
?>