Changeset 7930 for trunk/wp-admin/includes/template.php
- Timestamp:
- 05/14/2008 08:22:01 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/template.php
r7911 r7930 1042 1042 * @param string $page The type of edit page on which to show the box (post, page, link) 1043 1043 * @param string $context The context within the page where the boxes should show ('normal', 'advanced') 1044 * @param string $priority The priority within the context where the boxes should show ('high', 'low') 1044 1045 */ 1045 function add_meta_box($id, $title, $callback, $page, $context = 'advanced' ) {1046 function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default') { 1046 1047 global $wp_meta_boxes; 1047 1048 1049 1048 1050 if ( !isset($wp_meta_boxes) ) 1049 1051 $wp_meta_boxes = array(); … … 1053 1055 $wp_meta_boxes[$page][$context] = array(); 1054 1056 1055 $wp_meta_boxes[$page][$context][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback); 1057 foreach ( array('high', 'core', 'default', 'low') as $a_priority ) { 1058 if ( !isset($wp_meta_boxes[$page][$context][$a_priority][$id]) ) 1059 continue; 1060 // If a core box was previously added or removed by a plugin, don't add. 1061 if ( 'core' == $priority ) { 1062 // If core box previously deleted, don't add 1063 if ( false === $wp_meta_boxes[$page][$context][$a_priority][$id] ) 1064 return; 1065 // If box was added with default priority, give it core priority to maintain sort order 1066 if ( 'default' == $a_priority ) { 1067 $wp_meta_boxes[$page][$context]['core'][$id] = $wp_meta_boxes[$page][$context]['default'][$id]; 1068 unset($wp_meta_boxes[$page][$context]['default'][$id]); 1069 } 1070 return; 1071 } 1072 // If no priority given and id already present, use existing priority 1073 if ( empty($priority) ) 1074 $priority = $a_priority; 1075 // An id can be in only one priority 1076 if ( $priority != $a_priority ) 1077 unset($wp_meta_boxes[$page][$context][$a_priority][$id]); 1078 } 1079 1080 if ( empty($priority) ) 1081 $priority = low; 1082 1083 if ( !isset($wp_meta_boxes[$page][$context][$priority]) ) 1084 $wp_meta_boxes[$page][$context][$priority] = array(); 1085 1086 $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback); 1056 1087 } 1057 1088 … … 1059 1090 global $wp_meta_boxes; 1060 1091 1092 do_action('do_meta_boxes', $page, $context, $object); 1093 1061 1094 if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) ) 1062 1095 return; 1063 1096 1064 foreach ( (array) $wp_meta_boxes[$page][$context] as $box ) { 1065 echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . '">' . "\n"; 1066 echo "<h3>{$box['title']}</h3>\n"; 1067 echo '<div class="inside">' . "\n"; 1068 call_user_func($box['callback'], $object, $box); 1069 echo "</div>\n"; 1070 echo "</div>\n"; 1071 } 1097 foreach ( array('high', 'core', 'default', 'low') as $priority ) { 1098 foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) { 1099 if ( false === $box ) 1100 continue; 1101 echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . '">' . "\n"; 1102 echo "<h3>{$box['title']}</h3>\n"; 1103 echo '<div class="inside">' . "\n"; 1104 call_user_func($box['callback'], $object, $box); 1105 echo "</div>\n"; 1106 echo "</div>\n"; 1107 } 1108 } 1109 } 1110 1111 /** 1112 * remove_meta_box() - Remove a meta box from an edit form 1113 * 1114 * @since 2.6 1115 * 1116 * @param string $id String for use in the 'id' attribute of tags. 1117 * @param string $page The type of edit page on which to show the box (post, page, link) 1118 * @param string $context The context within the page where the boxes should show ('normal', 'advanced') 1119 */ 1120 function remove_meta_box($id, $page, $context) { 1121 global $wp_meta_boxes; 1122 1123 if ( !isset($wp_meta_boxes) ) 1124 $wp_meta_boxes = array(); 1125 if ( !isset($wp_meta_boxes[$page]) ) 1126 $wp_meta_boxes[$page] = array(); 1127 if ( !isset($wp_meta_boxes[$page][$context]) ) 1128 $wp_meta_boxes[$page][$context] = array(); 1129 1130 foreach ( array('high', 'core', 'default', 'low') as $priority ) 1131 $wp_meta_boxes[$page][$context][$priority][$id] = false; 1072 1132 } 1073 1133
Note: See TracChangeset
for help on using the changeset viewer.