Make WordPress Core


Ignore:
Timestamp:
02/08/2008 09:06:15 PM (17 years ago)
Author:
ryan
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/template.php

    r6758 r6762  
    854854 * @param string $title Title of the meta box
    855855 * @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...
     856 * @param string $page The type of edit page on which to show the box (post, page, link)
     857 * @param string $context The context within the page where the boxes should show ('normal', 'advanced')
    857858 */
    858 function add_meta_box($id, $title, $callback, $context) {
     859function add_meta_box($id, $title, $callback, $page, $context = 'advanced') {
    859860    global $wp_meta_boxes;
    860861
    861     $wp_meta_boxes[$context][] = array('id' => $id, 'title' => $title, 'callback' => $callback);
    862 }
    863 
    864 function do_meta_boxes($context, $object) {
     862    if  ( !isset($wp_meta_boxes) )
     863        $wp_meta_boxes = array();
     864    if ( !isset($wp_meta_boxes[$page]) )
     865        $wp_meta_boxes[$page] = array();
     866    if ( !isset($wp_meta_boxes[$page][$context]) )
     867        $wp_meta_boxes[$page][$context] = array();
     868
     869    $wp_meta_boxes[$page][$context][] = array('id' => $id, 'title' => $title, 'callback' => $callback);
     870}
     871
     872function do_meta_boxes($page, $context, $object) {
    865873    global $wp_meta_boxes;
    866874
    867     if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$context]) )
     875    if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
    868876        return;
    869877
    870     foreach ( (array) $wp_meta_boxes[$context] as $box ) {
    871         echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id']) . '">' . "\n";
     878    foreach ( (array) $wp_meta_boxes[$page][$context] as $box ) {
     879        echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . '">' . "\n";
    872880        echo "<h3>{$box['title']}</h3>\n";
    873881        echo '<div class="inside">' . "\n";
     
    878886}
    879887
    880 ?>
     888function test_box($post) {
     889    echo "Hello $post->ID";
     890}
     891
     892add_meta_box('test', 'Test', 'test_box', 'post');
     893?>
Note: See TracChangeset for help on using the changeset viewer.