WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/30/2008 11:33:02 PM (12 years ago)
Author:
mdawaffe
Message:

First pass at draggable meta boxes. Meta boxes must now be defined before the first call to do_meta_boxes(). Meta boxes can be dragged from any set of meta boxes to any set of meta boxes on the same page, including the sidebar. Some funkiness with Opera. Untested in IE

File:
1 edited

Legend:

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

    r8147 r8219  
    11351135    global $wp_meta_boxes;
    11361136
    1137    
    11381137    if  ( !isset($wp_meta_boxes) )
    11391138        $wp_meta_boxes = array();
     
    11431142        $wp_meta_boxes[$page][$context] = array();
    11441143
     1144    foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
    11451145    foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
    1146         if ( !isset($wp_meta_boxes[$page][$context][$a_priority][$id]) )
     1146        if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
    11471147            continue;
     1148
    11481149        // If a core box was previously added or removed by a plugin, don't add.
    11491150        if ( 'core' == $priority ) {
    11501151            // If core box previously deleted, don't add
    1151             if ( false === $wp_meta_boxes[$page][$context][$a_priority][$id] )
     1152            if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
    11521153                return;
    11531154            // If box was added with default priority, give it core priority to maintain sort order
    11541155            if ( 'default' == $a_priority ) {
    1155                 $wp_meta_boxes[$page][$context]['core'][$id] = $wp_meta_boxes[$page][$context]['default'][$id];
    1156                 unset($wp_meta_boxes[$page][$context]['default'][$id]);
     1156                $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
     1157                unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
    11571158            }
    11581159            return;
    11591160        }
    11601161        // If no priority given and id already present, use existing priority
    1161         if ( empty($priority) )
     1162        if ( empty($priority) ) {
    11621163            $priority = $a_priority;
    1163         // An id can be in only one priority
    1164         if ( $priority != $a_priority )
    1165             unset($wp_meta_boxes[$page][$context][$a_priority][$id]);
     1164        // else if we're adding to the sorted priortiy, we don't know the title or callback.  Glab them from the previously added context/priority.
     1165        } elseif ( 'sorted' == $priority ) {
     1166            $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
     1167            $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
     1168        }
     1169        // An id can be in only one priority and one context
     1170        if ( $priority != $a_priority || $context != $a_context )
     1171            unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
     1172    }
    11661173    }
    11671174
    11681175    if ( empty($priority) )
    1169         $priority = low;
     1176        $priority = 'low';
    11701177
    11711178    if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
     
    11771184function do_meta_boxes($page, $context, $object) {
    11781185    global $wp_meta_boxes;
     1186    static $already_sorted = false;
    11791187
    11801188    do_action('do_meta_boxes', $page, $context, $object);
    11811189
    1182     if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
    1183         return;
    1184 
    1185     foreach ( array('high', 'core', 'default', 'low') as $priority ) {
    1186         foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
    1187             if ( false === $box )
    1188                 continue;
    1189             echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . '">' . "\n";
    1190             echo "<h3>{$box['title']}</h3>\n";
    1191             echo '<div class="inside">' . "\n";
    1192             call_user_func($box['callback'], $object, $box);
    1193             echo "</div>\n";
    1194             echo "</div>\n";
    1195         }
    1196     }
     1190    echo "<div id='$context-sortables' class='meta-box-sortables'>\n";
     1191
     1192    do {
     1193        // Grab the ones the user has manually sorted.  Pull them out of their previous context/priority and into the one the user chose
     1194        if ( !$already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) {
     1195            foreach ( $sorted as $box_context => $ids )
     1196                foreach ( explode(',', $ids) as $id )
     1197                    if ( $id )
     1198                        add_meta_box( $id, null, null, $page, $box_context, 'sorted' );
     1199        }
     1200        $already_sorted = true;
     1201
     1202        if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
     1203            break;
     1204
     1205
     1206        foreach ( array('high', 'sorted', 'core', 'default', 'low') as $priority ) {
     1207            foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
     1208                if ( false === $box )
     1209                    continue;
     1210                echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . '">' . "\n";
     1211                echo "<h3>{$box['title']}</h3>\n";
     1212                echo '<div class="inside">' . "\n";
     1213                call_user_func($box['callback'], $object, $box);
     1214                echo "</div>\n";
     1215                echo "</div>\n";
     1216            }
     1217        }
     1218    } while(0);
     1219
     1220    echo "</div>";
     1221
    11971222}
    11981223
Note: See TracChangeset for help on using the changeset viewer.