15 * |
15 * |
16 * @param string|WP_Screen $screen The screen you want the headers for |
16 * @param string|WP_Screen $screen The screen you want the headers for |
17 * @return array Containing the headers in the format id => UI String |
17 * @return array Containing the headers in the format id => UI String |
18 */ |
18 */ |
19 function get_column_headers( $screen ) { |
19 function get_column_headers( $screen ) { |
20 if ( is_string( $screen ) ) |
20 if ( is_string( $screen ) ) { |
21 $screen = convert_to_screen( $screen ); |
21 $screen = convert_to_screen( $screen ); |
|
22 } |
22 |
23 |
23 static $column_headers = array(); |
24 static $column_headers = array(); |
24 |
25 |
25 if ( ! isset( $column_headers[ $screen->id ] ) ) { |
26 if ( ! isset( $column_headers[ $screen->id ] ) ) { |
26 |
27 |
96 * @param WP_Screen $screen |
97 * @param WP_Screen $screen |
97 */ |
98 */ |
98 function meta_box_prefs( $screen ) { |
99 function meta_box_prefs( $screen ) { |
99 global $wp_meta_boxes; |
100 global $wp_meta_boxes; |
100 |
101 |
101 if ( is_string( $screen ) ) |
102 if ( is_string( $screen ) ) { |
102 $screen = convert_to_screen( $screen ); |
103 $screen = convert_to_screen( $screen ); |
103 |
104 } |
104 if ( empty($wp_meta_boxes[$screen->id]) ) |
105 |
|
106 if ( empty( $wp_meta_boxes[ $screen->id ] ) ) { |
105 return; |
107 return; |
106 |
108 } |
107 $hidden = get_hidden_meta_boxes($screen); |
109 |
|
110 $hidden = get_hidden_meta_boxes( $screen ); |
108 |
111 |
109 foreach ( array_keys( $wp_meta_boxes[ $screen->id ] ) as $context ) { |
112 foreach ( array_keys( $wp_meta_boxes[ $screen->id ] ) as $context ) { |
110 foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { |
113 foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { |
111 if ( ! isset( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] ) ) { |
114 if ( ! isset( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] ) ) { |
112 continue; |
115 continue; |
113 } |
116 } |
114 foreach ( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] as $box ) { |
117 foreach ( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] as $box ) { |
115 if ( false == $box || ! $box['title'] ) |
118 if ( false == $box || ! $box['title'] ) { |
116 continue; |
119 continue; |
|
120 } |
117 // Submit box cannot be hidden |
121 // Submit box cannot be hidden |
118 if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] ) |
122 if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] ) { |
119 continue; |
123 continue; |
|
124 } |
120 |
125 |
121 $widget_title = $box['title']; |
126 $widget_title = $box['title']; |
122 |
127 |
123 if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) { |
128 if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) { |
124 $widget_title = $box['args']['__widget_basename']; |
129 $widget_title = $box['args']['__widget_basename']; |
142 * |
147 * |
143 * @param string|WP_Screen $screen Screen identifier |
148 * @param string|WP_Screen $screen Screen identifier |
144 * @return array Hidden Meta Boxes |
149 * @return array Hidden Meta Boxes |
145 */ |
150 */ |
146 function get_hidden_meta_boxes( $screen ) { |
151 function get_hidden_meta_boxes( $screen ) { |
147 if ( is_string( $screen ) ) |
152 if ( is_string( $screen ) ) { |
148 $screen = convert_to_screen( $screen ); |
153 $screen = convert_to_screen( $screen ); |
|
154 } |
149 |
155 |
150 $hidden = get_user_option( "metaboxhidden_{$screen->id}" ); |
156 $hidden = get_user_option( "metaboxhidden_{$screen->id}" ); |
151 |
157 |
152 $use_defaults = ! is_array( $hidden ); |
158 $use_defaults = ! is_array( $hidden ); |
153 |
159 |
154 // Hide slug boxes by default |
160 // Hide slug boxes by default |
155 if ( $use_defaults ) { |
161 if ( $use_defaults ) { |
156 $hidden = array(); |
162 $hidden = array(); |
157 if ( 'post' == $screen->base ) { |
163 if ( 'post' == $screen->base ) { |
158 if ( 'post' == $screen->post_type || 'page' == $screen->post_type || 'attachment' == $screen->post_type ) |
164 if ( 'post' == $screen->post_type || 'page' == $screen->post_type || 'attachment' == $screen->post_type ) { |
159 $hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv'); |
165 $hidden = array( 'slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv' ); |
160 else |
166 } else { |
161 $hidden = array( 'slugdiv' ); |
167 $hidden = array( 'slugdiv' ); |
|
168 } |
162 } |
169 } |
163 |
170 |
164 /** |
171 /** |
165 * Filters the default list of hidden meta boxes. |
172 * Filters the default list of hidden meta boxes. |
166 * |
173 * |
194 * @param mixed $args Option-dependent arguments. |
201 * @param mixed $args Option-dependent arguments. |
195 */ |
202 */ |
196 function add_screen_option( $option, $args = array() ) { |
203 function add_screen_option( $option, $args = array() ) { |
197 $current_screen = get_current_screen(); |
204 $current_screen = get_current_screen(); |
198 |
205 |
199 if ( ! $current_screen ) |
206 if ( ! $current_screen ) { |
200 return; |
207 return; |
|
208 } |
201 |
209 |
202 $current_screen->add_option( $option, $args ); |
210 $current_screen->add_option( $option, $args ); |
203 } |
211 } |
204 |
212 |
205 /** |
213 /** |
212 * @return WP_Screen|null Current screen object or null when screen not defined. |
220 * @return WP_Screen|null Current screen object or null when screen not defined. |
213 */ |
221 */ |
214 function get_current_screen() { |
222 function get_current_screen() { |
215 global $current_screen; |
223 global $current_screen; |
216 |
224 |
217 if ( ! isset( $current_screen ) ) |
225 if ( ! isset( $current_screen ) ) { |
218 return null; |
226 return null; |
|
227 } |
219 |
228 |
220 return $current_screen; |
229 return $current_screen; |
221 } |
230 } |
222 |
231 |
223 /** |
232 /** |
224 * Set the current screen object |
233 * Set the current screen object |
225 * |
234 * |
226 * @since 3.0.0 |
235 * @since 3.0.0 |
227 * |
236 * |
228 * @param mixed $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen, |
237 * @param mixed $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen, |
229 * or an existing screen object. |
238 * or an existing screen object. |
230 */ |
239 */ |
231 function set_current_screen( $hook_name = '' ) { |
240 function set_current_screen( $hook_name = '' ) { |
232 WP_Screen::get( $hook_name )->set_current_screen(); |
241 WP_Screen::get( $hook_name )->set_current_screen(); |
233 } |
242 } |