Make WordPress Core


Ignore:
Timestamp:
10/19/2011 09:43:02 PM (14 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.