Make WordPress Core


Ignore:
Timestamp:
03/15/2013 01:16:38 PM (12 years ago)
Author:
markjaquith
Message:

Turn the Nav Menu meta boxes into an accordion. Less sprawling and overwhelming.

  • Registration stays the same — they're meta boxes
  • Call do_accordion_sections() instead of do_meta_boxes() and they render as an accordion

props DrewAPicture, lessbloat, jkudish. fixes #23450. see #23449

File:
1 edited

Legend:

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

    r23567 r23707  
    969969
    970970/**
     971 * Meta Box Accordion Template Function
     972 *
     973 * Largely made up of abstracted code from {@link do_meta_boxes()}, this
     974 * function serves to build meta boxes as list items for display as
     975 * a collapsible accordion.
     976 *
     977 * @since 3.6.0
     978 *
     979 * @uses global $wp_meta_boxes Used to retrieve registered meta boxes.
     980 *
     981 * @param string|object $screen The screen identifier.
     982 * @param string $context The meta box context.
     983 * @param mixed $object gets passed to the section callback function as first parameter.
     984 * @return int number of meta boxes as accordion sections.
     985 */
     986function do_accordion_sections( $screen, $context, $object ) {
     987    global $wp_meta_boxes;
     988
     989    if ( empty( $screen ) )
     990        $screen = get_current_screen();
     991    elseif ( is_string( $screen ) )
     992        $screen = convert_to_screen( $screen );
     993
     994    $page = $screen->id;
     995
     996    $hidden = get_hidden_meta_boxes( $screen );
     997    ?>
     998    <div id="side-sortables" class="accordion-container">
     999        <ul class="outer-border">
     1000    <?php
     1001    $i = 0;
     1002    do {
     1003        if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[$page] ) || ! isset( $wp_meta_boxes[$page][$context] ) )
     1004            break;
     1005
     1006        foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
     1007            if ( isset( $wp_meta_boxes[$page][$context][$priority] ) ) {
     1008                foreach ( $wp_meta_boxes[$page][$context][$priority] as $box ) {
     1009                    if ( false == $box || ! $box['title'] )
     1010                        continue;
     1011                    $i++;
     1012                    $hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
     1013                    ?>
     1014                    <li class="control-section accordion-section <?php echo $hidden_class; ?> <?php echo esc_attr( $box['id'] ); ?>" id="<?php echo esc_attr( $box['id'] ); ?>">
     1015                        <h3 class="accordion-section-title hndle" tabindex="0" title="<?php echo esc_attr( $box['title'] ); ?>"><?php echo esc_html( $box['title'] ); ?></h3>
     1016                        <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
     1017                            <div class="inside">
     1018                                <?php call_user_func( $box['callback'], $object, $box ); ?>
     1019                            </div><!-- .inside -->
     1020                        </div><!-- .accordion-section-content -->
     1021                    </li><!-- .accordion-section -->
     1022                    <?php
     1023                }
     1024            }
     1025        }
     1026    } while(0);
     1027    ?>
     1028        </ul><!-- .outer-border -->
     1029    </div><!-- .accordion-container -->
     1030    <?php
     1031    return $i;
     1032}
     1033
     1034/**
    9711035 * Add a new section to a settings page.
    9721036 *
Note: See TracChangeset for help on using the changeset viewer.