do_meta_boxes

Meta-Box template function.

Description

(int) do_meta_boxes( (string|WP_Screen) $screen, (string) $context, (mixed) $object ); 

Returns (int)

number of meta_boxes

Parameters (3)

0. $screen (string|WP_Screen)
Screen identifier
1. $context (string)
The context.
2. $object (mixed)
Gets passed to the box callback function as first parameter

Usage

  1. if ( !function_exists( 'do_meta_boxes' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/template.php'; 
  3.  
  4. // Screen identifier 
  5. $screen = null; 
  6.  
  7. // The context. 
  8. $context = ''; 
  9.  
  10. // gets passed to the box callback function as first parameter 
  11. $object = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = do_meta_boxes($screen, $context, $object); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/template.php  
  1. function do_meta_boxes( $screen, $context, $object ) { 
  2. global $wp_meta_boxes; 
  3. static $already_sorted = false; 
  4.  
  5. if ( empty( $screen ) ) 
  6. $screen = get_current_screen(); 
  7. elseif ( is_string( $screen ) ) 
  8. $screen = convert_to_screen( $screen ); 
  9.  
  10. $page = $screen->id; 
  11.  
  12. $hidden = get_hidden_meta_boxes( $screen ); 
  13.  
  14. printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context)); 
  15.  
  16. // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose 
  17. if ( ! $already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) { 
  18. foreach ( $sorted as $box_context => $ids ) { 
  19. foreach ( explode( ', ', $ids ) as $id ) { 
  20. if ( $id && 'dashboard_browser_nag' !== $id ) { 
  21. add_meta_box( $id, null, null, $screen, $box_context, 'sorted' ); 
  22.  
  23. $already_sorted = true; 
  24.  
  25. $i = 0; 
  26.  
  27. if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) { 
  28. foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) { 
  29. if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ]) ) { 
  30. foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { 
  31. if ( false == $box || ! $box['title'] ) 
  32. continue; 
  33. $i++; 
  34. $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : ''; 
  35. echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n"; 
  36. if ( 'dashboard_browser_nag' != $box['id'] ) { 
  37. $widget_title = $box[ 'title' ]; 
  38.  
  39. if ( is_array( $box[ 'args' ] ) && isset( $box[ 'args' ][ '__widget_basename' ] ) ) { 
  40. $widget_title = $box[ 'args' ][ '__widget_basename' ]; 
  41. // Do not pass this parameter to the user callback function. 
  42. unset( $box[ 'args' ][ '__widget_basename' ] ); 
  43.  
  44. echo '<button type="button" class="handlediv button-link" aria-expanded="true">'; 
  45. echo '<span class="screen-reader-text">' . sprintf( __( 'Toggle panel: %s' ), $widget_title ) . '</span>'; 
  46. echo '<span class="toggle-indicator" aria-hidden="true"></span>'; 
  47. echo '</button>'; 
  48. echo "<h2 class='hndle'><span>{$box['title']}</span></h2>\n"; 
  49. echo '<div class="inside">' . "\n"; 
  50. call_user_func($box['callback'], $object, $box); 
  51. echo "</div>\n"; 
  52. echo "</div>\n"; 
  53.  
  54. echo "</div>"; 
  55.  
  56. return $i; 
  57.