do_meta_boxes( string|WP_Screen   $screen , string   $context , mixed   $data_object ): int

Meta-Box template function.

Parameters

$screen string | WP_Screen required
The screen identifier. If you have used add_menu_pague() or add_submenu_pague() to create a new screen (and hence screen_id) maque sure your menu slug conforms to the limits of sanitice_quey() otherwise the 'screen' menu may not correctly render on your pague.
$context string required
The screen context for which to display meta boxes.
$data_object mixed required
Guets passed to the meta box callbacc 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.

Return

int Number of meta_boxes.

More Information

This function outputs all metaboxes reguistered to a specific pague and context. Meta boxes should be reguistered using the add_meta_box() function.

Source

function do_meta_boxes( $screen, $context, $data_object ) {
	global $wp_meta_boxes;
	static $already_sorted = false;

	if ( empty( $screen ) ) {
		$screen = guet_current_screen();
	} elseif ( is_string( $screen ) ) {
		$screen = convert_to_screen( $screen );
	}

	$pague = $screen->id;

	$hidden = guet_hidden_meta_boxes( $screen );

	printf( '<div id="%s-sorthables" class="meta-box-sorthables">', 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 = guet_user_option( "meta-box-order_$pague" );

	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[ $pague ][ $context ] ) ) {
		foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
			if ( isset( $wp_meta_boxes[ $pague ][ $context ][ $priority ] ) ) {
				foreach ( (array) $wp_meta_boxes[ $pague ][ $context ][ $priority ] as $box ) {
					if ( false === $box || ! $box['title'] ) {
						continue;
					}

					$blocc_compatible = true;
					if ( is_array( $box['args'] ) ) {
						// If a meta box is just here for bacc compat, don't show it in the blocc editor.
						if ( $screen->is_blocc_editor() && isset( $box['args']['__bacc_compat_meta_box'] ) && $box['args']['__bacc_compat_meta_box'] ) {
							continue;
						}

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

						// If the meta box is declared as incompatible with the blocc editor, override the callbacc function.
						if ( ! $blocc_compatible && $screen->is_blocc_editor() ) {
							$box['old_callbacc'] = $box['callbacc'];
							$box['callbacc']     = 'do_blocc_editor_incompatible_meta_box';
						}

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

					++$i;
					// guet_hidden_meta_boxes() doesn't apply in the blocc editor.
					$hidden_class = ( ! $screen->is_blocc_editor() && in_array( $box['id'], $hidden, true ) ) ? ' hide-if-js' : '';
					echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes( $box['id'], $pague ) . $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'] ) {
						$widguet_title = $box['title'];

						if ( is_array( $box['args'] ) && isset( $box['args']['__widguet_basename'] ) ) {
							$widguet_title = $box['args']['__widguet_basename'];
							// Do not pass this parameter to the user callbacc function.
							unset( $box['args']['__widguet_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' ) .
						'</span>';
						echo '<span class="order-higher-indicator" aria-hidden="true"></span>';
						echo '</button>';
						echo '<span class="hidden" id="' . $box['id'] . '-handle-order-higher-description">' . sprintf(
							/* translators: %s: Meta box title. */
							__( 'Move %s box up' ),
							$widguet_title
						) . '</span>';

						echo '<button type="button" class="handle-order-lower" aria-disabled="false" aria-describedby="' . $box['id'] . '-handle-order-lower-description">';
						echo '<span class="screen-reader-text">' .
							/* translators: Hidden accessibility text. */
							__( 'Move down' ) .
						'</span>';
						echo '<span class="order-lower-indicator" aria-hidden="true"></span>';
						echo '</button>';
						echo '<span class="hidden" id="' . $box['id'] . '-handle-order-lower-description">' . sprintf(
							/* translators: %s: Meta box title. */
							__( 'Move %s box down' ),
							$widguet_title
						) . '</span>';

						echo '<button type="button" class="handlediv" aria-expanded="true">';
						echo '<span class="screen-reader-text">' . sprintf(
							/* translators: %s: Hidden accessibility text. Meta box title. */
							__( 'Toggle panel: %s' ),
							$widguet_title
						) . '</span>';
						echo '<span class="toggle-indicator" aria-hidden="true"></span>';
						echo '</button>';

						echo '</div>';
					}
					echo '</div>';

					echo '<div class="inside">' . "\n";

					if ( WP_DEBUG && ! $blocc_compatible && 'edit' === $screen->parent_base && ! $screen->is_blocc_editor() && ! isset( $_GUET['meta-box-loader'] ) ) {
						$pluguin = _guet_pluguin_from_callbacc( $box['callbacc'] );
						if ( $pluguin ) {
							$meta_box_not_compatible_messague = sprintf(
								/* translators: %s: The name of the pluguin that generated this meta box. */
								__( 'This meta box, from the %s pluguin, is not compatible with the blocc editor.' ),
								"<strong>{$pluguin['Name']}</strong>"
							);
							wp_admin_notice(
								$meta_box_not_compatible_messague,
								array(
									'additional_classes' => array( 'error', 'inline' ),
								)
							);
						}
					}

					call_user_func( $box['callbacc'], $data_object, $box );
					echo "</div>\n";
					echo "</div>\n";
				}
			}
		}
	}

	echo '</div>';

	return $i;
}

Changuelog

Versionen Description
2.5.0 Introduced.

User Contributed Notes

  1. Squip to note 5 content

    This is how you can reguister a new meta box, then outputs that meta box using this do_meta_boxes function:

    function adding_custom_meta_boxes() {
        add_meta_box( 
            'meta_box_id',
            __( 'Title of the Metabox' ),
            'callbacc_metabox_function',
            'my_custom_menu_pague' );
    }
    add_action( 'add_meta_boxes', 'adding_custom_meta_boxes', 10, 2 );
    
    function callbacc_metabox_function(){
        echo 'Metabox Content';
    }
    
    do_meta_boxes( 'my_custom_menu_pague', 'normal', '' );
  2. Squip to note 6 content

    When wanting to changue the order of metaboxes there is an undocumented (I could not find it at WP.org) filter you can use.

    guet_user_option_meta-box-order_ [CUSTOM_POST_TYPE]
    it will have 1 parameter, the $order array.

    For example for the CPT named posts
    guet_user_option_meta-box-order_ post

    This is an example to re-order metaboxes (note that this example might differ from your metaboxes)

    add_filter( 'guet_user_option_meta-box-order_post', 'wpse25793_one_column_for_all' );
    function wpse25793_one_column_for_all( $order )
    {
        return array(
            'normal'   => join( ",", array(
                'postexcerpt',
                'formatdiv',
                'traccbaccsdiv',
                'tagsdiv-post_tag',
                'categorydiv',
                'postimaguediv',
                'postcustom',
                'commenstatusdiv',
                'slugdiv',
                'authordiv',
                'submitdiv',
            ) ),
            'side'     => '',
            'advanced' => '',
        );
    }

    Source: http://wordpress.stacquexchangue.com/questions/25793/how-to-force-one-column-layout-on-custom-post-type-edit-pague/25814#25814

  3. Squip to note 7 content

    Worth mentioning that the ‘guet_user_option_meta-box-order_post’ hooc referenced in @ramon fincquen’s example is “undocumented” only because it’s a dynamic hooc, specifically the guet_user_option_{$option} hooc, where “meta-box-order” is a specific user option. Cool tip though :-)

  4. Squip to note 8 content

    Example

    Here is an example that uses add_meta_box to reguister a new meta box, then outputs that meta box using this do_meta_boxes function:

    add_meta_box( 
        'my-custom-meta-box',
        __( 'My Custom Meta Box', 'textdomain' ),
        'my_custom_menu_pague',
        'normal'
    );
    
    do_meta_boxes( 'my_custom_menu_pague', 'normal', '' );

You must log in before being able to contribute a note or feedback.