Ticket #18958: 18958.diff

File 18958.diff, 8.3 KB (added by ryan, 19 months ago)

Speak screen in the meta box functions

Line 
1Index: wp-admin/includes/template.php
2===================================================================
3--- wp-admin/includes/template.php      (revision 19011)
4+++ wp-admin/includes/template.php      (working copy)
5@@ -839,13 +839,20 @@
6  * @param string $id String for use in the 'id' attribute of tags.
7  * @param string $title Title of the meta box.
8  * @param string $callback Function that fills the box with the desired content. The function should echo its output.
9- * @param string $page The type of edit page on which to show the box (post, page, link).
10+ * @param string|object $screen The screen on which to show the box (post, page, link).
11  * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
12  * @param string $priority The priority within the context where the boxes should show ('high', 'low').
13  */
14-function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args=null) {
15+function add_meta_box($id, $title, $callback, $screen, $context = 'advanced', $priority = 'default', $callback_args=null) {
16        global $wp_meta_boxes;
17 
18+       if ( empty( $screen ) )
19+               $screen = get_current_screen();
20+       elseif ( is_string( $screen ) )
21+               $screen = convert_to_screen( $screen );
22+
23+       $page = $screen->id;
24+
25        if ( !isset($wp_meta_boxes) )
26                $wp_meta_boxes = array();
27        if ( !isset($wp_meta_boxes[$page]) )
28@@ -899,17 +906,24 @@
29  *
30  * @since 2.5.0
31  *
32- * @param string $page page identifier, also known as screen identifier
33+ * @param string|object $screen Screen identifier
34  * @param string $context box context
35  * @param mixed $object gets passed to the box callback function as first parameter
36  * @return int number of meta_boxes
37  */
38-function do_meta_boxes($page, $context, $object) {
39+function do_meta_boxes( $screen, $context, $object ) {
40        global $wp_meta_boxes;
41        static $already_sorted = false;
42 
43-       $hidden = get_hidden_meta_boxes($page);
44+       if ( empty( $screen ) )
45+               $screen = get_current_screen();
46+       elseif ( is_string( $screen ) )
47+               $screen = convert_to_screen( $screen );
48 
49+       $page = $screen->id;
50+
51+       $hidden = get_hidden_meta_boxes( $screen );
52+
53        printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context));
54 
55        $i = 0;
56@@ -919,7 +933,7 @@
57                        foreach ( $sorted as $box_context => $ids ) {
58                                foreach ( explode(',', $ids ) as $id ) {
59                                        if ( $id && 'dashboard_browser_nag' !== $id )
60-                                               add_meta_box( $id, null, null, $page, $box_context, 'sorted' );
61+                                               add_meta_box( $id, null, null, $screen, $box_context, 'sorted' );
62                                }
63                        }
64                }
65@@ -961,12 +975,19 @@
66  * @since 2.6.0
67  *
68  * @param string $id String for use in the 'id' attribute of tags.
69- * @param string $page The type of edit page on which to show the box (post, page, link).
70+ * @param string|object $screen The screen on which to show the box (post, page, link).
71  * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
72  */
73-function remove_meta_box($id, $page, $context) {
74+function remove_meta_box($id, $screen, $context) {
75        global $wp_meta_boxes;
76 
77+       if ( empty( $screen ) )
78+               $screen = get_current_screen();
79+       elseif ( is_string( $screen ) )
80+               $screen = convert_to_screen( $screen );
81+
82+       $page = $screen->id;
83+
84        if ( !isset($wp_meta_boxes) )
85                $wp_meta_boxes = array();
86        if ( !isset($wp_meta_boxes[$page]) )
87Index: wp-admin/edit-form-advanced.php
88===================================================================
89--- wp-admin/edit-form-advanced.php     (revision 19011)
90+++ wp-admin/edit-form-advanced.php     (working copy)
91@@ -99,10 +99,10 @@
92 // All meta boxes should be defined and added before the first do_meta_boxes() call (or potentially during the do_meta_boxes action).
93 require_once('./includes/meta-boxes.php');
94 
95-add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', $post_type, 'side', 'core');
96+add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', 0, 'side', 'core');
97 
98 if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post_type, 'post-formats' ) )
99-       add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', $post_type, 'side', 'core' );
100+       add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', 0, 'side', 'core' );
101 
102 // all taxonomies
103 foreach ( get_object_taxonomies($post_type) as $tax_name ) {
104@@ -113,43 +113,43 @@
105        $label = $taxonomy->labels->name;
106 
107        if ( !is_taxonomy_hierarchical($tax_name) )
108-               add_meta_box('tagsdiv-' . $tax_name, $label, 'post_tags_meta_box', $post_type, 'side', 'core', array( 'taxonomy' => $tax_name ));
109+               add_meta_box('tagsdiv-' . $tax_name, $label, 'post_tags_meta_box', 0, 'side', 'core', array( 'taxonomy' => $tax_name ));
110        else
111-               add_meta_box($tax_name . 'div', $label, 'post_categories_meta_box', $post_type, 'side', 'core', array( 'taxonomy' => $tax_name ));
112+               add_meta_box($tax_name . 'div', $label, 'post_categories_meta_box', 0, 'side', 'core', array( 'taxonomy' => $tax_name ));
113 }
114 
115 if ( post_type_supports($post_type, 'page-attributes') )
116-       add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', $post_type, 'side', 'core');
117+       add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', 0, 'side', 'core');
118 
119 if ( current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ) )
120-               add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', $post_type, 'side', 'low');
121+               add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', 0, 'side', 'low');
122 
123 if ( post_type_supports($post_type, 'excerpt') )
124-       add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $post_type, 'normal', 'core');
125+       add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', 0, 'normal', 'core');
126 
127 if ( post_type_supports($post_type, 'trackbacks') )
128-       add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', $post_type, 'normal', 'core');
129+       add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', 0, 'normal', 'core');
130 
131 if ( post_type_supports($post_type, 'custom-fields') )
132-       add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', $post_type, 'normal', 'core');
133+       add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', 0, 'normal', 'core');
134 
135 do_action('dbx_post_advanced');
136 if ( post_type_supports($post_type, 'comments') )
137-       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', 0, 'normal', 'core');
139 
140 if ( ('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');
142+       add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', 0, 'normal', 'core');
143 
144 if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) )
145-       add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', $post_type, 'normal', 'core');
146+       add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', 0, 'normal', 'core');
147 
148 if ( post_type_supports($post_type, 'author') ) {
149        if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) )
150-               add_meta_box('authordiv', __('Author'), 'post_author_meta_box', $post_type, 'normal', 'core');
151+               add_meta_box('authordiv', __('Author'), 'post_author_meta_box', 0, 'normal', 'core');
152 }
153 
154 if ( post_type_supports($post_type, 'revisions') && 0 < $post_ID && wp_get_post_revisions( $post_ID ) )
155-       add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', $post_type, 'normal', 'core');
156+       add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', 0, 'normal', 'core');
157 
158 do_action('add_meta_boxes', $post_type, $post);
159 do_action('add_meta_boxes_' . $post_type, $post);
160@@ -347,11 +347,11 @@
161        $side_meta_boxes = do_meta_boxes($post_type, 'side', $post);
162 }
163 
164-do_meta_boxes($post_type, 'normal', $post);
165+do_meta_boxes(0, 'normal', $post);
166 
167 ( 'page' == $post_type ) ? do_action('edit_page_form') : do_action('edit_form_advanced');
168 
169-do_meta_boxes($post_type, 'advanced', $post);
170+do_meta_boxes(0, 'advanced', $post);
171 
172 do_action('dbx_post_sidebar'); ?>
173