Make WordPress Core

Ticket #15000: 15000.3.diff

File 15000.3.diff, 6.0 KB (added by egill, 11 years ago)
  • wp-admin/includes/template.php

     
    899899 * @param string           $title         Title of the meta box.
    900900 * @param callback         $callback      Function that fills the box with the desired content.
    901901 *                                        The function should echo its output.
    902  * @param string|WP_Screen $screen        Optional. The screen on which to show the box (like a post
     902 * @param mixed|WP_Screen $screens        Optional. The screen on which to show the box (like a post
    903903 *                                        type, 'link', or 'comment'). Default is the current screen.
    904904 * @param string           $context       Optional. The context within the screen where the boxes
    905905 *                                        should display. Available contexts vary from screen to
     
    913913 *                                        of the box array (which is the second parameter passed
    914914 *                                        to your callback). Default null.
    915915 */
    916 function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {
     916function add_meta_box( $id, $title, $callback, $screens = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {
    917917        global $wp_meta_boxes;
    918918
    919         if ( empty( $screen ) )
    920                 $screen = get_current_screen();
    921         elseif ( is_string( $screen ) )
    922                 $screen = convert_to_screen( $screen );
    923 
    924         $page = $screen->id;
    925 
    926919        if ( !isset($wp_meta_boxes) )
    927920                $wp_meta_boxes = array();
    928         if ( !isset($wp_meta_boxes[$page]) )
    929                 $wp_meta_boxes[$page] = array();
    930         if ( !isset($wp_meta_boxes[$page][$context]) )
    931                 $wp_meta_boxes[$page][$context] = array();
    932921
    933         foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
    934                 foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
    935                         if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
    936                                 continue;
     922        if ( ! is_array( $screens ) )
     923                $screens = array( $screens );
    937924
    938                         // If a core box was previously added or removed by a plugin, don't add.
    939                         if ( 'core' == $priority ) {
    940                                 // If core box previously deleted, don't add
    941                                 if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
     925        foreach ( $screen as $screen ) {
     926                if ( empty( $screen ) ) {
     927                        $screen = get_current_screen();
     928                } elseif ( is_string( $screen ) ) {
     929                        $screen = convert_to_screen( $screen );
     930                }
     931
     932                if ( ! isset( $screen->id ) )
     933                        return;
     934
     935                $page = $screen->id;
     936
     937                if ( !isset($wp_meta_boxes[$page]) )
     938                        $wp_meta_boxes[$page] = array();
     939                if ( !isset($wp_meta_boxes[$page][$context]) )
     940                        $wp_meta_boxes[$page][$context] = array();
     941
     942                foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
     943                        foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
     944                                if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
     945                                        continue;
     946
     947                                // If a core box was previously added or removed by a plugin, don't add.
     948                                if ( 'core' == $priority ) {
     949                                        // If core box previously deleted, don't add
     950                                        if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
     951                                                return;
     952                                        // If box was added with default priority, give it core priority to maintain sort order
     953                                        if ( 'default' == $a_priority ) {
     954                                                $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
     955                                                unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
     956                                        }
    942957                                        return;
    943                                 // If box was added with default priority, give it core priority to maintain sort order
    944                                 if ( 'default' == $a_priority ) {
    945                                         $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
    946                                         unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
    947958                                }
    948                                 return;
     959                                // If no priority given and id already present, use existing priority
     960                                if ( empty($priority) ) {
     961                                        $priority = $a_priority;
     962                                // else if we're adding to the sorted priority, we don't know the title or callback. Grab them from the previously added context/priority.
     963                                } elseif ( 'sorted' == $priority ) {
     964                                        $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
     965                                        $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
     966                                        $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
     967                                }
     968                                // An id can be in only one priority and one context
     969                                if ( $priority != $a_priority || $context != $a_context )
     970                                        unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
    949971                        }
    950                         // If no priority given and id already present, use existing priority
    951                         if ( empty($priority) ) {
    952                                 $priority = $a_priority;
    953                         // else if we're adding to the sorted priority, we don't know the title or callback. Grab them from the previously added context/priority.
    954                         } elseif ( 'sorted' == $priority ) {
    955                                 $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
    956                                 $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
    957                                 $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
    958                         }
    959                         // An id can be in only one priority and one context
    960                         if ( $priority != $a_priority || $context != $a_context )
    961                                 unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
    962972                }
    963         }
    964973
    965         if ( empty($priority) )
    966                 $priority = 'low';
     974                if ( empty($priority) )
     975                        $priority = 'low';
    967976
    968         if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
    969                 $wp_meta_boxes[$page][$context][$priority] = array();
     977                if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
     978                        $wp_meta_boxes[$page][$context][$priority] = array();
    970979
    971         $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
     980                $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
     981        }
    972982}
    973983
    974984/**