WordPress.org

Make WordPress Core

Ticket #5798: add_meta_box.diff

File add_meta_box.diff, 1.9 KB (added by ryan, 14 years ago)
  • wp-admin/includes/template.php

     
    845845                echo '<input type="hidden" id="wp-old-slug" name="wp-old-slug" value="' . $name . '" />';
    846846}
    847847
     848/**
     849 * add_meta_box() - Add a meta box to an edit form
     850 *
     851 * @since 2.5
     852 *
     853 * @param string $id String for use in the 'id' attribute of tags.
     854 * @param string $title Title of the meta box
     855 * @param string $callback Function that fills the box with the desired content.  The function should echo its output.
     856 * @param string $context The context in which the box should be displayed.  edit_post, edit_page, edit_link, edit_post_advanced...
     857 */
     858function add_meta_box($id, $title, $callback, $context) {
     859        global $wp_meta_boxes;
     860
     861        $wp_meta_boxes[$context][] = array('id' => $id, 'title' => $title, 'callback' => $callback);
     862}
     863
     864function do_meta_boxes($context, $object) {
     865        global $wp_meta_boxes;
     866
     867        if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$context]) )
     868                return;
     869
     870        foreach ( (array) $wp_meta_boxes[$context] as $box ) {
     871                echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id']) . '">' . "\n";
     872                echo "<h3>{$box['title']}</h3>\n";
     873                echo '<div class="inside">' . "\n";
     874                call_user_func($box['callback'], $object);
     875                echo "</div>\n";
     876                echo "</div>\n";
     877        }
     878}
     879
    848880?>
  • wp-admin/edit-form-advanced.php

     
    218218</div>
    219219</div>
    220220
     221<?php do_meta_boxes('edit_post', $post); ?>
     222
    221223<?php do_action('edit_form_advanced'); ?>
    222224
    223225<?php
     
    315317</div>
    316318<?php endif; ?>
    317319
     320<?php do_meta_boxes('edit_post_advanced', $post); ?>
     321
    318322<?php do_action('dbx_post_sidebar'); ?>
    319323
    320324</div>