From d0d8eb2aaf8656d67aeda7bec1e55bedb29aa143 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 19 Oct 2011 21:43:02 +0000 Subject: [PATCH] Update meta box functions to handle WP_Screen objects and pass objects instead of IDs to them in core files. Allow passing emptiness to get the current screen. see #18958 git-svn-id: http://svn.automattic.com/wordpress/trunk@19013 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-form-advanced.php | 32 ++++++++++++++-------------- wp-admin/edit-form-comment.php | 2 +- wp-admin/edit-link-form.php | 14 ++++++------- wp-admin/includes/dashboard.php | 2 +- wp-admin/includes/template.php | 37 ++++++++++++++++++++++++++------- 5 files changed, 54 insertions(+), 33 deletions(-) diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index 128aea423f..6ebfe2645f 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -99,10 +99,10 @@ $post_type_object = get_post_type_object($post_type); // All meta boxes should be defined and added before the first do_meta_boxes() call (or potentially during the do_meta_boxes action). require_once('./includes/meta-boxes.php'); -add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', $post_type, 'side', 'core'); +add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', null, 'side', 'core'); if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post_type, 'post-formats' ) ) - add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', $post_type, 'side', 'core' ); + add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', null, 'side', 'core' ); // all taxonomies foreach ( get_object_taxonomies($post_type) as $tax_name ) { @@ -113,43 +113,43 @@ foreach ( get_object_taxonomies($post_type) as $tax_name ) { $label = $taxonomy->labels->name; if ( !is_taxonomy_hierarchical($tax_name) ) - add_meta_box('tagsdiv-' . $tax_name, $label, 'post_tags_meta_box', $post_type, 'side', 'core', array( 'taxonomy' => $tax_name )); + add_meta_box('tagsdiv-' . $tax_name, $label, 'post_tags_meta_box', null, 'side', 'core', array( 'taxonomy' => $tax_name )); else - add_meta_box($tax_name . 'div', $label, 'post_categories_meta_box', $post_type, 'side', 'core', array( 'taxonomy' => $tax_name )); + add_meta_box($tax_name . 'div', $label, 'post_categories_meta_box', null, 'side', 'core', array( 'taxonomy' => $tax_name )); } if ( post_type_supports($post_type, 'page-attributes') ) - add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', $post_type, 'side', 'core'); + add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', null, 'side', 'core'); if ( current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ) ) - add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', $post_type, 'side', 'low'); + add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', null, 'side', 'low'); if ( post_type_supports($post_type, 'excerpt') ) - add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $post_type, 'normal', 'core'); + add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', null, 'normal', 'core'); if ( post_type_supports($post_type, 'trackbacks') ) - add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', $post_type, 'normal', 'core'); + add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', null, 'normal', 'core'); if ( post_type_supports($post_type, 'custom-fields') ) - add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', $post_type, 'normal', 'core'); + add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', null, 'normal', 'core'); do_action('dbx_post_advanced'); if ( post_type_supports($post_type, 'comments') ) - add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', $post_type, 'normal', 'core'); + add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', null, 'normal', 'core'); if ( ('publish' == $post->post_status || 'private' == $post->post_status) && post_type_supports($post_type, 'comments') ) - add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', $post_type, 'normal', 'core'); + add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', null, 'normal', 'core'); if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) ) - add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', $post_type, 'normal', 'core'); + add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', null, 'normal', 'core'); if ( post_type_supports($post_type, 'author') ) { if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) - add_meta_box('authordiv', __('Author'), 'post_author_meta_box', $post_type, 'normal', 'core'); + add_meta_box('authordiv', __('Author'), 'post_author_meta_box', null, 'normal', 'core'); } if ( post_type_supports($post_type, 'revisions') && 0 < $post_ID && wp_get_post_revisions( $post_ID ) ) - add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', $post_type, 'normal', 'core'); + add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core'); do_action('add_meta_boxes', $post_type, $post); do_action('add_meta_boxes_' . $post_type, $post); @@ -347,11 +347,11 @@ if ( 1 == $screen_layout_columns ) { $side_meta_boxes = do_meta_boxes($post_type, 'side', $post); } -do_meta_boxes($post_type, 'normal', $post); +do_meta_boxes(null, 'normal', $post); ( 'page' == $post_type ) ? do_action('edit_page_form') : do_action('edit_form_advanced'); -do_meta_boxes($post_type, 'advanced', $post); +do_meta_boxes(null, 'advanced', $post); do_action('dbx_post_sidebar'); ?> diff --git a/wp-admin/edit-form-comment.php b/wp-admin/edit-form-comment.php index 1e57fc63e3..23766e22a2 100644 --- a/wp-admin/edit-form-comment.php +++ b/wp-admin/edit-form-comment.php @@ -130,7 +130,7 @@ $date = date_i18n( $datef, strtotime( $comment->comment_date ) ); do_action('add_meta_boxes', 'comment', $comment); do_action('add_meta_boxes_comment', $comment); -do_meta_boxes('comment', 'normal', $comment); +do_meta_boxes(null, 'normal', $comment); ?> diff --git a/wp-admin/edit-link-form.php b/wp-admin/edit-link-form.php index 51152ec4f2..0dd0222971 100644 --- a/wp-admin/edit-link-form.php +++ b/wp-admin/edit-link-form.php @@ -24,11 +24,11 @@ if ( ! empty($link_id) ) { require_once('./includes/meta-boxes.php'); -add_meta_box('linksubmitdiv', __('Save'), 'link_submit_meta_box', 'link', 'side', 'core'); -add_meta_box('linkcategorydiv', __('Categories'), 'link_categories_meta_box', 'link', 'normal', 'core'); -add_meta_box('linktargetdiv', __('Target'), 'link_target_meta_box', 'link', 'normal', 'core'); -add_meta_box('linkxfndiv', __('Link Relationship (XFN)'), 'link_xfn_meta_box', 'link', 'normal', 'core'); -add_meta_box('linkadvanceddiv', __('Advanced'), 'link_advanced_meta_box', 'link', 'normal', 'core'); +add_meta_box('linksubmitdiv', __('Save'), 'link_submit_meta_box', null, 'side', 'core'); +add_meta_box('linkcategorydiv', __('Categories'), 'link_categories_meta_box', null, 'normal', 'core'); +add_meta_box('linktargetdiv', __('Target'), 'link_target_meta_box', null, 'normal', 'core'); +add_meta_box('linkxfndiv', __('Link Relationship (XFN)'), 'link_xfn_meta_box', null, 'normal', 'core'); +add_meta_box('linkadvanceddiv', __('Advanced'), 'link_advanced_meta_box', null, 'normal', 'core'); do_action('add_meta_boxes', 'link', $link); do_action('add_meta_boxes_link', $link); @@ -112,9 +112,9 @@ if ( 1 == $screen_layout_columns ) { $side_meta_boxes = do_meta_boxes( 'link', 'side', $link ); } -do_meta_boxes('link', 'normal', $link); +do_meta_boxes(null, 'normal', $link); -do_meta_boxes('link', 'advanced', $link); +do_meta_boxes(null, 'advanced', $link); if ( $link_id ) : ?> diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php index a8b79c3313..8c415b9982 100644 --- a/wp-admin/includes/dashboard.php +++ b/wp-admin/includes/dashboard.php @@ -176,7 +176,7 @@ function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_ if ( 'dashboard_browser_nag' === $widget_id ) $priority = 'high'; - add_meta_box( $widget_id, $widget_name, $callback, $screen->id, $location, $priority ); + add_meta_box( $widget_id, $widget_name, $callback, $screen, $location, $priority ); } function _wp_dashboard_control_callback( $dashboard, $meta_box ) { diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index d2e5ca22a4..51fc471298 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -839,13 +839,20 @@ function wp_import_upload_form( $action ) { * @param string $id String for use in the 'id' attribute of tags. * @param string $title Title of the meta box. * @param string $callback Function that fills the box with the desired content. The function should echo its output. - * @param string $page The type of edit page on which to show the box (post, page, link). + * @param string|object $screen The screen on which to show the box (post, page, link). * @param string $context The context within the page where the boxes should show ('normal', 'advanced'). * @param string $priority The priority within the context where the boxes should show ('high', 'low'). */ -function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args=null) { +function add_meta_box($id, $title, $callback, $screen, $context = 'advanced', $priority = 'default', $callback_args=null) { global $wp_meta_boxes; + if ( empty( $screen ) ) + $screen = get_current_screen(); + elseif ( is_string( $screen ) ) + $screen = convert_to_screen( $screen ); + + $page = $screen->id; + if ( !isset($wp_meta_boxes) ) $wp_meta_boxes = array(); if ( !isset($wp_meta_boxes[$page]) ) @@ -899,16 +906,23 @@ function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $pri * * @since 2.5.0 * - * @param string $page page identifier, also known as screen identifier + * @param string|object $screen Screen identifier * @param string $context box context * @param mixed $object gets passed to the box callback function as first parameter * @return int number of meta_boxes */ -function do_meta_boxes($page, $context, $object) { +function do_meta_boxes( $screen, $context, $object ) { global $wp_meta_boxes; static $already_sorted = false; - $hidden = get_hidden_meta_boxes($page); + 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('
', htmlspecialchars($context)); @@ -919,7 +933,7 @@ function do_meta_boxes($page, $context, $object) { foreach ( $sorted as $box_context => $ids ) { foreach ( explode(',', $ids ) as $id ) { if ( $id && 'dashboard_browser_nag' !== $id ) - add_meta_box( $id, null, null, $page, $box_context, 'sorted' ); + add_meta_box( $id, null, null, $screen, $box_context, 'sorted' ); } } } @@ -961,12 +975,19 @@ function do_meta_boxes($page, $context, $object) { * @since 2.6.0 * * @param string $id String for use in the 'id' attribute of tags. - * @param string $page The type of edit page on which to show the box (post, page, link). + * @param string|object $screen The screen on which to show the box (post, page, link). * @param string $context The context within the page where the boxes should show ('normal', 'advanced'). */ -function remove_meta_box($id, $page, $context) { +function remove_meta_box($id, $screen, $context) { global $wp_meta_boxes; + if ( empty( $screen ) ) + $screen = get_current_screen(); + elseif ( is_string( $screen ) ) + $screen = convert_to_screen( $screen ); + + $page = $screen->id; + if ( !isset($wp_meta_boxes) ) $wp_meta_boxes = array(); if ( !isset($wp_meta_boxes[$page]) )