^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 5年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云1核2g仅需102元/年,今日10点开抢

wordpress函数do_meta_boxes()用法示例

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

Meta-Box template function


�述


�数

$screen

(string|WP_Screen)
(Required)
Screen identifier

$context

(string)
(Required)
box context

$object

(mixed)
(Required)
gets passed to the box callback function as first parameter


返�值

(int) number of meta_boxes


�代�

File: wp-admin/includes/template.php

function do_meta_boxes( $screen, $context, $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">', htmlspecialchars($context));

	// Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
	if ( ! $already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) {
		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;
					$i++;
					$hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : '';
					echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\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 '<button type="button" class="handlediv" aria-expanded="true">';
echo '<span class="screen-reader-text">' . sprintf( __( 'Toggle panel: %s' ), $widget_title ) . '</span>';
echo '<span class="toggle-indicator" aria-hidden="true"></span>';
echo '</button>';
					}
					echo "<h2 class='hndle'><span>{$box['title']}</span></h2>\n";
					echo '<div class="inside">' . "\n";
					call_user_func($box['callback'], $object, $box);
					echo "</div>\n";
					echo "</div>\n";
				}
			}
		}
	}

	echo "</div>";

	return $i;

}

更新日志

Version �述
2.5.0 Introduced.

相关函数

Uses

  • wp-admin/includes/screen.php:
    get_current_screen()
  • wp-admin/includes/screen.php:
    get_hidden_meta_boxes()
  • wp-admin/includes/template.php:
    convert_to_screen()
  • wp-admin/includes/template.php:
    add_meta_box()
  • wp-admin/includes/post.php:
    postbox_classes()
  • wp-includes/l10n.php:
    __()
  • wp-includes/user.php:
    get_user_option()
  • Show 2 more uses
    Hide more uses


Used By

  • wp-admin/includes/dashboard.php:
    wp_dashboard()

User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by ramon fincken

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

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

    For example for the CPT named posts
    get_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( 'get_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',
                'trackbacksdiv',
                'tagsdiv-post_tag',
                'categorydiv',
                'postimagediv',
                'postcustom',
                'commentstatusdiv',
                'slugdiv',
                'authordiv',
                'submitdiv',
            ) ),
            'side'     => '',
            'advanced' => '',
        );
    }

    �代�: http://wordpress.stackexchange.com/questions/25793/how-to-force-one-column-layout-on-custom-post-type-edit-page/25814#25814

  2. This is how you can register 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' ),
            'callback_metabox_function',
            'my_custom_menu_page' );
    }
    add_action( 'add_meta_boxes', 'adding_custom_meta_boxes', 10, 2 );
    
    function callback_metabox_function(){
        echo 'Metabox Content';
    }
    
    do_meta_boxes( 'my_custom_menu_page', 'normal', '' );
    

    Worth mentioning that the ‘get_user_option_meta-box-order_post’ hook referenced in @ramon fincken’s example is “undocumented” only because it’s a dynamic hook, specifically the get_user_option_{$option} hook, where “meta-box-order” is a specific user option. Cool tip though 🙂

    Example

    Here is an example that uses add_meta_box to register 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_page',
        'normal'
    );
    
    do_meta_boxes( 'my_custom_menu_page', 'normal', '' );
    

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈