do_accordion_sections() WordPress Function
The do_accordion_sections() function allows you to create an accordion section for your WordPress site. This function takes two arguments: the id of the accordion section and the title of the section. The accordion section will be created using the WordPress default settings. However, you can override the default settings by passing an array of settings as the third argument. The do_accordion_sections() function is useful for creating a collapsing list of content on your WordPress site. This can be helpful for organizing long lists of content into manageable sections.
do_accordion_sections( string|object $screen, string $context, mixed $data_object ) #
Meta Box Accordion Template Function.
Description
Largely made up of abstracted code from do_meta_boxes(), this function serves to build meta boxes as list items for display as a collapsible accordion.
Parameters
- $screen
(string|object)(Required)The screen identifier.
- $context
(string)(Required)The screen context for which to display accordion sections.
- $data_object
(mixed)(Required)Gets passed to the section callback function as the first parameter.
Return
(int) Number of meta boxes as accordion sections.
Source
File: wp-admin/includes/template.php
function do_accordion_sections( $screen, $context, $data_object ) { global $wp_meta_boxes; wp_enqueue_script( 'accordion' ); if ( empty( $screen ) ) { $screen = get_current_screen(); } elseif ( is_string( $screen ) ) { $screen = convert_to_screen( $screen ); } $page = $screen->id; $hidden = get_hidden_meta_boxes( $screen ); ?> <div id="side-sortables" class="accordion-container"> <ul class="outer-border"> <?php $i = 0; $first_open = false; if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) { foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { if ( false === $box || ! $box['title'] ) { continue; } $i++; $hidden_class = in_array( $box['id'], $hidden, true ) ? 'hide-if-js' : ''; $open_class = ''; if ( ! $first_open && empty( $hidden_class ) ) { $first_open = true; $open_class = 'open'; } ?> <li class="control-section accordion-section <?php echo $hidden_class; ?> <?php echo $open_class; ?> <?php echo esc_attr( $box['id'] ); ?>" id="<?php echo esc_attr( $box['id'] ); ?>"> <h3 class="accordion-section-title hndle" tabindex="0"> <?php echo esc_html( $box['title'] ); ?> <span class="screen-reader-text"><?php _e( 'Press return or enter to open this section' ); ?></span> </h3> <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>"> <div class="inside"> <?php call_user_func( $box['callback'], $data_object, $box ); ?> </div><!-- .inside --> </div><!-- .accordion-section-content --> </li><!-- .accordion-section --> <?php } } } } ?> </ul><!-- .outer-border --> </div><!-- .accordion-container --> <?php return $i; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
3.6.0 | Introduced. |