WordPress.org

Make WordPress Core

Changeset 19013


Ignore:
Timestamp:
10/19/2011 09:43:02 PM (7 years ago)
Author:
ryan
Message:

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

Location:
trunk/wp-admin
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-form-advanced.php

    r18941 r19013  
    100100require_once('./includes/meta-boxes.php');
    101101
    102 add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', $post_type, 'side', 'core');
     102add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', null, 'side', 'core');
    103103
    104104if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post_type, 'post-formats' ) )
    105     add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', $post_type, 'side', 'core' );
     105    add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', null, 'side', 'core' );
    106106
    107107// all taxonomies
     
    114114
    115115    if ( !is_taxonomy_hierarchical($tax_name) )
    116         add_meta_box('tagsdiv-' . $tax_name, $label, 'post_tags_meta_box', $post_type, 'side', 'core', array( 'taxonomy' => $tax_name ));
     116        add_meta_box('tagsdiv-' . $tax_name, $label, 'post_tags_meta_box', null, 'side', 'core', array( 'taxonomy' => $tax_name ));
    117117    else
    118         add_meta_box($tax_name . 'div', $label, 'post_categories_meta_box', $post_type, 'side', 'core', array( 'taxonomy' => $tax_name ));
     118        add_meta_box($tax_name . 'div', $label, 'post_categories_meta_box', null, 'side', 'core', array( 'taxonomy' => $tax_name ));
    119119}
    120120
    121121if ( post_type_supports($post_type, 'page-attributes') )
    122     add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', $post_type, 'side', 'core');
     122    add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', null, 'side', 'core');
    123123
    124124if ( current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ) )
    125         add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', $post_type, 'side', 'low');
     125        add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', null, 'side', 'low');
    126126
    127127if ( post_type_supports($post_type, 'excerpt') )
    128     add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $post_type, 'normal', 'core');
     128    add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', null, 'normal', 'core');
    129129
    130130if ( post_type_supports($post_type, 'trackbacks') )
    131     add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', $post_type, 'normal', 'core');
     131    add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', null, 'normal', 'core');
    132132
    133133if ( post_type_supports($post_type, 'custom-fields') )
    134     add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', $post_type, 'normal', 'core');
     134    add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', null, 'normal', 'core');
    135135
    136136do_action('dbx_post_advanced');
    137137if ( post_type_supports($post_type, 'comments') )
    138     add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', $post_type, 'normal', 'core');
     138    add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', null, 'normal', 'core');
    139139
    140140if ( ('publish' == $post->post_status || 'private' == $post->post_status) && post_type_supports($post_type, 'comments') )
    141     add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', $post_type, 'normal', 'core');
     141    add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', null, 'normal', 'core');
    142142
    143143if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) )
    144     add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', $post_type, 'normal', 'core');
     144    add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', null, 'normal', 'core');
    145145
    146146if ( post_type_supports($post_type, 'author') ) {
    147147    if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) )
    148         add_meta_box('authordiv', __('Author'), 'post_author_meta_box', $post_type, 'normal', 'core');
     148        add_meta_box('authordiv', __('Author'), 'post_author_meta_box', null, 'normal', 'core');
    149149}
    150150
    151151if ( post_type_supports($post_type, 'revisions') && 0 < $post_ID && wp_get_post_revisions( $post_ID ) )
    152     add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', $post_type, 'normal', 'core');
     152    add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core');
    153153
    154154do_action('add_meta_boxes', $post_type, $post);
     
    348348}
    349349
    350 do_meta_boxes($post_type, 'normal', $post);
     350do_meta_boxes(null, 'normal', $post);
    351351
    352352( 'page' == $post_type ) ? do_action('edit_page_form') : do_action('edit_form_advanced');
    353353
    354 do_meta_boxes($post_type, 'advanced', $post);
     354do_meta_boxes(null, 'advanced', $post);
    355355
    356356do_action('dbx_post_sidebar'); ?>
  • trunk/wp-admin/edit-form-comment.php

    r18632 r19013  
    131131do_action('add_meta_boxes_comment', $comment);
    132132
    133 do_meta_boxes('comment', 'normal', $comment);
     133do_meta_boxes(null, 'normal', $comment);
    134134?>
    135135<input type="hidden" name="c" value="<?php echo esc_attr($comment->comment_ID) ?>" />
  • trunk/wp-admin/edit-link-form.php

    r18911 r19013  
    2525require_once('./includes/meta-boxes.php');
    2626
    27 add_meta_box('linksubmitdiv', __('Save'), 'link_submit_meta_box', 'link', 'side', 'core');
    28 add_meta_box('linkcategorydiv', __('Categories'), 'link_categories_meta_box', 'link', 'normal', 'core');
    29 add_meta_box('linktargetdiv', __('Target'), 'link_target_meta_box', 'link', 'normal', 'core');
    30 add_meta_box('linkxfndiv', __('Link Relationship (XFN)'), 'link_xfn_meta_box', 'link', 'normal', 'core');
    31 add_meta_box('linkadvanceddiv', __('Advanced'), 'link_advanced_meta_box', 'link', 'normal', 'core');
     27add_meta_box('linksubmitdiv', __('Save'), 'link_submit_meta_box', null, 'side', 'core');
     28add_meta_box('linkcategorydiv', __('Categories'), 'link_categories_meta_box', null, 'normal', 'core');
     29add_meta_box('linktargetdiv', __('Target'), 'link_target_meta_box', null, 'normal', 'core');
     30add_meta_box('linkxfndiv', __('Link Relationship (XFN)'), 'link_xfn_meta_box', null, 'normal', 'core');
     31add_meta_box('linkadvanceddiv', __('Advanced'), 'link_advanced_meta_box', null, 'normal', 'core');
    3232
    3333do_action('add_meta_boxes', 'link', $link);
     
    113113}
    114114
    115 do_meta_boxes('link', 'normal', $link);
     115do_meta_boxes(null, 'normal', $link);
    116116
    117 do_meta_boxes('link', 'advanced', $link);
     117do_meta_boxes(null, 'advanced', $link);
    118118
    119119if ( $link_id ) : ?>
  • trunk/wp-admin/includes/dashboard.php

    r19009 r19013  
    177177        $priority = 'high';
    178178
    179     add_meta_box( $widget_id, $widget_name, $callback, $screen->id, $location, $priority );
     179    add_meta_box( $widget_id, $widget_name, $callback, $screen, $location, $priority );
    180180}
    181181
  • trunk/wp-admin/includes/template.php

    r18982 r19013  
    840840 * @param string $title Title of the meta box.
    841841 * @param string $callback Function that fills the box with the desired content. The function should echo its output.
    842  * @param string $page The type of edit page on which to show the box (post, page, link).
     842 * @param string|object $screen The screen on which to show the box (post, page, link).
    843843 * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
    844844 * @param string $priority The priority within the context where the boxes should show ('high', 'low').
    845845 */
    846 function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args=null) {
     846function add_meta_box($id, $title, $callback, $screen, $context = 'advanced', $priority = 'default', $callback_args=null) {
    847847    global $wp_meta_boxes;
     848
     849    if ( empty( $screen ) )
     850        $screen = get_current_screen();
     851    elseif ( is_string( $screen ) )
     852        $screen = convert_to_screen( $screen );
     853
     854    $page = $screen->id;
    848855
    849856    if ( !isset($wp_meta_boxes) )
     
    900907 * @since 2.5.0
    901908 *
    902  * @param string $page page identifier, also known as screen identifier
     909 * @param string|object $screen Screen identifier
    903910 * @param string $context box context
    904911 * @param mixed $object gets passed to the box callback function as first parameter
    905912 * @return int number of meta_boxes
    906913 */
    907 function do_meta_boxes($page, $context, $object) {
     914function do_meta_boxes( $screen, $context, $object ) {
    908915    global $wp_meta_boxes;
    909916    static $already_sorted = false;
    910917
    911     $hidden = get_hidden_meta_boxes($page);
     918    if ( empty( $screen ) )
     919        $screen = get_current_screen();
     920    elseif ( is_string( $screen ) )
     921        $screen = convert_to_screen( $screen );
     922
     923    $page = $screen->id;
     924
     925    $hidden = get_hidden_meta_boxes( $screen );
    912926
    913927    printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context));
     
    920934                foreach ( explode(',', $ids ) as $id ) {
    921935                    if ( $id && 'dashboard_browser_nag' !== $id )
    922                         add_meta_box( $id, null, null, $page, $box_context, 'sorted' );
     936                        add_meta_box( $id, null, null, $screen, $box_context, 'sorted' );
    923937                }
    924938            }
     
    962976 *
    963977 * @param string $id String for use in the 'id' attribute of tags.
    964  * @param string $page The type of edit page on which to show the box (post, page, link).
     978 * @param string|object $screen The screen on which to show the box (post, page, link).
    965979 * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
    966980 */
    967 function remove_meta_box($id, $page, $context) {
     981function remove_meta_box($id, $screen, $context) {
    968982    global $wp_meta_boxes;
     983
     984    if ( empty( $screen ) )
     985        $screen = get_current_screen();
     986    elseif ( is_string( $screen ) )
     987        $screen = convert_to_screen( $screen );
     988
     989    $page = $screen->id;
    969990
    970991    if ( !isset($wp_meta_boxes) )
Note: See TracChangeset for help on using the changeset viewer.