changeset 16 | a86126ab1dd4 |
parent 9 | 177826044cd9 |
child 18 | be944660c56a |
15:3d4e9c994f10 | 16:a86126ab1dd4 |
---|---|
7 * @package WordPress |
7 * @package WordPress |
8 * @subpackage Administration |
8 * @subpackage Administration |
9 */ |
9 */ |
10 |
10 |
11 /** Walker_Category_Checklist class */ |
11 /** Walker_Category_Checklist class */ |
12 require_once( ABSPATH . 'wp-admin/includes/class-walker-category-checklist.php' ); |
12 require_once ABSPATH . 'wp-admin/includes/class-walker-category-checklist.php'; |
13 |
13 |
14 /** WP_Internal_Pointers class */ |
14 /** WP_Internal_Pointers class */ |
15 require_once( ABSPATH . 'wp-admin/includes/class-wp-internal-pointers.php' ); |
15 require_once ABSPATH . 'wp-admin/includes/class-wp-internal-pointers.php'; |
16 |
16 |
17 // |
17 // |
18 // Category Checklists |
18 // Category Checklists. |
19 // |
19 // |
20 |
20 |
21 /** |
21 /** |
22 * Output an unordered list of checkbox input elements labeled with category names. |
22 * Output an unordered list of checkbox input elements labeled with category names. |
23 * |
23 * |
30 * @param int $descendants_and_self Optional. ID of the category to output along with its descendants. |
30 * @param int $descendants_and_self Optional. ID of the category to output along with its descendants. |
31 * Default 0. |
31 * Default 0. |
32 * @param int[] $selected_cats Optional. Array of category IDs to mark as checked. Default false. |
32 * @param int[] $selected_cats Optional. Array of category IDs to mark as checked. Default false. |
33 * @param int[] $popular_cats Optional. Array of category IDs to receive the "popular-category" class. |
33 * @param int[] $popular_cats Optional. Array of category IDs to receive the "popular-category" class. |
34 * Default false. |
34 * Default false. |
35 * @param object $walker Optional. Walker object to use to build the output. |
35 * @param Walker $walker Optional. Walker object to use to build the output. |
36 * Default is a Walker_Category_Checklist instance. |
36 * Default is a Walker_Category_Checklist instance. |
37 * @param bool $checked_ontop Optional. Whether to move checked items out of the hierarchy and to |
37 * @param bool $checked_ontop Optional. Whether to move checked items out of the hierarchy and to |
38 * the top of the list. Default true. |
38 * the top of the list. Default true. |
39 */ |
39 */ |
40 function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) { |
40 function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) { |
66 * @type int $descendants_and_self ID of the category to output along with its descendants. |
66 * @type int $descendants_and_self ID of the category to output along with its descendants. |
67 * Default 0. |
67 * Default 0. |
68 * @type int[] $selected_cats Array of category IDs to mark as checked. Default false. |
68 * @type int[] $selected_cats Array of category IDs to mark as checked. Default false. |
69 * @type int[] $popular_cats Array of category IDs to receive the "popular-category" class. |
69 * @type int[] $popular_cats Array of category IDs to receive the "popular-category" class. |
70 * Default false. |
70 * Default false. |
71 * @type object $walker Walker object to use to build the output. |
71 * @type Walker $walker Walker object to use to build the output. |
72 * Default is a Walker_Category_Checklist instance. |
72 * Default is a Walker_Category_Checklist instance. |
73 * @type string $taxonomy Taxonomy to generate the checklist for. Default 'category'. |
73 * @type string $taxonomy Taxonomy to generate the checklist for. Default 'category'. |
74 * @type bool $checked_ontop Whether to move checked items out of the hierarchy and to |
74 * @type bool $checked_ontop Whether to move checked items out of the hierarchy and to |
75 * the top of the list. Default true. |
75 * the top of the list. Default true. |
76 * @type bool $echo Whether to echo the generated markup. False to return the markup instead |
76 * @type bool $echo Whether to echo the generated markup. False to return the markup instead |
77 * of echoing it. Default true. |
77 * of echoing it. Default true. |
78 * } |
78 * } |
79 * @return string HTML list of input elements. |
|
79 */ |
80 */ |
80 function wp_terms_checklist( $post_id = 0, $args = array() ) { |
81 function wp_terms_checklist( $post_id = 0, $args = array() ) { |
81 $defaults = array( |
82 $defaults = array( |
82 'descendants_and_self' => 0, |
83 'descendants_and_self' => 0, |
83 'selected_cats' => false, |
84 'selected_cats' => false, |
98 * @param array $args An array of arguments. |
99 * @param array $args An array of arguments. |
99 * @param int $post_id The post ID. |
100 * @param int $post_id The post ID. |
100 */ |
101 */ |
101 $params = apply_filters( 'wp_terms_checklist_args', $args, $post_id ); |
102 $params = apply_filters( 'wp_terms_checklist_args', $args, $post_id ); |
102 |
103 |
103 $r = wp_parse_args( $params, $defaults ); |
104 $parsed_args = wp_parse_args( $params, $defaults ); |
104 |
105 |
105 if ( empty( $r['walker'] ) || ! ( $r['walker'] instanceof Walker ) ) { |
106 if ( empty( $parsed_args['walker'] ) || ! ( $parsed_args['walker'] instanceof Walker ) ) { |
106 $walker = new Walker_Category_Checklist; |
107 $walker = new Walker_Category_Checklist; |
107 } else { |
108 } else { |
108 $walker = $r['walker']; |
109 $walker = $parsed_args['walker']; |
109 } |
110 } |
110 |
111 |
111 $taxonomy = $r['taxonomy']; |
112 $taxonomy = $parsed_args['taxonomy']; |
112 $descendants_and_self = (int) $r['descendants_and_self']; |
113 $descendants_and_self = (int) $parsed_args['descendants_and_self']; |
113 |
114 |
114 $args = array( 'taxonomy' => $taxonomy ); |
115 $args = array( 'taxonomy' => $taxonomy ); |
115 |
116 |
116 $tax = get_taxonomy( $taxonomy ); |
117 $tax = get_taxonomy( $taxonomy ); |
117 $args['disabled'] = ! current_user_can( $tax->cap->assign_terms ); |
118 $args['disabled'] = ! current_user_can( $tax->cap->assign_terms ); |
118 |
119 |
119 $args['list_only'] = ! empty( $r['list_only'] ); |
120 $args['list_only'] = ! empty( $parsed_args['list_only'] ); |
120 |
121 |
121 if ( is_array( $r['selected_cats'] ) ) { |
122 if ( is_array( $parsed_args['selected_cats'] ) ) { |
122 $args['selected_cats'] = $r['selected_cats']; |
123 $args['selected_cats'] = array_map( 'intval', $parsed_args['selected_cats'] ); |
123 } elseif ( $post_id ) { |
124 } elseif ( $post_id ) { |
124 $args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) ); |
125 $args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) ); |
125 } else { |
126 } else { |
126 $args['selected_cats'] = array(); |
127 $args['selected_cats'] = array(); |
127 } |
128 } |
128 if ( is_array( $r['popular_cats'] ) ) { |
129 |
129 $args['popular_cats'] = $r['popular_cats']; |
130 if ( is_array( $parsed_args['popular_cats'] ) ) { |
131 $args['popular_cats'] = array_map( 'intval', $parsed_args['popular_cats'] ); |
|
130 } else { |
132 } else { |
131 $args['popular_cats'] = get_terms( |
133 $args['popular_cats'] = get_terms( |
132 $taxonomy, |
|
133 array( |
134 array( |
135 'taxonomy' => $taxonomy, |
|
134 'fields' => 'ids', |
136 'fields' => 'ids', |
135 'orderby' => 'count', |
137 'orderby' => 'count', |
136 'order' => 'DESC', |
138 'order' => 'DESC', |
137 'number' => 10, |
139 'number' => 10, |
138 'hierarchical' => false, |
140 'hierarchical' => false, |
139 ) |
141 ) |
140 ); |
142 ); |
141 } |
143 } |
144 |
|
142 if ( $descendants_and_self ) { |
145 if ( $descendants_and_self ) { |
143 $categories = (array) get_terms( |
146 $categories = (array) get_terms( |
144 $taxonomy, |
|
145 array( |
147 array( |
148 'taxonomy' => $taxonomy, |
|
146 'child_of' => $descendants_and_self, |
149 'child_of' => $descendants_and_self, |
147 'hierarchical' => 0, |
150 'hierarchical' => 0, |
148 'hide_empty' => 0, |
151 'hide_empty' => 0, |
149 ) |
152 ) |
150 ); |
153 ); |
151 $self = get_term( $descendants_and_self, $taxonomy ); |
154 $self = get_term( $descendants_and_self, $taxonomy ); |
152 array_unshift( $categories, $self ); |
155 array_unshift( $categories, $self ); |
153 } else { |
156 } else { |
154 $categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) ); |
157 $categories = (array) get_terms( |
158 array( |
|
159 'taxonomy' => $taxonomy, |
|
160 'get' => 'all', |
|
161 ) |
|
162 ); |
|
155 } |
163 } |
156 |
164 |
157 $output = ''; |
165 $output = ''; |
158 |
166 |
159 if ( $r['checked_ontop'] ) { |
167 if ( $parsed_args['checked_ontop'] ) { |
160 // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache) |
168 // Post-process $categories rather than adding an exclude to the get_terms() query |
169 // to keep the query the same across all posts (for any query cache). |
|
161 $checked_categories = array(); |
170 $checked_categories = array(); |
162 $keys = array_keys( $categories ); |
171 $keys = array_keys( $categories ); |
163 |
172 |
164 foreach ( $keys as $k ) { |
173 foreach ( $keys as $k ) { |
165 if ( in_array( $categories[ $k ]->term_id, $args['selected_cats'] ) ) { |
174 if ( in_array( $categories[ $k ]->term_id, $args['selected_cats'], true ) ) { |
166 $checked_categories[] = $categories[ $k ]; |
175 $checked_categories[] = $categories[ $k ]; |
167 unset( $categories[ $k ] ); |
176 unset( $categories[ $k ] ); |
168 } |
177 } |
169 } |
178 } |
170 |
179 |
171 // Put checked cats on top |
180 // Put checked categories on top. |
172 $output .= call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) ); |
181 $output .= $walker->walk( $checked_categories, 0, $args ); |
173 } |
182 } |
174 // Then the rest of them |
183 // Then the rest of them. |
175 $output .= call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) ); |
184 $output .= $walker->walk( $categories, 0, $args ); |
176 |
185 |
177 if ( $r['echo'] ) { |
186 if ( $parsed_args['echo'] ) { |
178 echo $output; |
187 echo $output; |
179 } |
188 } |
180 |
189 |
181 return $output; |
190 return $output; |
182 } |
191 } |
190 * post will be marked as checked. |
199 * post will be marked as checked. |
191 * |
200 * |
192 * @since 2.5.0 |
201 * @since 2.5.0 |
193 * |
202 * |
194 * @param string $taxonomy Taxonomy to retrieve terms from. |
203 * @param string $taxonomy Taxonomy to retrieve terms from. |
195 * @param int $default Not used. |
204 * @param int $default Not used. |
196 * @param int $number Number of terms to retrieve. Defaults to 10. |
205 * @param int $number Number of terms to retrieve. Defaults to 10. |
197 * @param bool $echo Optionally output the list as well. Defaults to true. |
206 * @param bool $echo Optionally output the list as well. Defaults to true. |
198 * @return array List of popular term IDs. |
207 * @return int[] Array of popular term IDs. |
199 */ |
208 */ |
200 function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) { |
209 function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) { |
201 $post = get_post(); |
210 $post = get_post(); |
202 |
211 |
203 if ( $post && $post->ID ) { |
212 if ( $post && $post->ID ) { |
205 } else { |
214 } else { |
206 $checked_terms = array(); |
215 $checked_terms = array(); |
207 } |
216 } |
208 |
217 |
209 $terms = get_terms( |
218 $terms = get_terms( |
210 $taxonomy, |
|
211 array( |
219 array( |
220 'taxonomy' => $taxonomy, |
|
212 'orderby' => 'count', |
221 'orderby' => 'count', |
213 'order' => 'DESC', |
222 'order' => 'DESC', |
214 'number' => $number, |
223 'number' => $number, |
215 'hierarchical' => false, |
224 'hierarchical' => false, |
216 ) |
225 ) |
217 ); |
226 ); |
218 |
227 |
219 $tax = get_taxonomy( $taxonomy ); |
228 $tax = get_taxonomy( $taxonomy ); |
220 |
229 |
221 $popular_ids = array(); |
230 $popular_ids = array(); |
231 |
|
222 foreach ( (array) $terms as $term ) { |
232 foreach ( (array) $terms as $term ) { |
223 $popular_ids[] = $term->term_id; |
233 $popular_ids[] = $term->term_id; |
224 if ( ! $echo ) { // Hack for Ajax use. |
234 if ( ! $echo ) { // Hack for Ajax use. |
225 continue; |
235 continue; |
226 } |
236 } |
227 $id = "popular-$taxonomy-$term->term_id"; |
237 $id = "popular-$taxonomy-$term->term_id"; |
228 $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : ''; |
238 $checked = in_array( $term->term_id, $checked_terms, true ) ? 'checked="checked"' : ''; |
229 ?> |
239 ?> |
230 |
240 |
231 <li id="<?php echo $id; ?>" class="popular-category"> |
241 <li id="<?php echo $id; ?>" class="popular-category"> |
232 <label class="selectit"> |
242 <label class="selectit"> |
233 <input id="in-<?php echo $id; ?>" type="checkbox" <?php echo $checked; ?> value="<?php echo (int) $term->term_id; ?>" <?php disabled( ! current_user_can( $tax->cap->assign_terms ) ); ?> /> |
243 <input id="in-<?php echo $id; ?>" type="checkbox" <?php echo $checked; ?> value="<?php echo (int) $term->term_id; ?>" <?php disabled( ! current_user_can( $tax->cap->assign_terms ) ); ?> /> |
255 |
265 |
256 $checked_categories = array(); |
266 $checked_categories = array(); |
257 |
267 |
258 if ( $link_id ) { |
268 if ( $link_id ) { |
259 $checked_categories = wp_get_link_cats( $link_id ); |
269 $checked_categories = wp_get_link_cats( $link_id ); |
260 // No selected categories, strange |
270 // No selected categories, strange. |
261 if ( ! count( $checked_categories ) ) { |
271 if ( ! count( $checked_categories ) ) { |
262 $checked_categories[] = $default; |
272 $checked_categories[] = $default; |
263 } |
273 } |
264 } else { |
274 } else { |
265 $checked_categories[] = $default; |
275 $checked_categories[] = $default; |
266 } |
276 } |
267 |
277 |
268 $categories = get_terms( |
278 $categories = get_terms( |
269 'link_category', |
|
270 array( |
279 array( |
280 'taxonomy' => 'link_category', |
|
271 'orderby' => 'name', |
281 'orderby' => 'name', |
272 'hide_empty' => 0, |
282 'hide_empty' => 0, |
273 ) |
283 ) |
274 ); |
284 ); |
275 |
285 |
280 foreach ( $categories as $category ) { |
290 foreach ( $categories as $category ) { |
281 $cat_id = $category->term_id; |
291 $cat_id = $category->term_id; |
282 |
292 |
283 /** This filter is documented in wp-includes/category-template.php */ |
293 /** This filter is documented in wp-includes/category-template.php */ |
284 $name = esc_html( apply_filters( 'the_category', $category->name, '', '' ) ); |
294 $name = esc_html( apply_filters( 'the_category', $category->name, '', '' ) ); |
285 $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : ''; |
295 $checked = in_array( $cat_id, $checked_categories, true ) ? ' checked="checked"' : ''; |
286 echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked, '/> ', $name, '</label></li>'; |
296 echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked, '/> ', $name, '</label></li>'; |
287 } |
297 } |
288 } |
298 } |
289 |
299 |
290 /** |
300 /** |
300 return; |
310 return; |
301 } |
311 } |
302 |
312 |
303 $title = esc_textarea( trim( $post->post_title ) ); |
313 $title = esc_textarea( trim( $post->post_title ) ); |
304 |
314 |
305 /** This filter is documented in wp-admin/edit-tag-form.php */ |
|
306 echo ' |
315 echo ' |
307 <div class="hidden" id="inline_' . $post->ID . '"> |
316 <div class="hidden" id="inline_' . $post->ID . '"> |
308 <div class="post_title">' . $title . '</div>' . |
317 <div class="post_title">' . $title . '</div>' . |
309 /** This filter is documented in wp-admin/edit-tag-form.php */ |
318 /** This filter is documented in wp-admin/edit-tag-form.php */ |
310 '<div class="post_name">' . apply_filters( 'editable_slug', $post->post_name, $post ) . '</div> |
319 '<div class="post_name">' . apply_filters( 'editable_slug', $post->post_name, $post ) . '</div> |
329 if ( post_type_supports( $post->post_type, 'page-attributes' ) ) { |
338 if ( post_type_supports( $post->post_type, 'page-attributes' ) ) { |
330 echo '<div class="menu_order">' . $post->menu_order . '</div>'; |
339 echo '<div class="menu_order">' . $post->menu_order . '</div>'; |
331 } |
340 } |
332 |
341 |
333 $taxonomy_names = get_object_taxonomies( $post->post_type ); |
342 $taxonomy_names = get_object_taxonomies( $post->post_type ); |
343 |
|
334 foreach ( $taxonomy_names as $taxonomy_name ) { |
344 foreach ( $taxonomy_names as $taxonomy_name ) { |
335 $taxonomy = get_taxonomy( $taxonomy_name ); |
345 $taxonomy = get_taxonomy( $taxonomy_name ); |
336 |
346 |
337 if ( $taxonomy->hierarchical && $taxonomy->show_ui ) { |
347 if ( $taxonomy->hierarchical && $taxonomy->show_ui ) { |
338 |
348 |
422 echo $content; |
432 echo $content; |
423 return; |
433 return; |
424 } |
434 } |
425 |
435 |
426 if ( ! $wp_list_table ) { |
436 if ( ! $wp_list_table ) { |
427 if ( $mode == 'single' ) { |
437 if ( 'single' === $mode ) { |
428 $wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table' ); |
438 $wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table' ); |
429 } else { |
439 } else { |
430 $wp_list_table = _get_list_table( 'WP_Comments_List_Table' ); |
440 $wp_list_table = _get_list_table( 'WP_Comments_List_Table' ); |
431 } |
441 } |
432 } |
442 } |
515 </form> |
525 </form> |
516 <?php |
526 <?php |
517 } |
527 } |
518 |
528 |
519 /** |
529 /** |
520 * Output 'undo move to trash' text for comments |
530 * Output 'undo move to Trash' text for comments |
521 * |
531 * |
522 * @since 2.9.0 |
532 * @since 2.9.0 |
523 */ |
533 */ |
524 function wp_comment_trashnotice() { |
534 function wp_comment_trashnotice() { |
525 ?> |
535 ?> |
526 <div class="hidden" id="trash-undo-holder"> |
536 <div class="hidden" id="trash-undo-holder"> |
527 <div class="trash-undo-inside"><?php printf( __( 'Comment by %s moved to the trash.' ), '<strong></strong>' ); ?> <span class="undo untrash"><a href="#"><?php _e( 'Undo' ); ?></a></span></div> |
537 <div class="trash-undo-inside"> |
538 <?php |
|
539 /* translators: %s: Comment author, filled by Ajax. */ |
|
540 printf( __( 'Comment by %s moved to the Trash.' ), '<strong></strong>' ); |
|
541 ?> |
|
542 <span class="undo untrash"><a href="#"><?php _e( 'Undo' ); ?></a></span> |
|
543 </div> |
|
528 </div> |
544 </div> |
529 <div class="hidden" id="spam-undo-holder"> |
545 <div class="hidden" id="spam-undo-holder"> |
530 <div class="spam-undo-inside"><?php printf( __( 'Comment by %s marked as spam.' ), '<strong></strong>' ); ?> <span class="undo unspam"><a href="#"><?php _e( 'Undo' ); ?></a></span></div> |
546 <div class="spam-undo-inside"> |
547 <?php |
|
548 /* translators: %s: Comment author, filled by Ajax. */ |
|
549 printf( __( 'Comment by %s marked as spam.' ), '<strong></strong>' ); |
|
550 ?> |
|
551 <span class="undo unspam"><a href="#"><?php _e( 'Undo' ); ?></a></span> |
|
552 </div> |
|
531 </div> |
553 </div> |
532 <?php |
554 <?php |
533 } |
555 } |
534 |
556 |
535 /** |
557 /** |
538 * @since 1.2.0 |
560 * @since 1.2.0 |
539 * |
561 * |
540 * @param array $meta |
562 * @param array $meta |
541 */ |
563 */ |
542 function list_meta( $meta ) { |
564 function list_meta( $meta ) { |
543 // Exit if no meta |
565 // Exit if no meta. |
544 if ( ! $meta ) { |
566 if ( ! $meta ) { |
545 echo ' |
567 echo ' |
546 <table id="list-table" style="display: none;"> |
568 <table id="list-table" style="display: none;"> |
547 <thead> |
569 <thead> |
548 <tr> |
570 <tr> |
551 </tr> |
573 </tr> |
552 </thead> |
574 </thead> |
553 <tbody id="the-list" data-wp-lists="list:meta"> |
575 <tbody id="the-list" data-wp-lists="list:meta"> |
554 <tr><td></td></tr> |
576 <tr><td></td></tr> |
555 </tbody> |
577 </tbody> |
556 </table>'; //TBODY needed for list-manipulation JS |
578 </table>'; // TBODY needed for list-manipulation JS. |
557 return; |
579 return; |
558 } |
580 } |
559 $count = 0; |
581 $count = 0; |
560 ?> |
582 ?> |
561 <table id="list-table"> |
583 <table id="list-table"> |
579 /** |
601 /** |
580 * Outputs a single row of public meta data in the Custom Fields meta box. |
602 * Outputs a single row of public meta data in the Custom Fields meta box. |
581 * |
603 * |
582 * @since 2.5.0 |
604 * @since 2.5.0 |
583 * |
605 * |
584 * @staticvar string $update_nonce |
|
585 * |
|
586 * @param array $entry |
606 * @param array $entry |
587 * @param int $count |
607 * @param int $count |
588 * @return string |
608 * @return string |
589 */ |
609 */ |
590 function _list_meta_row( $entry, &$count ) { |
610 function _list_meta_row( $entry, &$count ) { |
611 return ''; |
631 return ''; |
612 } |
632 } |
613 } |
633 } |
614 |
634 |
615 $entry['meta_key'] = esc_attr( $entry['meta_key'] ); |
635 $entry['meta_key'] = esc_attr( $entry['meta_key'] ); |
616 $entry['meta_value'] = esc_textarea( $entry['meta_value'] ); // using a <textarea /> |
636 $entry['meta_value'] = esc_textarea( $entry['meta_value'] ); // Using a <textarea />. |
617 $entry['meta_id'] = (int) $entry['meta_id']; |
637 $entry['meta_id'] = (int) $entry['meta_id']; |
618 |
638 |
619 $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] ); |
639 $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] ); |
620 |
640 |
621 $r .= "\n\t<tr id='meta-{$entry['meta_id']}'>"; |
641 $r .= "\n\t<tr id='meta-{$entry['meta_id']}'>"; |
667 * @since 2.1.0 |
687 * @since 2.1.0 |
668 * |
688 * |
669 * @param int $limit Number of custom fields to retrieve. Default 30. |
689 * @param int $limit Number of custom fields to retrieve. Default 30. |
670 */ |
690 */ |
671 $limit = apply_filters( 'postmeta_form_limit', 30 ); |
691 $limit = apply_filters( 'postmeta_form_limit', 30 ); |
672 $sql = "SELECT DISTINCT meta_key |
692 |
673 FROM $wpdb->postmeta |
693 $keys = $wpdb->get_col( |
674 WHERE meta_key NOT BETWEEN '_' AND '_z' |
694 $wpdb->prepare( |
675 HAVING meta_key NOT LIKE %s |
695 "SELECT DISTINCT meta_key |
676 ORDER BY meta_key |
696 FROM $wpdb->postmeta |
677 LIMIT %d"; |
697 WHERE meta_key NOT BETWEEN '_' AND '_z' |
678 $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) ); |
698 HAVING meta_key NOT LIKE %s |
699 ORDER BY meta_key |
|
700 LIMIT %d", |
|
701 $wpdb->esc_like( '_' ) . '%', |
|
702 $limit |
|
703 ) |
|
704 ); |
|
679 } |
705 } |
680 |
706 |
681 if ( $keys ) { |
707 if ( $keys ) { |
682 natcasesort( $keys ); |
708 natcasesort( $keys ); |
683 $meta_key_input_id = 'metakeyselect'; |
709 $meta_key_input_id = 'metakeyselect'; |
699 <td id="newmetaleft" class="left"> |
725 <td id="newmetaleft" class="left"> |
700 <?php if ( $keys ) { ?> |
726 <?php if ( $keys ) { ?> |
701 <select id="metakeyselect" name="metakeyselect"> |
727 <select id="metakeyselect" name="metakeyselect"> |
702 <option value="#NONE#"><?php _e( '— Select —' ); ?></option> |
728 <option value="#NONE#"><?php _e( '— Select —' ); ?></option> |
703 <?php |
729 <?php |
704 |
|
705 foreach ( $keys as $key ) { |
730 foreach ( $keys as $key ) { |
706 if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $post->ID, $key ) ) { |
731 if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $post->ID, $key ) ) { |
707 continue; |
732 continue; |
708 } |
733 } |
709 echo "\n<option value='" . esc_attr( $key ) . "'>" . esc_html( $key ) . '</option>'; |
734 echo "\n<option value='" . esc_attr( $key ) . "'>" . esc_html( $key ) . '</option>'; |
748 * Print out HTML form date elements for editing post or comment publish date. |
773 * Print out HTML form date elements for editing post or comment publish date. |
749 * |
774 * |
750 * @since 0.71 |
775 * @since 0.71 |
751 * @since 4.4.0 Converted to use get_comment() instead of the global `$comment`. |
776 * @since 4.4.0 Converted to use get_comment() instead of the global `$comment`. |
752 * |
777 * |
753 * @global WP_Locale $wp_locale |
778 * @global WP_Locale $wp_locale WordPress date and time locale object. |
754 * |
779 * |
755 * @param int|bool $edit Accepts 1|true for editing the date, 0|false for adding the date. |
780 * @param int|bool $edit Accepts 1|true for editing the date, 0|false for adding the date. |
756 * @param int|bool $for_post Accepts 1|true for applying the date to a post, 0|false for a comment. |
781 * @param int|bool $for_post Accepts 1|true for applying the date to a post, 0|false for a comment. |
757 * @param int $tab_index The tabindex attribute to add. Default 0. |
782 * @param int $tab_index The tabindex attribute to add. Default 0. |
758 * @param int|bool $multi Optional. Whether the additional fields and buttons should be added. |
783 * @param int|bool $multi Optional. Whether the additional fields and buttons should be added. |
761 function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { |
786 function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { |
762 global $wp_locale; |
787 global $wp_locale; |
763 $post = get_post(); |
788 $post = get_post(); |
764 |
789 |
765 if ( $for_post ) { |
790 if ( $for_post ) { |
766 $edit = ! ( in_array( $post->post_status, array( 'draft', 'pending' ) ) && ( ! $post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) ); |
791 $edit = ! ( in_array( $post->post_status, array( 'draft', 'pending' ), true ) && ( ! $post->post_date_gmt || '0000-00-00 00:00:00' === $post->post_date_gmt ) ); |
767 } |
792 } |
768 |
793 |
769 $tab_index_attribute = ''; |
794 $tab_index_attribute = ''; |
770 if ( (int) $tab_index > 0 ) { |
795 if ( (int) $tab_index > 0 ) { |
771 $tab_index_attribute = " tabindex=\"$tab_index\""; |
796 $tab_index_attribute = " tabindex=\"$tab_index\""; |
772 } |
797 } |
773 |
798 |
774 // todo: Remove this? |
799 // @todo Remove this? |
775 // echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />'; |
800 // echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />'; |
776 |
801 |
777 $post_date = ( $for_post ) ? $post->post_date : get_comment()->comment_date; |
802 $post_date = ( $for_post ) ? $post->post_date : get_comment()->comment_date; |
778 $jj = ( $edit ) ? mysql2date( 'd', $post_date, false ) : current_time( 'd' ); |
803 $jj = ( $edit ) ? mysql2date( 'd', $post_date, false ) : current_time( 'd' ); |
779 $mm = ( $edit ) ? mysql2date( 'm', $post_date, false ) : current_time( 'm' ); |
804 $mm = ( $edit ) ? mysql2date( 'm', $post_date, false ) : current_time( 'm' ); |
791 $month = '<label><span class="screen-reader-text">' . __( 'Month' ) . '</span><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n"; |
816 $month = '<label><span class="screen-reader-text">' . __( 'Month' ) . '</span><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n"; |
792 for ( $i = 1; $i < 13; $i = $i + 1 ) { |
817 for ( $i = 1; $i < 13; $i = $i + 1 ) { |
793 $monthnum = zeroise( $i, 2 ); |
818 $monthnum = zeroise( $i, 2 ); |
794 $monthtext = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ); |
819 $monthtext = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ); |
795 $month .= "\t\t\t" . '<option value="' . $monthnum . '" data-text="' . $monthtext . '" ' . selected( $monthnum, $mm, false ) . '>'; |
820 $month .= "\t\t\t" . '<option value="' . $monthnum . '" data-text="' . $monthtext . '" ' . selected( $monthnum, $mm, false ) . '>'; |
796 /* translators: 1: month number (01, 02, etc.), 2: month abbreviation */ |
821 /* translators: 1: Month number (01, 02, etc.), 2: Month abbreviation. */ |
797 $month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $monthtext ) . "</option>\n"; |
822 $month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $monthtext ) . "</option>\n"; |
798 } |
823 } |
799 $month .= '</select></label>'; |
824 $month .= '</select></label>'; |
800 |
825 |
801 $day = '<label><span class="screen-reader-text">' . __( 'Day' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>'; |
826 $day = '<label><span class="screen-reader-text">' . __( 'Day' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>'; |
802 $year = '<label><span class="screen-reader-text">' . __( 'Year' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" /></label>'; |
827 $year = '<label><span class="screen-reader-text">' . __( 'Year' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" /></label>'; |
803 $hour = '<label><span class="screen-reader-text">' . __( 'Hour' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>'; |
828 $hour = '<label><span class="screen-reader-text">' . __( 'Hour' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>'; |
804 $minute = '<label><span class="screen-reader-text">' . __( 'Minute' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>'; |
829 $minute = '<label><span class="screen-reader-text">' . __( 'Minute' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>'; |
805 |
830 |
806 echo '<div class="timestamp-wrap">'; |
831 echo '<div class="timestamp-wrap">'; |
807 /* translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */ |
832 /* translators: 1: Month, 2: Day, 3: Year, 4: Hour, 5: Minute. */ |
808 printf( __( '%1$s %2$s, %3$s @ %4$s:%5$s' ), $month, $day, $year, $hour, $minute ); |
833 printf( __( '%1$s %2$s, %3$s at %4$s:%5$s' ), $month, $day, $year, $hour, $minute ); |
809 |
834 |
810 echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />'; |
835 echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />'; |
811 |
836 |
812 if ( $multi ) { |
837 if ( $multi ) { |
813 return; |
838 return; |
814 } |
839 } |
815 |
840 |
816 echo "\n\n"; |
841 echo "\n\n"; |
842 |
|
817 $map = array( |
843 $map = array( |
818 'mm' => array( $mm, $cur_mm ), |
844 'mm' => array( $mm, $cur_mm ), |
819 'jj' => array( $jj, $cur_jj ), |
845 'jj' => array( $jj, $cur_jj ), |
820 'aa' => array( $aa, $cur_aa ), |
846 'aa' => array( $aa, $cur_aa ), |
821 'hh' => array( $hh, $cur_hh ), |
847 'hh' => array( $hh, $cur_hh ), |
822 'mn' => array( $mn, $cur_mn ), |
848 'mn' => array( $mn, $cur_mn ), |
823 ); |
849 ); |
850 |
|
824 foreach ( $map as $timeunit => $value ) { |
851 foreach ( $map as $timeunit => $value ) { |
825 list( $unit, $curr ) = $value; |
852 list( $unit, $curr ) = $value; |
826 |
853 |
827 echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $unit . '" />' . "\n"; |
854 echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $unit . '" />' . "\n"; |
828 $cur_timeunit = 'cur_' . $timeunit; |
855 $cur_timeunit = 'cur_' . $timeunit; |
846 * @param string $default Optional. The template file name. Default empty. |
873 * @param string $default Optional. The template file name. Default empty. |
847 * @param string $post_type Optional. Post type to get templates for. Default 'post'. |
874 * @param string $post_type Optional. Post type to get templates for. Default 'post'. |
848 */ |
875 */ |
849 function page_template_dropdown( $default = '', $post_type = 'page' ) { |
876 function page_template_dropdown( $default = '', $post_type = 'page' ) { |
850 $templates = get_page_templates( null, $post_type ); |
877 $templates = get_page_templates( null, $post_type ); |
878 |
|
851 ksort( $templates ); |
879 ksort( $templates ); |
880 |
|
852 foreach ( array_keys( $templates ) as $template ) { |
881 foreach ( array_keys( $templates ) as $template ) { |
853 $selected = selected( $default, $templates[ $template ], false ); |
882 $selected = selected( $default, $templates[ $template ], false ); |
854 echo "\n\t<option value='" . esc_attr( $templates[ $template ] ) . "' $selected>" . esc_html( $template ) . '</option>'; |
883 echo "\n\t<option value='" . esc_attr( $templates[ $template ] ) . "' $selected>" . esc_html( $template ) . '</option>'; |
855 } |
884 } |
856 } |
885 } |
865 * |
894 * |
866 * @param int $default Optional. The default page ID to be pre-selected. Default 0. |
895 * @param int $default Optional. The default page ID to be pre-selected. Default 0. |
867 * @param int $parent Optional. The parent page ID. Default 0. |
896 * @param int $parent Optional. The parent page ID. Default 0. |
868 * @param int $level Optional. Page depth level. Default 0. |
897 * @param int $level Optional. Page depth level. Default 0. |
869 * @param int|WP_Post $post Post ID or WP_Post object. |
898 * @param int|WP_Post $post Post ID or WP_Post object. |
870 * |
899 * @return void|false Void on success, false if the page has no children. |
871 * @return null|false Boolean False if page has no children, otherwise print out html elements. |
|
872 */ |
900 */ |
873 function parent_dropdown( $default = 0, $parent = 0, $level = 0, $post = null ) { |
901 function parent_dropdown( $default = 0, $parent = 0, $level = 0, $post = null ) { |
874 global $wpdb; |
902 global $wpdb; |
903 |
|
875 $post = get_post( $post ); |
904 $post = get_post( $post ); |
876 $items = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent ) ); |
905 $items = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent ) ); |
877 |
906 |
878 if ( $items ) { |
907 if ( $items ) { |
879 foreach ( $items as $item ) { |
908 foreach ( $items as $item ) { |
880 // A page cannot be its own parent. |
909 // A page cannot be its own parent. |
881 if ( $post && $post->ID && $item->ID == $post->ID ) { |
910 if ( $post && $post->ID && (int) $item->ID === $post->ID ) { |
882 continue; |
911 continue; |
883 } |
912 } |
884 |
913 |
885 $pad = str_repeat( ' ', $level * 3 ); |
914 $pad = str_repeat( ' ', $level * 3 ); |
886 $selected = selected( $default, $item->ID, false ); |
915 $selected = selected( $default, $item->ID, false ); |
892 return false; |
921 return false; |
893 } |
922 } |
894 } |
923 } |
895 |
924 |
896 /** |
925 /** |
897 * Print out option html elements for role selectors. |
926 * Print out option HTML elements for role selectors. |
898 * |
927 * |
899 * @since 2.1.0 |
928 * @since 2.1.0 |
900 * |
929 * |
901 * @param string $selected Slug for the role that should be already selected. |
930 * @param string $selected Slug for the role that should be already selected. |
902 */ |
931 */ |
905 |
934 |
906 $editable_roles = array_reverse( get_editable_roles() ); |
935 $editable_roles = array_reverse( get_editable_roles() ); |
907 |
936 |
908 foreach ( $editable_roles as $role => $details ) { |
937 foreach ( $editable_roles as $role => $details ) { |
909 $name = translate_user_role( $details['name'] ); |
938 $name = translate_user_role( $details['name'] ); |
910 // preselect specified role |
939 // Preselect specified role. |
911 if ( $selected == $role ) { |
940 if ( $selected === $role ) { |
912 $r .= "\n\t<option selected='selected' value='" . esc_attr( $role ) . "'>$name</option>"; |
941 $r .= "\n\t<option selected='selected' value='" . esc_attr( $role ) . "'>$name</option>"; |
913 } else { |
942 } else { |
914 $r .= "\n\t<option value='" . esc_attr( $role ) . "'>$name</option>"; |
943 $r .= "\n\t<option value='" . esc_attr( $role ) . "'>$name</option>"; |
915 } |
944 } |
916 } |
945 } |
946 <?php |
975 <?php |
947 else : |
976 else : |
948 ?> |
977 ?> |
949 <form enctype="multipart/form-data" id="import-upload-form" method="post" class="wp-upload-form" action="<?php echo esc_url( wp_nonce_url( $action, 'import-upload' ) ); ?>"> |
978 <form enctype="multipart/form-data" id="import-upload-form" method="post" class="wp-upload-form" action="<?php echo esc_url( wp_nonce_url( $action, 'import-upload' ) ); ?>"> |
950 <p> |
979 <p> |
951 <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __( 'Maximum size: %s' ), $size ); ?>) |
980 <?php |
981 printf( |
|
982 '<label for="upload">%s</label> (%s)', |
|
983 __( 'Choose a file from your computer:' ), |
|
984 /* translators: %s: Maximum allowed file size. */ |
|
985 sprintf( __( 'Maximum size: %s' ), $size ) |
|
986 ); |
|
987 ?> |
|
952 <input type="file" id="upload" name="import" size="25" /> |
988 <input type="file" id="upload" name="import" size="25" /> |
953 <input type="hidden" name="action" value="save" /> |
989 <input type="hidden" name="action" value="save" /> |
954 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" /> |
990 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" /> |
955 </p> |
991 </p> |
956 <?php submit_button( __( 'Upload file and import' ), 'primary' ); ?> |
992 <?php submit_button( __( 'Upload file and import' ), 'primary' ); ?> |
1023 foreach ( array( 'high', 'core', 'default', 'low' ) as $a_priority ) { |
1059 foreach ( array( 'high', 'core', 'default', 'low' ) as $a_priority ) { |
1024 if ( ! isset( $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] ) ) { |
1060 if ( ! isset( $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] ) ) { |
1025 continue; |
1061 continue; |
1026 } |
1062 } |
1027 |
1063 |
1028 // If a core box was previously added or removed by a plugin, don't add. |
1064 // If a core box was previously removed, don't add. |
1029 if ( 'core' == $priority ) { |
1065 if ( ( 'core' === $priority || 'sorted' === $priority ) |
1030 // If core box previously deleted, don't add |
1066 && false === $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] |
1031 if ( false === $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] ) { |
1067 ) { |
1032 return; |
1068 return; |
1033 } |
1069 } |
1034 |
1070 |
1071 // If a core box was previously added by a plugin, don't add. |
|
1072 if ( 'core' === $priority ) { |
|
1035 /* |
1073 /* |
1036 * If box was added with default priority, give it core priority to |
1074 * If the box was added with default priority, give it core priority |
1037 * maintain sort order. |
1075 * to maintain sort order. |
1038 */ |
1076 */ |
1039 if ( 'default' == $a_priority ) { |
1077 if ( 'default' === $a_priority ) { |
1040 $wp_meta_boxes[ $page ][ $a_context ]['core'][ $id ] = $wp_meta_boxes[ $page ][ $a_context ]['default'][ $id ]; |
1078 $wp_meta_boxes[ $page ][ $a_context ]['core'][ $id ] = $wp_meta_boxes[ $page ][ $a_context ]['default'][ $id ]; |
1041 unset( $wp_meta_boxes[ $page ][ $a_context ]['default'][ $id ] ); |
1079 unset( $wp_meta_boxes[ $page ][ $a_context ]['default'][ $id ] ); |
1042 } |
1080 } |
1043 return; |
1081 return; |
1044 } |
1082 } |
1045 // If no priority given and id already present, use existing priority. |
1083 |
1084 // If no priority given and ID already present, use existing priority. |
|
1046 if ( empty( $priority ) ) { |
1085 if ( empty( $priority ) ) { |
1047 $priority = $a_priority; |
1086 $priority = $a_priority; |
1048 /* |
1087 /* |
1049 * Else, if we're adding to the sorted priority, we don't know the title |
1088 * Else, if we're adding to the sorted priority, we don't know the title |
1050 * or callback. Grab them from the previously added context/priority. |
1089 * or callback. Grab them from the previously added context/priority. |
1051 */ |
1090 */ |
1052 } elseif ( 'sorted' == $priority ) { |
1091 } elseif ( 'sorted' === $priority ) { |
1053 $title = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['title']; |
1092 $title = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['title']; |
1054 $callback = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['callback']; |
1093 $callback = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['callback']; |
1055 $callback_args = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['args']; |
1094 $callback_args = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['args']; |
1056 } |
1095 } |
1057 // An id can be in only one priority and one context. |
1096 |
1058 if ( $priority != $a_priority || $context != $a_context ) { |
1097 // An ID can be in only one priority and one context. |
1098 if ( $priority !== $a_priority || $context !== $a_context ) { |
|
1059 unset( $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] ); |
1099 unset( $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] ); |
1060 } |
1100 } |
1061 } |
1101 } |
1062 } |
1102 } |
1063 |
1103 |
1097 function do_block_editor_incompatible_meta_box( $object, $box ) { |
1137 function do_block_editor_incompatible_meta_box( $object, $box ) { |
1098 $plugin = _get_plugin_from_callback( $box['old_callback'] ); |
1138 $plugin = _get_plugin_from_callback( $box['old_callback'] ); |
1099 $plugins = get_plugins(); |
1139 $plugins = get_plugins(); |
1100 echo '<p>'; |
1140 echo '<p>'; |
1101 if ( $plugin ) { |
1141 if ( $plugin ) { |
1102 /* translators: %s: the name of the plugin that generated this meta box. */ |
1142 /* translators: %s: The name of the plugin that generated this meta box. */ |
1103 printf( __( "This meta box, from the %s plugin, isn't compatible with the block editor." ), "<strong>{$plugin['Name']}</strong>" ); |
1143 printf( __( "This meta box, from the %s plugin, isn't compatible with the block editor." ), "<strong>{$plugin['Name']}</strong>" ); |
1104 } else { |
1144 } else { |
1105 _e( "This meta box isn't compatible with the block editor." ); |
1145 _e( "This meta box isn't compatible with the block editor." ); |
1106 } |
1146 } |
1107 echo '</p>'; |
1147 echo '</p>'; |
1108 |
1148 |
1109 if ( empty( $plugins['classic-editor/classic-editor.php'] ) ) { |
1149 if ( empty( $plugins['classic-editor/classic-editor.php'] ) ) { |
1110 if ( current_user_can( 'install_plugins' ) ) { |
1150 if ( current_user_can( 'install_plugins' ) ) { |
1111 echo '<p>'; |
1151 echo '<p>'; |
1112 /* translators: %s: A link to install the Classic Editor plugin. */ |
1152 printf( |
1113 printf( __( 'Please install the <a href="%s">Classic Editor plugin</a> to use this meta box.' ), esc_url( self_admin_url( 'plugin-install.php?tab=featured' ) ) ); |
1153 /* translators: %s: A link to install the Classic Editor plugin. */ |
1154 __( 'Please install the <a href="%s">Classic Editor plugin</a> to use this meta box.' ), |
|
1155 esc_url( wp_nonce_url( self_admin_url( 'plugin-install.php?tab=favorites&user=wordpressdotorg&save=0' ), 'save_wporg_username_' . get_current_user_id() ) ) |
|
1156 ); |
|
1114 echo '</p>'; |
1157 echo '</p>'; |
1115 } |
1158 } |
1116 } elseif ( is_plugin_inactive( 'classic-editor/classic-editor.php' ) ) { |
1159 } elseif ( is_plugin_inactive( 'classic-editor/classic-editor.php' ) ) { |
1117 if ( current_user_can( 'activate_plugins' ) ) { |
1160 if ( current_user_can( 'activate_plugins' ) ) { |
1118 $activate_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=classic-editor/classic-editor.php' ), 'activate-plugin_classic-editor/classic-editor.php' ); |
1161 $activate_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=classic-editor/classic-editor.php' ), 'activate-plugin_classic-editor/classic-editor.php' ); |
1164 if ( ! $reflection->isInternal() ) { |
1207 if ( ! $reflection->isInternal() ) { |
1165 |
1208 |
1166 // Only show errors if the meta box was registered by a plugin. |
1209 // Only show errors if the meta box was registered by a plugin. |
1167 $filename = wp_normalize_path( $reflection->getFileName() ); |
1210 $filename = wp_normalize_path( $reflection->getFileName() ); |
1168 $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR ); |
1211 $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR ); |
1212 |
|
1169 if ( strpos( $filename, $plugin_dir ) === 0 ) { |
1213 if ( strpos( $filename, $plugin_dir ) === 0 ) { |
1170 $filename = str_replace( $plugin_dir, '', $filename ); |
1214 $filename = str_replace( $plugin_dir, '', $filename ); |
1171 $filename = preg_replace( '|^/([^/]*/).*$|', '\\1', $filename ); |
1215 $filename = preg_replace( '|^/([^/]*/).*$|', '\\1', $filename ); |
1172 |
1216 |
1173 $plugins = get_plugins(); |
1217 $plugins = get_plugins(); |
1218 |
|
1174 foreach ( $plugins as $name => $plugin ) { |
1219 foreach ( $plugins as $name => $plugin ) { |
1175 if ( strpos( $name, $filename ) === 0 ) { |
1220 if ( strpos( $name, $filename ) === 0 ) { |
1176 return $plugin; |
1221 return $plugin; |
1177 } |
1222 } |
1178 } |
1223 } |
1187 * |
1232 * |
1188 * @since 2.5.0 |
1233 * @since 2.5.0 |
1189 * |
1234 * |
1190 * @global array $wp_meta_boxes |
1235 * @global array $wp_meta_boxes |
1191 * |
1236 * |
1192 * @staticvar bool $already_sorted |
1237 * @param string|WP_Screen $screen The screen identifier. If you have used add_menu_page() or |
1193 * |
|
1194 * @param string|WP_Screen $screen Screen identifier. If you have used add_menu_page() or |
|
1195 * add_submenu_page() to create a new screen (and hence screen_id) |
1238 * add_submenu_page() to create a new screen (and hence screen_id) |
1196 * make sure your menu slug conforms to the limits of sanitize_key() |
1239 * make sure your menu slug conforms to the limits of sanitize_key() |
1197 * otherwise the 'screen' menu may not correctly render on your page. |
1240 * otherwise the 'screen' menu may not correctly render on your page. |
1198 * @param string $context The screen context for which to display meta boxes. |
1241 * @param string $context The screen context for which to display meta boxes. |
1199 * @param mixed $object Gets passed to the first parameter of the meta box callback function. |
1242 * @param mixed $object Gets passed to the meta box callback function as the first parameter. |
1200 * Often this is the object that's the focus of the current screen, for |
1243 * Often this is the object that's the focus of the current screen, for |
1201 * example a `WP_Post` or `WP_Comment` object. |
1244 * example a `WP_Post` or `WP_Comment` object. |
1202 * @return int number of meta_boxes |
1245 * @return int Number of meta_boxes. |
1203 */ |
1246 */ |
1204 function do_meta_boxes( $screen, $context, $object ) { |
1247 function do_meta_boxes( $screen, $context, $object ) { |
1205 global $wp_meta_boxes; |
1248 global $wp_meta_boxes; |
1206 static $already_sorted = false; |
1249 static $already_sorted = false; |
1207 |
1250 |
1215 |
1258 |
1216 $hidden = get_hidden_meta_boxes( $screen ); |
1259 $hidden = get_hidden_meta_boxes( $screen ); |
1217 |
1260 |
1218 printf( '<div id="%s-sortables" class="meta-box-sortables">', esc_attr( $context ) ); |
1261 printf( '<div id="%s-sortables" class="meta-box-sortables">', esc_attr( $context ) ); |
1219 |
1262 |
1220 // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose |
1263 // Grab the ones the user has manually sorted. |
1221 if ( ! $already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) { |
1264 // Pull them out of their previous context/priority and into the one the user chose. |
1265 $sorted = get_user_option( "meta-box-order_$page" ); |
|
1266 |
|
1267 if ( ! $already_sorted && $sorted ) { |
|
1222 foreach ( $sorted as $box_context => $ids ) { |
1268 foreach ( $sorted as $box_context => $ids ) { |
1223 foreach ( explode( ',', $ids ) as $id ) { |
1269 foreach ( explode( ',', $ids ) as $id ) { |
1224 if ( $id && 'dashboard_browser_nag' !== $id ) { |
1270 if ( $id && 'dashboard_browser_nag' !== $id ) { |
1225 add_meta_box( $id, null, null, $screen, $box_context, 'sorted' ); |
1271 add_meta_box( $id, null, null, $screen, $box_context, 'sorted' ); |
1226 } |
1272 } |
1234 |
1280 |
1235 if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) { |
1281 if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) { |
1236 foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) { |
1282 foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) { |
1237 if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { |
1283 if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { |
1238 foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { |
1284 foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { |
1239 if ( false == $box || ! $box['title'] ) { |
1285 if ( false === $box || ! $box['title'] ) { |
1240 continue; |
1286 continue; |
1241 } |
1287 } |
1242 |
1288 |
1243 $block_compatible = true; |
1289 $block_compatible = true; |
1244 if ( is_array( $box['args'] ) ) { |
1290 if ( is_array( $box['args'] ) ) { |
1264 } |
1310 } |
1265 } |
1311 } |
1266 |
1312 |
1267 $i++; |
1313 $i++; |
1268 // get_hidden_meta_boxes() doesn't apply in the block editor. |
1314 // get_hidden_meta_boxes() doesn't apply in the block editor. |
1269 $hidden_class = ( ! $screen->is_block_editor() && in_array( $box['id'], $hidden ) ) ? ' hide-if-js' : ''; |
1315 $hidden_class = ( ! $screen->is_block_editor() && in_array( $box['id'], $hidden, true ) ) ? ' hide-if-js' : ''; |
1270 echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes( $box['id'], $page ) . $hidden_class . '" ' . '>' . "\n"; |
1316 echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes( $box['id'], $page ) . $hidden_class . '" ' . '>' . "\n"; |
1271 if ( 'dashboard_browser_nag' != $box['id'] ) { |
1317 |
1318 echo '<div class="postbox-header">'; |
|
1319 echo '<h2 class="hndle">'; |
|
1320 if ( 'dashboard_php_nag' === $box['id'] ) { |
|
1321 echo '<span aria-hidden="true" class="dashicons dashicons-warning"></span>'; |
|
1322 echo '<span class="screen-reader-text">' . __( 'Warning:' ) . ' </span>'; |
|
1323 } |
|
1324 echo "{$box['title']}"; |
|
1325 echo "</h2>\n"; |
|
1326 |
|
1327 if ( 'dashboard_browser_nag' !== $box['id'] ) { |
|
1272 $widget_title = $box['title']; |
1328 $widget_title = $box['title']; |
1273 |
1329 |
1274 if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) { |
1330 if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) { |
1275 $widget_title = $box['args']['__widget_basename']; |
1331 $widget_title = $box['args']['__widget_basename']; |
1276 // Do not pass this parameter to the user callback function. |
1332 // Do not pass this parameter to the user callback function. |
1277 unset( $box['args']['__widget_basename'] ); |
1333 unset( $box['args']['__widget_basename'] ); |
1278 } |
1334 } |
1279 |
1335 |
1336 echo '<div class="handle-actions hide-if-no-js">'; |
|
1337 |
|
1338 echo '<button type="button" class="handle-order-higher" aria-disabled="false" aria-describedby="' . $box['id'] . '-handle-order-higher-description">'; |
|
1339 echo '<span class="screen-reader-text">' . __( 'Move up' ) . '</span>'; |
|
1340 echo '<span class="order-higher-indicator" aria-hidden="true"></span>'; |
|
1341 echo '</button>'; |
|
1342 echo '<span class="hidden" id="' . $box['id'] . '-handle-order-higher-description">' . sprintf( |
|
1343 /* translators: %s: Meta box title. */ |
|
1344 __( 'Move %s box up' ), |
|
1345 $widget_title |
|
1346 ) . '</span>'; |
|
1347 |
|
1348 echo '<button type="button" class="handle-order-lower" aria-disabled="false" aria-describedby="' . $box['id'] . '-handle-order-lower-description">'; |
|
1349 echo '<span class="screen-reader-text">' . __( 'Move down' ) . '</span>'; |
|
1350 echo '<span class="order-lower-indicator" aria-hidden="true"></span>'; |
|
1351 echo '</button>'; |
|
1352 echo '<span class="hidden" id="' . $box['id'] . '-handle-order-lower-description">' . sprintf( |
|
1353 /* translators: %s: Meta box title. */ |
|
1354 __( 'Move %s box down' ), |
|
1355 $widget_title |
|
1356 ) . '</span>'; |
|
1357 |
|
1280 echo '<button type="button" class="handlediv" aria-expanded="true">'; |
1358 echo '<button type="button" class="handlediv" aria-expanded="true">'; |
1281 echo '<span class="screen-reader-text">' . sprintf( __( 'Toggle panel: %s' ), $widget_title ) . '</span>'; |
1359 echo '<span class="screen-reader-text">' . sprintf( |
1360 /* translators: %s: Meta box title. */ |
|
1361 __( 'Toggle panel: %s' ), |
|
1362 $widget_title |
|
1363 ) . '</span>'; |
|
1282 echo '<span class="toggle-indicator" aria-hidden="true"></span>'; |
1364 echo '<span class="toggle-indicator" aria-hidden="true"></span>'; |
1283 echo '</button>'; |
1365 echo '</button>'; |
1366 |
|
1367 echo '</div>'; |
|
1284 } |
1368 } |
1285 echo '<h2 class="hndle">'; |
1369 echo '</div>'; |
1286 if ( 'dashboard_php_nag' === $box['id'] ) { |
1370 |
1287 echo '<span aria-hidden="true" class="dashicons dashicons-warning"></span>'; |
|
1288 echo '<span class="screen-reader-text">' . __( 'Warning:' ) . ' </span>'; |
|
1289 } |
|
1290 echo "<span>{$box['title']}</span>"; |
|
1291 echo "</h2>\n"; |
|
1292 echo '<div class="inside">' . "\n"; |
1371 echo '<div class="inside">' . "\n"; |
1293 |
1372 |
1294 if ( WP_DEBUG && ! $block_compatible && 'edit' === $screen->parent_base && ! $screen->is_block_editor() && ! isset( $_GET['meta-box-loader'] ) ) { |
1373 if ( WP_DEBUG && ! $block_compatible && 'edit' === $screen->parent_base && ! $screen->is_block_editor() && ! isset( $_GET['meta-box-loader'] ) ) { |
1295 $plugin = _get_plugin_from_callback( $box['callback'] ); |
1374 $plugin = _get_plugin_from_callback( $box['callback'] ); |
1296 if ( $plugin ) { |
1375 if ( $plugin ) { |
1297 ?> |
1376 ?> |
1298 <div class="error inline"> |
1377 <div class="error inline"> |
1299 <p> |
1378 <p> |
1300 <?php |
1379 <?php |
1301 /* translators: %s: the name of the plugin that generated this meta box. */ |
1380 /* translators: %s: The name of the plugin that generated this meta box. */ |
1302 printf( __( "This meta box, from the %s plugin, isn't compatible with the block editor." ), "<strong>{$plugin['Name']}</strong>" ); |
1381 printf( __( "This meta box, from the %s plugin, isn't compatible with the block editor." ), "<strong>{$plugin['Name']}</strong>" ); |
1303 ?> |
1382 ?> |
1304 </p> |
1383 </p> |
1305 </div> |
1384 </div> |
1306 <?php |
1385 <?php |
1383 * @since 3.6.0 |
1462 * @since 3.6.0 |
1384 * |
1463 * |
1385 * @uses global $wp_meta_boxes Used to retrieve registered meta boxes. |
1464 * @uses global $wp_meta_boxes Used to retrieve registered meta boxes. |
1386 * |
1465 * |
1387 * @param string|object $screen The screen identifier. |
1466 * @param string|object $screen The screen identifier. |
1388 * @param string $context The meta box context. |
1467 * @param string $context The screen context for which to display accordion sections. |
1389 * @param mixed $object gets passed to the section callback function as first parameter. |
1468 * @param mixed $object Gets passed to the section callback function as the first parameter. |
1390 * @return int number of meta boxes as accordion sections. |
1469 * @return int Number of meta boxes as accordion sections. |
1391 */ |
1470 */ |
1392 function do_accordion_sections( $screen, $context, $object ) { |
1471 function do_accordion_sections( $screen, $context, $object ) { |
1393 global $wp_meta_boxes; |
1472 global $wp_meta_boxes; |
1394 |
1473 |
1395 wp_enqueue_script( 'accordion' ); |
1474 wp_enqueue_script( 'accordion' ); |
1412 |
1491 |
1413 if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) { |
1492 if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) { |
1414 foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { |
1493 foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { |
1415 if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { |
1494 if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { |
1416 foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { |
1495 foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { |
1417 if ( false == $box || ! $box['title'] ) { |
1496 if ( false === $box || ! $box['title'] ) { |
1418 continue; |
1497 continue; |
1419 } |
1498 } |
1499 |
|
1420 $i++; |
1500 $i++; |
1421 $hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : ''; |
1501 $hidden_class = in_array( $box['id'], $hidden, true ) ? 'hide-if-js' : ''; |
1422 |
1502 |
1423 $open_class = ''; |
1503 $open_class = ''; |
1424 if ( ! $first_open && empty( $hidden_class ) ) { |
1504 if ( ! $first_open && empty( $hidden_class ) ) { |
1425 $first_open = true; |
1505 $first_open = true; |
1426 $open_class = 'open'; |
1506 $open_class = 'open'; |
1460 * content you want to show at the top of the settings section before the actual |
1540 * content you want to show at the top of the settings section before the actual |
1461 * fields. It can output nothing if you want. |
1541 * fields. It can output nothing if you want. |
1462 * |
1542 * |
1463 * @since 2.7.0 |
1543 * @since 2.7.0 |
1464 * |
1544 * |
1465 * @global $wp_settings_sections Storage array of all settings sections added to admin pages. |
1545 * @global array $wp_settings_sections Storage array of all settings sections added to admin pages. |
1466 * |
1546 * |
1467 * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags. |
1547 * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags. |
1468 * @param string $title Formatted title of the section. Shown as the heading for the section. |
1548 * @param string $title Formatted title of the section. Shown as the heading for the section. |
1469 * @param callable $callback Function that echos out any content at the top of the section (between heading and fields). |
1549 * @param callable $callback Function that echos out any content at the top of the section (between heading and fields). |
1470 * @param string $page The slug-name of the settings page on which to show the section. Built-in pages include |
1550 * @param string $page The slug-name of the settings page on which to show the section. Built-in pages include |
1472 * add_options_page(); |
1552 * add_options_page(); |
1473 */ |
1553 */ |
1474 function add_settings_section( $id, $title, $callback, $page ) { |
1554 function add_settings_section( $id, $title, $callback, $page ) { |
1475 global $wp_settings_sections; |
1555 global $wp_settings_sections; |
1476 |
1556 |
1477 if ( 'misc' == $page ) { |
1557 if ( 'misc' === $page ) { |
1478 _deprecated_argument( |
1558 _deprecated_argument( |
1479 __FUNCTION__, |
1559 __FUNCTION__, |
1480 '3.0.0', |
1560 '3.0.0', |
1481 /* translators: %s: misc */ |
|
1482 sprintf( |
1561 sprintf( |
1562 /* translators: %s: misc */ |
|
1483 __( 'The "%s" options group has been removed. Use another settings group.' ), |
1563 __( 'The "%s" options group has been removed. Use another settings group.' ), |
1484 'misc' |
1564 'misc' |
1485 ) |
1565 ) |
1486 ); |
1566 ); |
1487 $page = 'general'; |
1567 $page = 'general'; |
1488 } |
1568 } |
1489 |
1569 |
1490 if ( 'privacy' == $page ) { |
1570 if ( 'privacy' === $page ) { |
1491 _deprecated_argument( |
1571 _deprecated_argument( |
1492 __FUNCTION__, |
1572 __FUNCTION__, |
1493 '3.5.0', |
1573 '3.5.0', |
1494 /* translators: %s: privacy */ |
|
1495 sprintf( |
1574 sprintf( |
1575 /* translators: %s: privacy */ |
|
1496 __( 'The "%s" options group has been removed. Use another settings group.' ), |
1576 __( 'The "%s" options group has been removed. Use another settings group.' ), |
1497 'privacy' |
1577 'privacy' |
1498 ) |
1578 ) |
1499 ); |
1579 ); |
1500 $page = 'reading'; |
1580 $page = 'reading'; |
1513 * Part of the Settings API. Use this to define a settings field that will show |
1593 * Part of the Settings API. Use this to define a settings field that will show |
1514 * as part of a settings section inside a settings page. The fields are shown using |
1594 * as part of a settings section inside a settings page. The fields are shown using |
1515 * do_settings_fields() in do_settings-sections() |
1595 * do_settings_fields() in do_settings-sections() |
1516 * |
1596 * |
1517 * The $callback argument should be the name of a function that echoes out the |
1597 * The $callback argument should be the name of a function that echoes out the |
1518 * html input tags for this setting field. Use get_option() to retrieve existing |
1598 * HTML input tags for this setting field. Use get_option() to retrieve existing |
1519 * values to show. |
1599 * values to show. |
1520 * |
1600 * |
1521 * @since 2.7.0 |
1601 * @since 2.7.0 |
1522 * @since 4.2.0 The `$class` argument was added. |
1602 * @since 4.2.0 The `$class` argument was added. |
1523 * |
1603 * |
1524 * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections. |
1604 * @global array $wp_settings_fields Storage array of settings fields and info about their pages/sections. |
1525 * |
1605 * |
1526 * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags. |
1606 * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags. |
1527 * @param string $title Formatted title of the field. Shown as the label for the field |
1607 * @param string $title Formatted title of the field. Shown as the label for the field |
1528 * during output. |
1608 * during output. |
1529 * @param callable $callback Function that fills the field with the desired form inputs. The |
1609 * @param callable $callback Function that fills the field with the desired form inputs. The |
1543 * } |
1623 * } |
1544 */ |
1624 */ |
1545 function add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array() ) { |
1625 function add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array() ) { |
1546 global $wp_settings_fields; |
1626 global $wp_settings_fields; |
1547 |
1627 |
1548 if ( 'misc' == $page ) { |
1628 if ( 'misc' === $page ) { |
1549 _deprecated_argument( |
1629 _deprecated_argument( |
1550 __FUNCTION__, |
1630 __FUNCTION__, |
1551 '3.0.0', |
1631 '3.0.0', |
1552 /* translators: %s: misc */ |
|
1553 sprintf( |
1632 sprintf( |
1633 /* translators: %s: misc */ |
|
1554 __( 'The "%s" options group has been removed. Use another settings group.' ), |
1634 __( 'The "%s" options group has been removed. Use another settings group.' ), |
1555 'misc' |
1635 'misc' |
1556 ) |
1636 ) |
1557 ); |
1637 ); |
1558 $page = 'general'; |
1638 $page = 'general'; |
1559 } |
1639 } |
1560 |
1640 |
1561 if ( 'privacy' == $page ) { |
1641 if ( 'privacy' === $page ) { |
1562 _deprecated_argument( |
1642 _deprecated_argument( |
1563 __FUNCTION__, |
1643 __FUNCTION__, |
1564 '3.5.0', |
1644 '3.5.0', |
1565 /* translators: %s: privacy */ |
|
1566 sprintf( |
1645 sprintf( |
1646 /* translators: %s: privacy */ |
|
1567 __( 'The "%s" options group has been removed. Use another settings group.' ), |
1647 __( 'The "%s" options group has been removed. Use another settings group.' ), |
1568 'privacy' |
1648 'privacy' |
1569 ) |
1649 ) |
1570 ); |
1650 ); |
1571 $page = 'reading'; |
1651 $page = 'reading'; |
1584 * |
1664 * |
1585 * Part of the Settings API. Use this in a settings page callback function |
1665 * Part of the Settings API. Use this in a settings page callback function |
1586 * to output all the sections and fields that were added to that $page with |
1666 * to output all the sections and fields that were added to that $page with |
1587 * add_settings_section() and add_settings_field() |
1667 * add_settings_section() and add_settings_field() |
1588 * |
1668 * |
1589 * @global $wp_settings_sections Storage array of all settings sections added to admin pages. |
1669 * @global array $wp_settings_sections Storage array of all settings sections added to admin pages. |
1590 * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections. |
1670 * @global array $wp_settings_fields Storage array of settings fields and info about their pages/sections. |
1591 * @since 2.7.0 |
1671 * @since 2.7.0 |
1592 * |
1672 * |
1593 * @param string $page The slug name of the page whose settings sections you want to output. |
1673 * @param string $page The slug name of the page whose settings sections you want to output. |
1594 */ |
1674 */ |
1595 function do_settings_sections( $page ) { |
1675 function do_settings_sections( $page ) { |
1622 * |
1702 * |
1623 * Part of the Settings API. Use this in a settings page to output |
1703 * Part of the Settings API. Use this in a settings page to output |
1624 * a specific section. Should normally be called by do_settings_sections() |
1704 * a specific section. Should normally be called by do_settings_sections() |
1625 * rather than directly. |
1705 * rather than directly. |
1626 * |
1706 * |
1627 * @global $wp_settings_fields Storage array of settings fields and their pages/sections. |
1707 * @global array $wp_settings_fields Storage array of settings fields and their pages/sections. |
1628 * |
1708 * |
1629 * @since 2.7.0 |
1709 * @since 2.7.0 |
1630 * |
1710 * |
1631 * @param string $page Slug title of the admin page whose settings fields you want to show. |
1711 * @param string $page Slug title of the admin page whose settings fields you want to show. |
1632 * @param string $section Slug title of the settings section whose fields you want to show. |
1712 * @param string $section Slug title of the settings section whose fields you want to show. |
1672 * By default messages will show immediately after the submission that generated the error. |
1752 * By default messages will show immediately after the submission that generated the error. |
1673 * Additional calls to settings_errors() can be used to show errors even when the settings |
1753 * Additional calls to settings_errors() can be used to show errors even when the settings |
1674 * page is first accessed. |
1754 * page is first accessed. |
1675 * |
1755 * |
1676 * @since 3.0.0 |
1756 * @since 3.0.0 |
1757 * @since 5.3.0 Added `warning` and `info` as possible values for `$type`. |
|
1677 * |
1758 * |
1678 * @global array $wp_settings_errors Storage array of errors registered during this pageload |
1759 * @global array $wp_settings_errors Storage array of errors registered during this pageload |
1679 * |
1760 * |
1680 * @param string $setting Slug title of the setting to which this error applies. |
1761 * @param string $setting Slug title of the setting to which this error applies. |
1681 * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output. |
1762 * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output. |
1682 * @param string $message The formatted message text to display to the user (will be shown inside styled |
1763 * @param string $message The formatted message text to display to the user (will be shown inside styled |
1683 * `<div>` and `<p>` tags). |
1764 * `<div>` and `<p>` tags). |
1684 * @param string $type Optional. Message type, controls HTML class. Accepts 'error' or 'updated'. |
1765 * @param string $type Optional. Message type, controls HTML class. Possible values include 'error', |
1685 * Default 'error'. |
1766 * 'success', 'warning', 'info'. Default 'error'. |
1686 */ |
1767 */ |
1687 function add_settings_error( $setting, $code, $message, $type = 'error' ) { |
1768 function add_settings_error( $setting, $code, $message, $type = 'error' ) { |
1688 global $wp_settings_errors; |
1769 global $wp_settings_errors; |
1689 |
1770 |
1690 $wp_settings_errors[] = array( |
1771 $wp_settings_errors[] = array( |
1712 * |
1793 * |
1713 * @since 3.0.0 |
1794 * @since 3.0.0 |
1714 * |
1795 * |
1715 * @global array $wp_settings_errors Storage array of errors registered during this pageload |
1796 * @global array $wp_settings_errors Storage array of errors registered during this pageload |
1716 * |
1797 * |
1717 * @param string $setting Optional slug title of a specific setting whose errors you want. |
1798 * @param string $setting Optional. Slug title of a specific setting whose errors you want. |
1718 * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors. |
1799 * @param bool $sanitize Optional. Whether to re-sanitize the setting value before returning errors. |
1719 * @return array Array of settings errors. |
1800 * @return array Array of settings errors. |
1720 */ |
1801 */ |
1721 function get_settings_errors( $setting = '', $sanitize = false ) { |
1802 function get_settings_errors( $setting = '', $sanitize = false ) { |
1722 global $wp_settings_errors; |
1803 global $wp_settings_errors; |
1723 |
1804 |
1742 } |
1823 } |
1743 |
1824 |
1744 // Filter the results to those of a specific setting if one was set. |
1825 // Filter the results to those of a specific setting if one was set. |
1745 if ( $setting ) { |
1826 if ( $setting ) { |
1746 $setting_errors = array(); |
1827 $setting_errors = array(); |
1828 |
|
1747 foreach ( (array) $wp_settings_errors as $key => $details ) { |
1829 foreach ( (array) $wp_settings_errors as $key => $details ) { |
1748 if ( $setting == $details['setting'] ) { |
1830 if ( $setting === $details['setting'] ) { |
1749 $setting_errors[] = $wp_settings_errors[ $key ]; |
1831 $setting_errors[] = $wp_settings_errors[ $key ]; |
1750 } |
1832 } |
1751 } |
1833 } |
1834 |
|
1752 return $setting_errors; |
1835 return $setting_errors; |
1753 } |
1836 } |
1754 |
1837 |
1755 return $wp_settings_errors; |
1838 return $wp_settings_errors; |
1756 } |
1839 } |
1774 * hidden to avoid repeating messages already shown in the default error |
1857 * hidden to avoid repeating messages already shown in the default error |
1775 * reporting after submission. This is useful to show general errors like |
1858 * reporting after submission. This is useful to show general errors like |
1776 * missing settings when the user arrives at the settings page. |
1859 * missing settings when the user arrives at the settings page. |
1777 * |
1860 * |
1778 * @since 3.0.0 |
1861 * @since 3.0.0 |
1862 * @since 5.3.0 Legacy `error` and `updated` CSS classes are mapped to |
|
1863 * `notice-error` and `notice-success`. |
|
1779 * |
1864 * |
1780 * @param string $setting Optional slug title of a specific setting whose errors you want. |
1865 * @param string $setting Optional slug title of a specific setting whose errors you want. |
1781 * @param bool $sanitize Whether to re-sanitize the setting value before returning errors. |
1866 * @param bool $sanitize Whether to re-sanitize the setting value before returning errors. |
1782 * @param bool $hide_on_update If set to true errors will not be shown if the settings page has |
1867 * @param bool $hide_on_update If set to true errors will not be shown if the settings page has |
1783 * already been submitted. |
1868 * already been submitted. |
1793 if ( empty( $settings_errors ) ) { |
1878 if ( empty( $settings_errors ) ) { |
1794 return; |
1879 return; |
1795 } |
1880 } |
1796 |
1881 |
1797 $output = ''; |
1882 $output = ''; |
1883 |
|
1798 foreach ( $settings_errors as $key => $details ) { |
1884 foreach ( $settings_errors as $key => $details ) { |
1799 $css_id = 'setting-error-' . $details['code']; |
1885 if ( 'updated' === $details['type'] ) { |
1800 $css_class = $details['type'] . ' settings-error notice is-dismissible'; |
1886 $details['type'] = 'success'; |
1801 $output .= "<div id='$css_id' class='$css_class'> \n"; |
1887 } |
1802 $output .= "<p><strong>{$details['message']}</strong></p>"; |
1888 |
1803 $output .= "</div> \n"; |
1889 if ( in_array( $details['type'], array( 'error', 'success', 'warning', 'info' ), true ) ) { |
1804 } |
1890 $details['type'] = 'notice-' . $details['type']; |
1891 } |
|
1892 |
|
1893 $css_id = sprintf( |
|
1894 'setting-error-%s', |
|
1895 esc_attr( $details['code'] ) |
|
1896 ); |
|
1897 $css_class = sprintf( |
|
1898 'notice %s settings-error is-dismissible', |
|
1899 esc_attr( $details['type'] ) |
|
1900 ); |
|
1901 |
|
1902 $output .= "<div id='$css_id' class='$css_class'> \n"; |
|
1903 $output .= "<p><strong>{$details['message']}</strong></p>"; |
|
1904 $output .= "</div> \n"; |
|
1905 } |
|
1906 |
|
1805 echo $output; |
1907 echo $output; |
1806 } |
1908 } |
1807 |
1909 |
1808 /** |
1910 /** |
1809 * Outputs the modal window used for attaching media to posts or pages in the media-listing screen. |
1911 * Outputs the modal window used for attaching media to posts or pages in the media-listing screen. |
1843 } |
1945 } |
1844 |
1946 |
1845 /** |
1947 /** |
1846 * Displays the post password. |
1948 * Displays the post password. |
1847 * |
1949 * |
1848 * The password is passed through esc_attr() to ensure that it is safe for placing in an html attribute. |
1950 * The password is passed through esc_attr() to ensure that it is safe for placing in an HTML attribute. |
1849 * |
1951 * |
1850 * @since 2.7.0 |
1952 * @since 2.7.0 |
1851 */ |
1953 */ |
1852 function the_post_password() { |
1954 function the_post_password() { |
1853 $post = get_post(); |
1955 $post = get_post(); |
1892 * |
1994 * |
1893 * @since 2.7.0 |
1995 * @since 2.7.0 |
1894 * |
1996 * |
1895 * @global string $hook_suffix |
1997 * @global string $hook_suffix |
1896 * @global string $admin_body_class |
1998 * @global string $admin_body_class |
1897 * @global WP_Locale $wp_locale |
1999 * @global WP_Locale $wp_locale WordPress date and time locale object. |
1898 * |
2000 * |
1899 * @param string $title Optional. Title of the Iframe page. Default empty. |
2001 * @param string $title Optional. Title of the Iframe page. Default empty. |
1900 * @param bool $deprecated Not used. |
2002 * @param bool $deprecated Not used. |
1901 */ |
2003 */ |
1902 function iframe_header( $title = '', $deprecated = false ) { |
2004 function iframe_header( $title = '', $deprecated = false ) { |
1904 global $hook_suffix, $admin_body_class, $wp_locale; |
2006 global $hook_suffix, $admin_body_class, $wp_locale; |
1905 $admin_body_class = preg_replace( '/[^a-z0-9_-]+/i', '-', $hook_suffix ); |
2007 $admin_body_class = preg_replace( '/[^a-z0-9_-]+/i', '-', $hook_suffix ); |
1906 |
2008 |
1907 $current_screen = get_current_screen(); |
2009 $current_screen = get_current_screen(); |
1908 |
2010 |
1909 @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) ); |
2011 header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) ); |
1910 _wp_admin_html_begin(); |
2012 _wp_admin_html_begin(); |
1911 ?> |
2013 ?> |
1912 <title><?php bloginfo( 'name' ); ?> › <?php echo $title; ?> — <?php _e( 'WordPress' ); ?></title> |
2014 <title><?php bloginfo( 'name' ); ?> › <?php echo $title; ?> — <?php _e( 'WordPress' ); ?></title> |
1913 <?php |
2015 <?php |
1914 wp_enqueue_style( 'colors' ); |
2016 wp_enqueue_style( 'colors' ); |
1927 <?php |
2029 <?php |
1928 /** This action is documented in wp-admin/admin-header.php */ |
2030 /** This action is documented in wp-admin/admin-header.php */ |
1929 do_action( 'admin_enqueue_scripts', $hook_suffix ); |
2031 do_action( 'admin_enqueue_scripts', $hook_suffix ); |
1930 |
2032 |
1931 /** This action is documented in wp-admin/admin-header.php */ |
2033 /** This action is documented in wp-admin/admin-header.php */ |
1932 do_action( "admin_print_styles-$hook_suffix" ); |
2034 do_action( "admin_print_styles-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
1933 |
2035 |
1934 /** This action is documented in wp-admin/admin-header.php */ |
2036 /** This action is documented in wp-admin/admin-header.php */ |
1935 do_action( 'admin_print_styles' ); |
2037 do_action( 'admin_print_styles' ); |
1936 |
2038 |
1937 /** This action is documented in wp-admin/admin-header.php */ |
2039 /** This action is documented in wp-admin/admin-header.php */ |
1938 do_action( "admin_print_scripts-$hook_suffix" ); |
2040 do_action( "admin_print_scripts-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
1939 |
2041 |
1940 /** This action is documented in wp-admin/admin-header.php */ |
2042 /** This action is documented in wp-admin/admin-header.php */ |
1941 do_action( 'admin_print_scripts' ); |
2043 do_action( 'admin_print_scripts' ); |
1942 |
2044 |
1943 /** This action is documented in wp-admin/admin-header.php */ |
2045 /** This action is documented in wp-admin/admin-header.php */ |
1944 do_action( "admin_head-$hook_suffix" ); |
2046 do_action( "admin_head-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
1945 |
2047 |
1946 /** This action is documented in wp-admin/admin-header.php */ |
2048 /** This action is documented in wp-admin/admin-header.php */ |
1947 do_action( 'admin_head' ); |
2049 do_action( 'admin_head' ); |
1948 |
2050 |
1949 $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) ); |
2051 $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) ); |
1953 } |
2055 } |
1954 |
2056 |
1955 ?> |
2057 ?> |
1956 </head> |
2058 </head> |
1957 <?php |
2059 <?php |
2060 /** |
|
2061 * @global string $body_id |
|
2062 */ |
|
2063 $admin_body_id = isset( $GLOBALS['body_id'] ) ? 'id="' . $GLOBALS['body_id'] . '" ' : ''; |
|
2064 |
|
1958 /** This filter is documented in wp-admin/admin-header.php */ |
2065 /** This filter is documented in wp-admin/admin-header.php */ |
1959 $admin_body_classes = apply_filters( 'admin_body_class', '' ); |
2066 $admin_body_classes = apply_filters( 'admin_body_class', '' ); |
1960 $admin_body_classes = ltrim( $admin_body_classes . ' ' . $admin_body_class ); |
2067 $admin_body_classes = ltrim( $admin_body_classes . ' ' . $admin_body_class ); |
1961 ?> |
2068 ?> |
1962 <body |
2069 <body <?php echo $admin_body_id; ?>class="wp-admin wp-core-ui no-js iframe <?php echo $admin_body_classes; ?>"> |
1963 <?php |
|
1964 /** |
|
1965 * @global string $body_id |
|
1966 */ |
|
1967 if ( isset( $GLOBALS['body_id'] ) ) { |
|
1968 echo ' id="' . $GLOBALS['body_id'] . '"'; |
|
1969 } |
|
1970 ?> |
|
1971 class="wp-admin wp-core-ui no-js iframe <?php echo $admin_body_classes; ?>"> |
|
1972 <script type="text/javascript"> |
2070 <script type="text/javascript"> |
1973 (function(){ |
2071 (function(){ |
1974 var c = document.body.className; |
2072 var c = document.body.className; |
1975 c = c.replace(/no-js/, 'js'); |
2073 c = c.replace(/no-js/, 'js'); |
1976 document.body.className = c; |
2074 document.body.className = c; |
2000 <?php |
2098 <?php |
2001 /** This action is documented in wp-admin/admin-footer.php */ |
2099 /** This action is documented in wp-admin/admin-footer.php */ |
2002 do_action( 'admin_footer', $hook_suffix ); |
2100 do_action( 'admin_footer', $hook_suffix ); |
2003 |
2101 |
2004 /** This action is documented in wp-admin/admin-footer.php */ |
2102 /** This action is documented in wp-admin/admin-footer.php */ |
2005 do_action( "admin_print_footer_scripts-$hook_suffix" ); |
2103 do_action( "admin_print_footer_scripts-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
2006 |
2104 |
2007 /** This action is documented in wp-admin/admin-footer.php */ |
2105 /** This action is documented in wp-admin/admin-footer.php */ |
2008 do_action( 'admin_print_footer_scripts' ); |
2106 do_action( 'admin_print_footer_scripts' ); |
2009 ?> |
2107 ?> |
2010 </div> |
2108 </div> |
2013 </html> |
2111 </html> |
2014 <?php |
2112 <?php |
2015 } |
2113 } |
2016 |
2114 |
2017 /** |
2115 /** |
2018 * @param WP_Post $post |
2116 * Function to echo or return the post states as HTML. |
2019 */ |
2117 * |
2020 function _post_states( $post ) { |
2118 * @since 2.7.0 |
2119 * @since 5.3.0 Added the `$echo` parameter and a return value. |
|
2120 * |
|
2121 * @see get_post_states() |
|
2122 * |
|
2123 * @param WP_Post $post The post to retrieve states for. |
|
2124 * @param bool $echo Optional. Whether to echo the post states as an HTML string. Default true. |
|
2125 * @return string Post states string. |
|
2126 */ |
|
2127 function _post_states( $post, $echo = true ) { |
|
2128 $post_states = get_post_states( $post ); |
|
2129 $post_states_string = ''; |
|
2130 |
|
2131 if ( ! empty( $post_states ) ) { |
|
2132 $state_count = count( $post_states ); |
|
2133 $i = 0; |
|
2134 |
|
2135 $post_states_string .= ' — '; |
|
2136 |
|
2137 foreach ( $post_states as $state ) { |
|
2138 $sep = ( ++$i === $state_count ) ? '' : ', '; |
|
2139 |
|
2140 $post_states_string .= "<span class='post-state'>$state$sep</span>"; |
|
2141 } |
|
2142 } |
|
2143 |
|
2144 if ( $echo ) { |
|
2145 echo $post_states_string; |
|
2146 } |
|
2147 |
|
2148 return $post_states_string; |
|
2149 } |
|
2150 |
|
2151 /** |
|
2152 * Retrieves an array of post states from a post. |
|
2153 * |
|
2154 * @since 5.3.0 |
|
2155 * |
|
2156 * @param WP_Post $post The post to retrieve states for. |
|
2157 * @return string[] Array of post state labels keyed by their state. |
|
2158 */ |
|
2159 function get_post_states( $post ) { |
|
2021 $post_states = array(); |
2160 $post_states = array(); |
2161 |
|
2022 if ( isset( $_REQUEST['post_status'] ) ) { |
2162 if ( isset( $_REQUEST['post_status'] ) ) { |
2023 $post_status = $_REQUEST['post_status']; |
2163 $post_status = $_REQUEST['post_status']; |
2024 } else { |
2164 } else { |
2025 $post_status = ''; |
2165 $post_status = ''; |
2026 } |
2166 } |
2027 |
2167 |
2028 if ( ! empty( $post->post_password ) ) { |
2168 if ( ! empty( $post->post_password ) ) { |
2029 $post_states['protected'] = __( 'Password protected' ); |
2169 $post_states['protected'] = _x( 'Password protected', 'post status' ); |
2030 } |
2170 } |
2031 if ( 'private' == $post->post_status && 'private' != $post_status ) { |
2171 |
2032 $post_states['private'] = __( 'Private' ); |
2172 if ( 'private' === $post->post_status && 'private' !== $post_status ) { |
2033 } |
2173 $post_states['private'] = _x( 'Private', 'post status' ); |
2174 } |
|
2175 |
|
2034 if ( 'draft' === $post->post_status ) { |
2176 if ( 'draft' === $post->post_status ) { |
2035 if ( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) { |
2177 if ( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) { |
2036 $post_states[] = __( 'Customization Draft' ); |
2178 $post_states[] = __( 'Customization Draft' ); |
2037 } elseif ( 'draft' !== $post_status ) { |
2179 } elseif ( 'draft' !== $post_status ) { |
2038 $post_states['draft'] = __( 'Draft' ); |
2180 $post_states['draft'] = _x( 'Draft', 'post status' ); |
2039 } |
2181 } |
2040 } elseif ( 'trash' === $post->post_status && get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) { |
2182 } elseif ( 'trash' === $post->post_status && get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) { |
2041 $post_states[] = __( 'Customization Draft' ); |
2183 $post_states[] = _x( 'Customization Draft', 'post status' ); |
2042 } |
2184 } |
2043 if ( 'pending' == $post->post_status && 'pending' != $post_status ) { |
2185 |
2186 if ( 'pending' === $post->post_status && 'pending' !== $post_status ) { |
|
2044 $post_states['pending'] = _x( 'Pending', 'post status' ); |
2187 $post_states['pending'] = _x( 'Pending', 'post status' ); |
2045 } |
2188 } |
2189 |
|
2046 if ( is_sticky( $post->ID ) ) { |
2190 if ( is_sticky( $post->ID ) ) { |
2047 $post_states['sticky'] = __( 'Sticky' ); |
2191 $post_states['sticky'] = _x( 'Sticky', 'post status' ); |
2048 } |
2192 } |
2049 |
2193 |
2050 if ( 'future' === $post->post_status ) { |
2194 if ( 'future' === $post->post_status ) { |
2051 $post_states['scheduled'] = __( 'Scheduled' ); |
2195 $post_states['scheduled'] = _x( 'Scheduled', 'post status' ); |
2052 } |
2196 } |
2053 |
2197 |
2054 if ( 'page' === get_option( 'show_on_front' ) ) { |
2198 if ( 'page' === get_option( 'show_on_front' ) ) { |
2055 if ( intval( get_option( 'page_on_front' ) ) === $post->ID ) { |
2199 if ( intval( get_option( 'page_on_front' ) ) === $post->ID ) { |
2056 $post_states['page_on_front'] = __( 'Front Page' ); |
2200 $post_states['page_on_front'] = _x( 'Front Page', 'page label' ); |
2057 } |
2201 } |
2058 |
2202 |
2059 if ( intval( get_option( 'page_for_posts' ) ) === $post->ID ) { |
2203 if ( intval( get_option( 'page_for_posts' ) ) === $post->ID ) { |
2060 $post_states['page_for_posts'] = __( 'Posts Page' ); |
2204 $post_states['page_for_posts'] = _x( 'Posts Page', 'page label' ); |
2061 } |
2205 } |
2062 } |
2206 } |
2063 |
2207 |
2064 if ( intval( get_option( 'wp_page_for_privacy_policy' ) ) === $post->ID ) { |
2208 if ( intval( get_option( 'wp_page_for_privacy_policy' ) ) === $post->ID ) { |
2065 $post_states['page_for_privacy_policy'] = __( 'Privacy Policy Page' ); |
2209 $post_states['page_for_privacy_policy'] = _x( 'Privacy Policy Page', 'page label' ); |
2066 } |
2210 } |
2067 |
2211 |
2068 /** |
2212 /** |
2069 * Filters the default post display states used in the posts list table. |
2213 * Filters the default post display states used in the posts list table. |
2070 * |
2214 * |
2071 * @since 2.8.0 |
2215 * @since 2.8.0 |
2072 * @since 3.6.0 Added the `$post` parameter. |
2216 * @since 3.6.0 Added the `$post` parameter. |
2217 * @since 5.5.0 Also applied in the Customizer context. If any admin functions |
|
2218 * are used within the filter, their existence should be checked |
|
2219 * with `function_exists()` before being used. |
|
2073 * |
2220 * |
2074 * @param string[] $post_states An array of post display states. |
2221 * @param string[] $post_states An array of post display states. |
2075 * @param WP_Post $post The current post object. |
2222 * @param WP_Post $post The current post object. |
2076 */ |
2223 */ |
2077 $post_states = apply_filters( 'display_post_states', $post_states, $post ); |
2224 return apply_filters( 'display_post_states', $post_states, $post ); |
2078 |
2225 } |
2079 if ( ! empty( $post_states ) ) { |
2226 |
2080 $state_count = count( $post_states ); |
2227 /** |
2081 $i = 0; |
2228 * Outputs the attachment media states as HTML. |
2082 echo ' — '; |
2229 * |
2083 foreach ( $post_states as $state ) { |
2230 * @since 3.2.0 |
2084 ++$i; |
2231 * |
2085 ( $i == $state_count ) ? $sep = '' : $sep = ', '; |
2232 * @param WP_Post $post The attachment post to retrieve states for. |
2086 echo "<span class='post-state'>$state$sep</span>"; |
|
2087 } |
|
2088 } |
|
2089 |
|
2090 } |
|
2091 |
|
2092 /** |
|
2093 * @param WP_Post $post |
|
2094 */ |
2233 */ |
2095 function _media_states( $post ) { |
2234 function _media_states( $post ) { |
2235 static $header_images; |
|
2236 |
|
2096 $media_states = array(); |
2237 $media_states = array(); |
2097 $stylesheet = get_option( 'stylesheet' ); |
2238 $stylesheet = get_option( 'stylesheet' ); |
2098 |
2239 |
2099 if ( current_theme_supports( 'custom-header' ) ) { |
2240 if ( current_theme_supports( 'custom-header' ) ) { |
2100 $meta_header = get_post_meta( $post->ID, '_wp_attachment_is_custom_header', true ); |
2241 $meta_header = get_post_meta( $post->ID, '_wp_attachment_is_custom_header', true ); |
2101 |
2242 |
2102 if ( is_random_header_image() ) { |
2243 if ( is_random_header_image() ) { |
2103 $header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' ); |
2244 if ( ! isset( $header_images ) ) { |
2104 |
2245 $header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' ); |
2105 if ( $meta_header == $stylesheet && in_array( $post->ID, $header_images ) ) { |
2246 } |
2247 |
|
2248 if ( $meta_header === $stylesheet && in_array( $post->ID, $header_images, true ) ) { |
|
2106 $media_states[] = __( 'Header Image' ); |
2249 $media_states[] = __( 'Header Image' ); |
2107 } |
2250 } |
2108 } else { |
2251 } else { |
2109 $header_image = get_header_image(); |
2252 $header_image = get_header_image(); |
2110 |
2253 |
2111 // Display "Header Image" if the image was ever used as a header image |
2254 // Display "Header Image" if the image was ever used as a header image. |
2112 if ( ! empty( $meta_header ) && $meta_header == $stylesheet && $header_image !== wp_get_attachment_url( $post->ID ) ) { |
2255 if ( ! empty( $meta_header ) && $meta_header === $stylesheet && wp_get_attachment_url( $post->ID ) !== $header_image ) { |
2113 $media_states[] = __( 'Header Image' ); |
2256 $media_states[] = __( 'Header Image' ); |
2114 } |
2257 } |
2115 |
2258 |
2116 // Display "Current Header Image" if the image is currently the header image |
2259 // Display "Current Header Image" if the image is currently the header image. |
2117 if ( $header_image && $header_image == wp_get_attachment_url( $post->ID ) ) { |
2260 if ( $header_image && wp_get_attachment_url( $post->ID ) === $header_image ) { |
2118 $media_states[] = __( 'Current Header Image' ); |
2261 $media_states[] = __( 'Current Header Image' ); |
2119 } |
2262 } |
2120 } |
2263 } |
2121 } |
2264 } |
2122 |
2265 |
2123 if ( current_theme_supports( 'custom-background' ) ) { |
2266 if ( current_theme_supports( 'custom-background' ) ) { |
2124 $meta_background = get_post_meta( $post->ID, '_wp_attachment_is_custom_background', true ); |
2267 $meta_background = get_post_meta( $post->ID, '_wp_attachment_is_custom_background', true ); |
2125 |
2268 |
2126 if ( ! empty( $meta_background ) && $meta_background == $stylesheet ) { |
2269 if ( ! empty( $meta_background ) && $meta_background === $stylesheet ) { |
2127 $media_states[] = __( 'Background Image' ); |
2270 $media_states[] = __( 'Background Image' ); |
2128 |
2271 |
2129 $background_image = get_background_image(); |
2272 $background_image = get_background_image(); |
2130 if ( $background_image && $background_image == wp_get_attachment_url( $post->ID ) ) { |
2273 if ( $background_image && wp_get_attachment_url( $post->ID ) === $background_image ) { |
2131 $media_states[] = __( 'Current Background Image' ); |
2274 $media_states[] = __( 'Current Background Image' ); |
2132 } |
2275 } |
2133 } |
2276 } |
2134 } |
2277 } |
2135 |
2278 |
2136 if ( $post->ID == get_option( 'site_icon' ) ) { |
2279 if ( (int) get_option( 'site_icon' ) === $post->ID ) { |
2137 $media_states[] = __( 'Site Icon' ); |
2280 $media_states[] = __( 'Site Icon' ); |
2138 } |
2281 } |
2139 |
2282 |
2140 if ( $post->ID == get_theme_mod( 'custom_logo' ) ) { |
2283 if ( (int) get_theme_mod( 'custom_logo' ) === $post->ID ) { |
2141 $media_states[] = __( 'Logo' ); |
2284 $media_states[] = __( 'Logo' ); |
2142 } |
2285 } |
2143 |
2286 |
2144 /** |
2287 /** |
2145 * Filters the default media display states for items in the Media list table. |
2288 * Filters the default media display states for items in the Media list table. |
2154 $media_states = apply_filters( 'display_media_states', $media_states, $post ); |
2297 $media_states = apply_filters( 'display_media_states', $media_states, $post ); |
2155 |
2298 |
2156 if ( ! empty( $media_states ) ) { |
2299 if ( ! empty( $media_states ) ) { |
2157 $state_count = count( $media_states ); |
2300 $state_count = count( $media_states ); |
2158 $i = 0; |
2301 $i = 0; |
2302 |
|
2159 echo ' — '; |
2303 echo ' — '; |
2304 |
|
2160 foreach ( $media_states as $state ) { |
2305 foreach ( $media_states as $state ) { |
2161 ++$i; |
2306 $sep = ( ++$i === $state_count ) ? '' : ', '; |
2162 ( $i == $state_count ) ? $sep = '' : $sep = ', '; |
2307 |
2163 echo "<span class='post-state'>$state$sep</span>"; |
2308 echo "<span class='post-state'>$state$sep</span>"; |
2164 } |
2309 } |
2165 } |
2310 } |
2166 } |
2311 } |
2167 |
2312 |
2215 |
2360 |
2216 return; |
2361 return; |
2217 } |
2362 } |
2218 |
2363 |
2219 if ( 2 == test ) { |
2364 if ( 2 == test ) { |
2220 if ( '"wpCompressionTest' == r ) |
2365 if ( '"wpCompressionTest' === r ) |
2221 this.get('yes'); |
2366 this.get('yes'); |
2222 else |
2367 else |
2223 this.get('no'); |
2368 this.get('no'); |
2224 } |
2369 } |
2225 } |
2370 } |
2281 $type = explode( ' ', $type ); |
2426 $type = explode( ' ', $type ); |
2282 } |
2427 } |
2283 |
2428 |
2284 $button_shorthand = array( 'primary', 'small', 'large' ); |
2429 $button_shorthand = array( 'primary', 'small', 'large' ); |
2285 $classes = array( 'button' ); |
2430 $classes = array( 'button' ); |
2431 |
|
2286 foreach ( $type as $t ) { |
2432 foreach ( $type as $t ) { |
2287 if ( 'secondary' === $t || 'button-secondary' === $t ) { |
2433 if ( 'secondary' === $t || 'button-secondary' === $t ) { |
2288 continue; |
2434 continue; |
2289 } |
2435 } |
2290 $classes[] = in_array( $t, $button_shorthand ) ? 'button-' . $t : $t; |
2436 |
2291 } |
2437 $classes[] = in_array( $t, $button_shorthand, true ) ? 'button-' . $t : $t; |
2438 } |
|
2439 |
|
2292 // Remove empty items, remove duplicate items, and finally build a string. |
2440 // Remove empty items, remove duplicate items, and finally build a string. |
2293 $class = implode( ' ', array_unique( array_filter( $classes ) ) ); |
2441 $class = implode( ' ', array_unique( array_filter( $classes ) ) ); |
2294 |
2442 |
2295 $text = $text ? $text : __( 'Save Changes' ); |
2443 $text = $text ? $text : __( 'Save Changes' ); |
2296 |
2444 |
2297 // Default the id attribute to $name unless an id was specifically provided in $other_attributes |
2445 // Default the id attribute to $name unless an id was specifically provided in $other_attributes. |
2298 $id = $name; |
2446 $id = $name; |
2299 if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) { |
2447 if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) { |
2300 $id = $other_attributes['id']; |
2448 $id = $other_attributes['id']; |
2301 unset( $other_attributes['id'] ); |
2449 unset( $other_attributes['id'] ); |
2302 } |
2450 } |
2303 |
2451 |
2304 $attributes = ''; |
2452 $attributes = ''; |
2305 if ( is_array( $other_attributes ) ) { |
2453 if ( is_array( $other_attributes ) ) { |
2306 foreach ( $other_attributes as $attribute => $value ) { |
2454 foreach ( $other_attributes as $attribute => $value ) { |
2307 $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important |
2455 $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important. |
2308 } |
2456 } |
2309 } elseif ( ! empty( $other_attributes ) ) { // Attributes provided as a string |
2457 } elseif ( ! empty( $other_attributes ) ) { // Attributes provided as a string. |
2310 $attributes = $other_attributes; |
2458 $attributes = $other_attributes; |
2311 } |
2459 } |
2312 |
2460 |
2313 // Don't output empty name and id attributes. |
2461 // Don't output empty name and id attributes. |
2314 $name_attr = $name ? ' name="' . esc_attr( $name ) . '"' : ''; |
2462 $name_attr = $name ? ' name="' . esc_attr( $name ) . '"' : ''; |
2331 global $is_IE; |
2479 global $is_IE; |
2332 |
2480 |
2333 $admin_html_class = ( is_admin_bar_showing() ) ? 'wp-toolbar' : ''; |
2481 $admin_html_class = ( is_admin_bar_showing() ) ? 'wp-toolbar' : ''; |
2334 |
2482 |
2335 if ( $is_IE ) { |
2483 if ( $is_IE ) { |
2336 @header( 'X-UA-Compatible: IE=edge' ); |
2484 header( 'X-UA-Compatible: IE=edge' ); |
2337 } |
2485 } |
2338 |
2486 |
2339 ?> |
2487 ?> |
2340 <!DOCTYPE html> |
2488 <!DOCTYPE html> |
2341 <!--[if IE 8]> |
2489 <html class="<?php echo $admin_html_class; ?>" |
2342 <html xmlns="http://www.w3.org/1999/xhtml" class="ie8 <?php echo $admin_html_class; ?>" |
|
2343 <?php |
2490 <?php |
2344 /** |
2491 /** |
2345 * Fires inside the HTML tag in the admin header. |
2492 * Fires inside the HTML tag in the admin header. |
2346 * |
2493 * |
2347 * @since 2.2.0 |
2494 * @since 2.2.0 |
2348 */ |
2495 */ |
2349 do_action( 'admin_xml_ns' ); |
2496 do_action( 'admin_xml_ns' ); |
2350 |
2497 |
2351 language_attributes(); |
2498 language_attributes(); |
2352 ?> |
2499 ?> |
2353 > |
2500 > |
2354 <![endif]--> |
|
2355 <!--[if !(IE 8) ]><!--> |
|
2356 <html xmlns="http://www.w3.org/1999/xhtml" class="<?php echo $admin_html_class; ?>" |
|
2357 <?php |
|
2358 /** This action is documented in wp-admin/includes/template.php */ |
|
2359 do_action( 'admin_xml_ns' ); |
|
2360 |
|
2361 language_attributes(); |
|
2362 ?> |
|
2363 > |
|
2364 <!--<![endif]--> |
|
2365 <head> |
2501 <head> |
2366 <meta http-equiv="Content-Type" content="<?php bloginfo( 'html_type' ); ?>; charset=<?php echo get_option( 'blog_charset' ); ?>" /> |
2502 <meta http-equiv="Content-Type" content="<?php bloginfo( 'html_type' ); ?>; charset=<?php echo get_option( 'blog_charset' ); ?>" /> |
2367 <?php |
2503 <?php |
2368 } |
2504 } |
2369 |
2505 |
2439 * of echoing it. Default true. |
2575 * of echoing it. Default true. |
2440 * } |
2576 * } |
2441 * @return string Star rating HTML. |
2577 * @return string Star rating HTML. |
2442 */ |
2578 */ |
2443 function wp_star_rating( $args = array() ) { |
2579 function wp_star_rating( $args = array() ) { |
2444 $defaults = array( |
2580 $defaults = array( |
2445 'rating' => 0, |
2581 'rating' => 0, |
2446 'type' => 'rating', |
2582 'type' => 'rating', |
2447 'number' => 0, |
2583 'number' => 0, |
2448 'echo' => true, |
2584 'echo' => true, |
2449 ); |
2585 ); |
2450 $r = wp_parse_args( $args, $defaults ); |
2586 $parsed_args = wp_parse_args( $args, $defaults ); |
2451 |
2587 |
2452 // Non-English decimal places when the $rating is coming from a string |
2588 // Non-English decimal places when the $rating is coming from a string. |
2453 $rating = (float) str_replace( ',', '.', $r['rating'] ); |
2589 $rating = (float) str_replace( ',', '.', $parsed_args['rating'] ); |
2454 |
2590 |
2455 // Convert Percentage to star rating, 0..5 in .5 increments |
2591 // Convert percentage to star rating, 0..5 in .5 increments. |
2456 if ( 'percent' === $r['type'] ) { |
2592 if ( 'percent' === $parsed_args['type'] ) { |
2457 $rating = round( $rating / 10, 0 ) / 2; |
2593 $rating = round( $rating / 10, 0 ) / 2; |
2458 } |
2594 } |
2459 |
2595 |
2460 // Calculate the number of each type of star needed |
2596 // Calculate the number of each type of star needed. |
2461 $full_stars = floor( $rating ); |
2597 $full_stars = floor( $rating ); |
2462 $half_stars = ceil( $rating - $full_stars ); |
2598 $half_stars = ceil( $rating - $full_stars ); |
2463 $empty_stars = 5 - $full_stars - $half_stars; |
2599 $empty_stars = 5 - $full_stars - $half_stars; |
2464 |
2600 |
2465 if ( $r['number'] ) { |
2601 if ( $parsed_args['number'] ) { |
2466 /* translators: 1: the rating, 2: the number of ratings */ |
2602 /* translators: 1: The rating, 2: The number of ratings. */ |
2467 $format = _n( '%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $r['number'] ); |
2603 $format = _n( '%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $parsed_args['number'] ); |
2468 $title = sprintf( $format, number_format_i18n( $rating, 1 ), number_format_i18n( $r['number'] ) ); |
2604 $title = sprintf( $format, number_format_i18n( $rating, 1 ), number_format_i18n( $parsed_args['number'] ) ); |
2469 } else { |
2605 } else { |
2470 /* translators: %s: the rating */ |
2606 /* translators: %s: The rating. */ |
2471 $title = sprintf( __( '%s rating' ), number_format_i18n( $rating, 1 ) ); |
2607 $title = sprintf( __( '%s rating' ), number_format_i18n( $rating, 1 ) ); |
2472 } |
2608 } |
2473 |
2609 |
2474 $output = '<div class="star-rating">'; |
2610 $output = '<div class="star-rating">'; |
2475 $output .= '<span class="screen-reader-text">' . $title . '</span>'; |
2611 $output .= '<span class="screen-reader-text">' . $title . '</span>'; |
2476 $output .= str_repeat( '<div class="star star-full" aria-hidden="true"></div>', $full_stars ); |
2612 $output .= str_repeat( '<div class="star star-full" aria-hidden="true"></div>', $full_stars ); |
2477 $output .= str_repeat( '<div class="star star-half" aria-hidden="true"></div>', $half_stars ); |
2613 $output .= str_repeat( '<div class="star star-half" aria-hidden="true"></div>', $half_stars ); |
2478 $output .= str_repeat( '<div class="star star-empty" aria-hidden="true"></div>', $empty_stars ); |
2614 $output .= str_repeat( '<div class="star star-empty" aria-hidden="true"></div>', $empty_stars ); |
2479 $output .= '</div>'; |
2615 $output .= '</div>'; |
2480 |
2616 |
2481 if ( $r['echo'] ) { |
2617 if ( $parsed_args['echo'] ) { |
2482 echo $output; |
2618 echo $output; |
2483 } |
2619 } |
2484 |
2620 |
2485 return $output; |
2621 return $output; |
2486 } |
2622 } |