do_meta_boxes() – Meta-Box template function.

You appear to be a bot. Output may be restricted

Description

Meta-Box template function.

Usage

$int = do_meta_boxes( $screen, $context, $data_object );

Parameters

$screen
( string|WP_Screen ) required – The screen identifier. If you have used add_menu_page() or add_submenu_page() to create a new screen (and hence screen_id) make sure your menu slug conforms to the limits of sanitize_key() otherwise the 'screen' menu may not correctly render on your page.
$context
( string ) required – The screen context for which to display meta boxes.
$data_object
( mixed ) required – Gets passed to the meta box callback function as the first parameter. Often this is the object that's the focus of the current screen, for example a WP_Post or WP_Comment object.

Returns

int Number of meta_boxes.

Source

File name: wordpress/wp-admin/includes/template.php


Lines:

1 to 100 of 167
function do_meta_boxes( $screen, $context, $data_object ) {
  global $wp_meta_boxes;
  static $already_sorted = false;

  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 );

  printf( '<div id="%s-sortables" class="meta-box-sortables">', esc_attr( $context ) );

  /*
	 * Grab the ones the user has manually sorted.
	 * Pull them out of their previous context/priority and into the one the user chose.
	 */
  $sorted = get_user_option( "meta-box-order_$page" );

  if ( ! $already_sorted && $sorted ) {
    foreach ( $sorted as $box_context => $ids ) {
      foreach ( explode( ',', $ids ) as $id ) {
        if ( $id && 'dashboard_browser_nag' !== $id ) {
          add_meta_box( $id, null, null, $screen, $box_context, 'sorted' );
        }
      }
    }
  }

  $already_sorted = true;

  $i = 0;

  if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
    foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
      if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
        foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
          if ( false === $box || ! $box['title'] ) {
            continue;
          }

          $block_compatible = true;
          if ( is_array( $box['args'] ) ) {
            // If a meta box is just here for back compat, don't show it in the block editor.
            if ( $screen->is_block_editor() && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) {
              continue;
            }

            if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) {
              $block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box'];
              unset( $box['args']['__block_editor_compatible_meta_box'] );
            }

            // If the meta box is declared as incompatible with the block editor, override the callback function.
            if ( ! $block_compatible && $screen->is_block_editor() ) {
              $box['old_callback'] = $box['callback'];
              $box['callback']     = 'do_block_editor_incompatible_meta_box';
            }

            if ( isset( $box['args']['__back_compat_meta_box'] ) ) {
              $block_compatible = $block_compatible || (bool) $box['args']['__back_compat_meta_box'];
              unset( $box['args']['__back_compat_meta_box'] );
            }
          }

          $i++;
          // get_hidden_meta_boxes() doesn't apply in the block editor.
          $hidden_class = ( ! $screen->is_block_editor() && in_array( $box['id'], $hidden, true ) ) ? ' hide-if-js' : '';
          echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes( $box['id'], $page ) . $hidden_class . '" ' . '>' . "\n";

          echo '<div class="postbox-header">';
          echo '<h2 class="hndle">';
          if ( 'dashboard_php_nag' === $box['id'] ) {
            echo '<span aria-hidden="true" class="dashicons dashicons-warning"></span>';
            echo '<span class="screen-reader-text">' .
              /* translators: Hidden accessibility text. */
              __( 'Warning:' ) .
            ' </span>';
          }
          echo $box['title'];
          echo "</h2>\n";

          if ( 'dashboard_browser_nag' !== $box['id'] ) {
            $widget_title = $box['title'];

            if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) {
              $widget_title = $box['args']['__widget_basename'];
              // Do not pass this parameter to the user callback function.
              unset( $box['args']['__widget_basename'] );
            }

            echo '<div class="handle-actions hide-if-no-js">';

            echo '<button type="button" class="handle-order-higher" aria-disabled="false" aria-describedby="' . $box['id'] . '-handle-order-higher-description">';
            echo '<span class="screen-reader-text">' .
              /* translators: Hidden accessibility text. */
              __( 'Move up' ) .

 View on GitHub View on Trac