Ticket #15000: 15000.3.diff
File 15000.3.diff, 6.0 KB (added by , 11 years ago) |
---|
-
wp-admin/includes/template.php
899 899 * @param string $title Title of the meta box. 900 900 * @param callback $callback Function that fills the box with the desired content. 901 901 * The function should echo its output. 902 * @param string|WP_Screen $screenOptional. The screen on which to show the box (like a post902 * @param mixed|WP_Screen $screens Optional. The screen on which to show the box (like a post 903 903 * type, 'link', or 'comment'). Default is the current screen. 904 904 * @param string $context Optional. The context within the screen where the boxes 905 905 * should display. Available contexts vary from screen to … … 913 913 * of the box array (which is the second parameter passed 914 914 * to your callback). Default null. 915 915 */ 916 function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {916 function add_meta_box( $id, $title, $callback, $screens = null, $context = 'advanced', $priority = 'default', $callback_args = null ) { 917 917 global $wp_meta_boxes; 918 918 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 926 919 if ( !isset($wp_meta_boxes) ) 927 920 $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();932 921 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 ); 937 924 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 } 942 957 return; 943 // If box was added with default priority, give it core priority to maintain sort order944 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]);947 958 } 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]); 949 971 } 950 // If no priority given and id already present, use existing priority951 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 context960 if ( $priority != $a_priority || $context != $a_context )961 unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);962 972 } 963 }964 973 965 if ( empty($priority) )966 $priority = 'low';974 if ( empty($priority) ) 975 $priority = 'low'; 967 976 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(); 970 979 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 } 972 982 } 973 983 974 984 /**