5 * A Big Mess. Also some neat functions that are nicely written. |
5 * A Big Mess. Also some neat functions that are nicely written. |
6 * |
6 * |
7 * @package WordPress |
7 * @package WordPress |
8 * @subpackage Administration |
8 * @subpackage Administration |
9 */ |
9 */ |
|
10 |
|
11 /** Walker_Category_Checklist class */ |
|
12 require_once( ABSPATH . 'wp-admin/includes/class-walker-category-checklist.php' ); |
|
13 |
|
14 /** WP_Internal_Pointers class */ |
|
15 require_once( ABSPATH . 'wp-admin/includes/class-wp-internal-pointers.php' ); |
10 |
16 |
11 // |
17 // |
12 // Category Checklists |
18 // Category Checklists |
13 // |
19 // |
14 |
|
15 /** |
|
16 * Walker to output an unordered list of category checkbox input elements. |
|
17 * |
|
18 * @since 2.5.1 |
|
19 * |
|
20 * @see Walker |
|
21 * @see wp_category_checklist() |
|
22 * @see wp_terms_checklist() |
|
23 */ |
|
24 class Walker_Category_Checklist extends Walker { |
|
25 public $tree_type = 'category'; |
|
26 public $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this |
|
27 |
|
28 /** |
|
29 * Starts the list before the elements are added. |
|
30 * |
|
31 * @see Walker:start_lvl() |
|
32 * |
|
33 * @since 2.5.1 |
|
34 * |
|
35 * @param string $output Passed by reference. Used to append additional content. |
|
36 * @param int $depth Depth of category. Used for tab indentation. |
|
37 * @param array $args An array of arguments. @see wp_terms_checklist() |
|
38 */ |
|
39 public function start_lvl( &$output, $depth = 0, $args = array() ) { |
|
40 $indent = str_repeat("\t", $depth); |
|
41 $output .= "$indent<ul class='children'>\n"; |
|
42 } |
|
43 |
|
44 /** |
|
45 * Ends the list of after the elements are added. |
|
46 * |
|
47 * @see Walker::end_lvl() |
|
48 * |
|
49 * @since 2.5.1 |
|
50 * |
|
51 * @param string $output Passed by reference. Used to append additional content. |
|
52 * @param int $depth Depth of category. Used for tab indentation. |
|
53 * @param array $args An array of arguments. @see wp_terms_checklist() |
|
54 */ |
|
55 public function end_lvl( &$output, $depth = 0, $args = array() ) { |
|
56 $indent = str_repeat("\t", $depth); |
|
57 $output .= "$indent</ul>\n"; |
|
58 } |
|
59 |
|
60 /** |
|
61 * Start the element output. |
|
62 * |
|
63 * @see Walker::start_el() |
|
64 * |
|
65 * @since 2.5.1 |
|
66 * |
|
67 * @param string $output Passed by reference. Used to append additional content. |
|
68 * @param object $category The current term object. |
|
69 * @param int $depth Depth of the term in reference to parents. Default 0. |
|
70 * @param array $args An array of arguments. @see wp_terms_checklist() |
|
71 * @param int $id ID of the current term. |
|
72 */ |
|
73 public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { |
|
74 if ( empty( $args['taxonomy'] ) ) { |
|
75 $taxonomy = 'category'; |
|
76 } else { |
|
77 $taxonomy = $args['taxonomy']; |
|
78 } |
|
79 |
|
80 if ( $taxonomy == 'category' ) { |
|
81 $name = 'post_category'; |
|
82 } else { |
|
83 $name = 'tax_input[' . $taxonomy . ']'; |
|
84 } |
|
85 |
|
86 $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats']; |
|
87 $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : ''; |
|
88 |
|
89 $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats']; |
|
90 |
|
91 /** This filter is documented in wp-includes/category-template.php */ |
|
92 if ( ! empty( $args['list_only'] ) ) { |
|
93 $aria_cheched = 'false'; |
|
94 $inner_class = 'category'; |
|
95 |
|
96 if ( in_array( $category->term_id, $args['selected_cats'] ) ) { |
|
97 $inner_class .= ' selected'; |
|
98 $aria_cheched = 'true'; |
|
99 } |
|
100 |
|
101 $output .= "\n" . '<li' . $class . '>' . |
|
102 '<div class="' . $inner_class . '" data-term-id=' . $category->term_id . |
|
103 ' tabindex="0" role="checkbox" aria-checked="' . $aria_cheched . '">' . |
|
104 esc_html( apply_filters( 'the_category', $category->name ) ) . '</div>'; |
|
105 } else { |
|
106 $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . |
|
107 '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . |
|
108 checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) . |
|
109 disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . |
|
110 esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>'; |
|
111 } |
|
112 } |
|
113 |
|
114 /** |
|
115 * Ends the element output, if needed. |
|
116 * |
|
117 * @see Walker::end_el() |
|
118 * |
|
119 * @since 2.5.1 |
|
120 * |
|
121 * @param string $output Passed by reference. Used to append additional content. |
|
122 * @param object $category The current term object. |
|
123 * @param int $depth Depth of the term in reference to parents. Default 0. |
|
124 * @param array $args An array of arguments. @see wp_terms_checklist() |
|
125 */ |
|
126 public function end_el( &$output, $category, $depth = 0, $args = array() ) { |
|
127 $output .= "</li>\n"; |
|
128 } |
|
129 } |
|
130 |
20 |
131 /** |
21 /** |
132 * 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. |
133 * |
23 * |
134 * @since 2.5.1 |
24 * @since 2.5.1 |
177 * @type object $walker Walker object to use to build the output. |
68 * @type object $walker Walker object to use to build the output. |
178 * Default is a Walker_Category_Checklist instance. |
69 * Default is a Walker_Category_Checklist instance. |
179 * @type string $taxonomy Taxonomy to generate the checklist for. Default 'category'. |
70 * @type string $taxonomy Taxonomy to generate the checklist for. Default 'category'. |
180 * @type bool $checked_ontop Whether to move checked items out of the hierarchy and to |
71 * @type bool $checked_ontop Whether to move checked items out of the hierarchy and to |
181 * the top of the list. Default true. |
72 * the top of the list. Default true. |
|
73 * @type bool $echo Whether to echo the generated markup. False to return the markup instead |
|
74 * of echoing it. Default true. |
182 * } |
75 * } |
183 */ |
76 */ |
184 function wp_terms_checklist( $post_id = 0, $args = array() ) { |
77 function wp_terms_checklist( $post_id = 0, $args = array() ) { |
185 $defaults = array( |
78 $defaults = array( |
186 'descendants_and_self' => 0, |
79 'descendants_and_self' => 0, |
187 'selected_cats' => false, |
80 'selected_cats' => false, |
188 'popular_cats' => false, |
81 'popular_cats' => false, |
189 'walker' => null, |
82 'walker' => null, |
190 'taxonomy' => 'category', |
83 'taxonomy' => 'category', |
191 'checked_ontop' => true |
84 'checked_ontop' => true, |
|
85 'echo' => true, |
192 ); |
86 ); |
193 |
87 |
194 /** |
88 /** |
195 * Filter the taxonomy terms checklist arguments. |
89 * Filters the taxonomy terms checklist arguments. |
196 * |
90 * |
197 * @since 3.4.0 |
91 * @since 3.4.0 |
198 * |
92 * |
199 * @see wp_terms_checklist() |
93 * @see wp_terms_checklist() |
200 * |
94 * |
249 array_unshift( $categories, $self ); |
143 array_unshift( $categories, $self ); |
250 } else { |
144 } else { |
251 $categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) ); |
145 $categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) ); |
252 } |
146 } |
253 |
147 |
|
148 $output = ''; |
|
149 |
254 if ( $r['checked_ontop'] ) { |
150 if ( $r['checked_ontop'] ) { |
255 // 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) |
151 // 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) |
256 $checked_categories = array(); |
152 $checked_categories = array(); |
257 $keys = array_keys( $categories ); |
153 $keys = array_keys( $categories ); |
258 |
154 |
259 foreach( $keys as $k ) { |
155 foreach ( $keys as $k ) { |
260 if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) { |
156 if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) { |
261 $checked_categories[] = $categories[$k]; |
157 $checked_categories[] = $categories[$k]; |
262 unset( $categories[$k] ); |
158 unset( $categories[$k] ); |
263 } |
159 } |
264 } |
160 } |
265 |
161 |
266 // Put checked cats on top |
162 // Put checked cats on top |
267 echo call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) ); |
163 $output .= call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) ); |
268 } |
164 } |
269 // Then the rest of them |
165 // Then the rest of them |
270 echo call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) ); |
166 $output .= call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) ); |
|
167 |
|
168 if ( $r['echo'] ) { |
|
169 echo $output; |
|
170 } |
|
171 |
|
172 return $output; |
271 } |
173 } |
272 |
174 |
273 /** |
175 /** |
274 * Retrieve a list of the most popular terms from the specified taxonomy. |
176 * Retrieve a list of the most popular terms from the specified taxonomy. |
275 * |
177 * |
299 $tax = get_taxonomy($taxonomy); |
201 $tax = get_taxonomy($taxonomy); |
300 |
202 |
301 $popular_ids = array(); |
203 $popular_ids = array(); |
302 foreach ( (array) $terms as $term ) { |
204 foreach ( (array) $terms as $term ) { |
303 $popular_ids[] = $term->term_id; |
205 $popular_ids[] = $term->term_id; |
304 if ( !$echo ) // hack for AJAX use |
206 if ( !$echo ) // Hack for Ajax use. |
305 continue; |
207 continue; |
306 $id = "popular-$taxonomy-$term->term_id"; |
208 $id = "popular-$taxonomy-$term->term_id"; |
307 $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : ''; |
209 $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : ''; |
308 ?> |
210 ?> |
309 |
211 |
310 <li id="<?php echo $id; ?>" class="popular-category"> |
212 <li id="<?php echo $id; ?>" class="popular-category"> |
311 <label class="selectit"> |
213 <label class="selectit"> |
312 <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 ) ); ?> /> |
214 <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 ) ); ?> /> |
313 <?php |
215 <?php |
314 /** This filter is documented in wp-includes/category-template.php */ |
216 /** This filter is documented in wp-includes/category-template.php */ |
315 echo esc_html( apply_filters( 'the_category', $term->name ) ); |
217 echo esc_html( apply_filters( 'the_category', $term->name, '', '' ) ); |
316 ?> |
218 ?> |
317 </label> |
219 </label> |
318 </li> |
220 </li> |
319 |
221 |
320 <?php |
222 <?php |
321 } |
223 } |
322 return $popular_ids; |
224 return $popular_ids; |
323 } |
225 } |
324 |
226 |
325 /** |
227 /** |
326 * {@internal Missing Short Description}} |
228 * Outputs a link category checklist element. |
327 * |
229 * |
328 * @since 2.5.1 |
230 * @since 2.5.1 |
329 * |
231 * |
330 * @param int $link_id |
232 * @param int $link_id |
331 */ |
233 */ |
388 <div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div> |
291 <div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div> |
389 <div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div> |
292 <div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div> |
390 <div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div> |
293 <div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div> |
391 <div class="post_password">' . esc_html( $post->post_password ) . '</div>'; |
294 <div class="post_password">' . esc_html( $post->post_password ) . '</div>'; |
392 |
295 |
393 if ( $post_type_object->hierarchical ) |
296 if ( $post_type_object->hierarchical ) { |
394 echo '<div class="post_parent">' . $post->post_parent . '</div>'; |
297 echo '<div class="post_parent">' . $post->post_parent . '</div>'; |
395 |
298 } |
396 if ( $post->post_type == 'page' ) |
299 |
397 echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>'; |
300 echo '<div class="page_template">' . ( $post->page_template ? esc_html( $post->page_template ) : 'default' ) . '</div>'; |
398 |
301 |
399 if ( post_type_supports( $post->post_type, 'page-attributes' ) ) |
302 if ( post_type_supports( $post->post_type, 'page-attributes' ) ) { |
400 echo '<div class="menu_order">' . $post->menu_order . '</div>'; |
303 echo '<div class="menu_order">' . $post->menu_order . '</div>'; |
|
304 } |
401 |
305 |
402 $taxonomy_names = get_object_taxonomies( $post->post_type ); |
306 $taxonomy_names = get_object_taxonomies( $post->post_type ); |
403 foreach ( $taxonomy_names as $taxonomy_name) { |
307 foreach ( $taxonomy_names as $taxonomy_name) { |
404 $taxonomy = get_taxonomy( $taxonomy_name ); |
308 $taxonomy = get_taxonomy( $taxonomy_name ); |
405 |
309 |
406 if ( $taxonomy->hierarchical && $taxonomy->show_ui ) { |
310 if ( $taxonomy->hierarchical && $taxonomy->show_ui ) { |
407 |
311 |
408 $terms = get_object_term_cache( $post->ID, $taxonomy_name ); |
312 $terms = get_object_term_cache( $post->ID, $taxonomy_name ); |
409 if ( false === $terms ) { |
313 if ( false === $terms ) { |
410 $terms = wp_get_object_terms( $post->ID, $taxonomy_name ); |
314 $terms = wp_get_object_terms( $post->ID, $taxonomy_name ); |
411 wp_cache_add( $post->ID, $terms, $taxonomy_name . '_relationships' ); |
315 wp_cache_add( $post->ID, wp_list_pluck( $terms, 'term_id' ), $taxonomy_name . '_relationships' ); |
412 } |
316 } |
413 $term_ids = empty( $terms ) ? array() : wp_list_pluck( $terms, 'term_id' ); |
317 $term_ids = empty( $terms ) ? array() : wp_list_pluck( $terms, 'term_id' ); |
414 |
318 |
415 echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode( ',', $term_ids ) . '</div>'; |
319 echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode( ',', $term_ids ) . '</div>'; |
416 |
320 |
417 } elseif ( $taxonomy->show_ui ) { |
321 } elseif ( $taxonomy->show_ui ) { |
418 |
322 |
|
323 $terms_to_edit = get_terms_to_edit( $post->ID, $taxonomy_name ); |
|
324 if ( ! is_string( $terms_to_edit ) ) { |
|
325 $terms_to_edit = ''; |
|
326 } |
|
327 |
419 echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">' |
328 echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">' |
420 . esc_html( str_replace( ',', ', ', get_terms_to_edit( $post->ID, $taxonomy_name ) ) ) . '</div>'; |
329 . esc_html( str_replace( ',', ', ', $terms_to_edit ) ) . '</div>'; |
421 |
330 |
422 } |
331 } |
423 } |
332 } |
424 |
333 |
425 if ( !$post_type_object->hierarchical ) |
334 if ( !$post_type_object->hierarchical ) |
426 echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>'; |
335 echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>'; |
427 |
336 |
428 if ( post_type_supports( $post->post_type, 'post-formats' ) ) |
337 if ( post_type_supports( $post->post_type, 'post-formats' ) ) |
429 echo '<div class="post_format">' . esc_html( get_post_format( $post->ID ) ) . '</div>'; |
338 echo '<div class="post_format">' . esc_html( get_post_format( $post->ID ) ) . '</div>'; |
430 |
339 |
|
340 /** |
|
341 * Fires after outputting the fields for the inline editor for posts and pages. |
|
342 * |
|
343 * @since 4.9.8 |
|
344 * |
|
345 * @param WP_Post $post The current post object. |
|
346 * @param WP_Post_Type $post_type_object The current post's post type object. |
|
347 */ |
|
348 do_action( 'add_inline_data', $post, $post_type_object ); |
|
349 |
431 echo '</div>'; |
350 echo '</div>'; |
432 } |
351 } |
433 |
352 |
434 /** |
353 /** |
435 * {@internal Missing Short Description}} |
354 * Outputs the in-line comment reply-to form in the Comments list table. |
436 * |
355 * |
437 * @since 2.7.0 |
356 * @since 2.7.0 |
438 * |
357 * |
439 * @param int $position |
358 * @global WP_List_Table $wp_list_table |
440 * @param bool $checkbox |
359 * |
|
360 * @param int $position |
|
361 * @param bool $checkbox |
441 * @param string $mode |
362 * @param string $mode |
442 * @param bool $table_row |
363 * @param bool $table_row |
443 */ |
364 */ |
444 function wp_comment_reply( $position = 1, $checkbox = false, $mode = 'single', $table_row = true ) { |
365 function wp_comment_reply( $position = 1, $checkbox = false, $mode = 'single', $table_row = true ) { |
445 global $wp_list_table; |
366 global $wp_list_table; |
446 /** |
367 /** |
447 * Filter the in-line comment reply-to form output in the Comments |
368 * Filters the in-line comment reply-to form output in the Comments |
448 * list table. |
369 * list table. |
449 * |
370 * |
450 * Returning a non-empty value here will short-circuit display |
371 * Returning a non-empty value here will short-circuit display |
451 * of the in-line comment-reply form in the Comments list table, |
372 * of the in-line comment-reply form in the Comments list table, |
452 * echoing the returned value instead. |
373 * echoing the returned value instead. |
474 } |
395 } |
475 |
396 |
476 ?> |
397 ?> |
477 <form method="get"> |
398 <form method="get"> |
478 <?php if ( $table_row ) : ?> |
399 <?php if ( $table_row ) : ?> |
479 <table style="display:none;"><tbody id="com-reply"><tr id="replyrow" style="display:none;"><td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="colspanchange"> |
400 <table style="display:none;"><tbody id="com-reply"><tr id="replyrow" class="inline-edit-row" style="display:none;"><td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="colspanchange"> |
480 <?php else : ?> |
401 <?php else : ?> |
481 <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;"> |
402 <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;"> |
482 <?php endif; ?> |
403 <?php endif; ?> |
483 <div id="replyhead" style="display:none;"><h5><?php _e( 'Reply to Comment' ); ?></h5></div> |
404 <fieldset class="comment-reply"> |
484 <div id="addhead" style="display:none;"><h5><?php _e('Add new Comment'); ?></h5></div> |
405 <legend> |
485 <div id="edithead" style="display:none;"> |
406 <span class="hidden" id="editlegend"><?php _e( 'Edit Comment' ); ?></span> |
486 <div class="inside"> |
407 <span class="hidden" id="replyhead"><?php _e( 'Reply to Comment' ); ?></span> |
487 <label for="author"><?php _e('Name') ?></label> |
408 <span class="hidden" id="addhead"><?php _e( 'Add new Comment' ); ?></span> |
488 <input type="text" name="newcomment_author" size="50" value="" id="author" /> |
409 </legend> |
489 </div> |
|
490 |
|
491 <div class="inside"> |
|
492 <label for="author-email"><?php _e('E-mail') ?></label> |
|
493 <input type="text" name="newcomment_author_email" size="50" value="" id="author-email" /> |
|
494 </div> |
|
495 |
|
496 <div class="inside"> |
|
497 <label for="author-url"><?php _e('URL') ?></label> |
|
498 <input type="text" id="author-url" name="newcomment_author_url" class="code" size="103" value="" /> |
|
499 </div> |
|
500 <div style="clear:both;"></div> |
|
501 </div> |
|
502 |
410 |
503 <div id="replycontainer"> |
411 <div id="replycontainer"> |
|
412 <label for="replycontent" class="screen-reader-text"><?php _e( 'Comment' ); ?></label> |
504 <?php |
413 <?php |
505 $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' ); |
414 $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' ); |
506 wp_editor( '', 'replycontent', array( 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings ) ); |
415 wp_editor( '', 'replycontent', array( 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings ) ); |
507 ?> |
416 ?> |
508 </div> |
417 </div> |
509 |
418 |
510 <p id="replysubmit" class="submit"> |
419 <div id="edithead" style="display:none;"> |
511 <a href="#comments-form" class="save button-primary alignright"> |
420 <div class="inside"> |
512 <span id="addbtn" style="display:none;"><?php _e('Add Comment'); ?></span> |
421 <label for="author-name"><?php _e( 'Name' ) ?></label> |
513 <span id="savebtn" style="display:none;"><?php _e('Update Comment'); ?></span> |
422 <input type="text" name="newcomment_author" size="50" value="" id="author-name" /> |
514 <span id="replybtn" style="display:none;"><?php _e('Submit Reply'); ?></span></a> |
423 </div> |
515 <a href="#comments-form" class="cancel button-secondary alignleft"><?php _e('Cancel'); ?></a> |
424 |
516 <span class="waiting spinner"></span> |
425 <div class="inside"> |
517 <span class="error" style="display:none;"></span> |
426 <label for="author-email"><?php _e('Email') ?></label> |
518 <br class="clear" /> |
427 <input type="text" name="newcomment_author_email" size="50" value="" id="author-email" /> |
519 </p> |
428 </div> |
|
429 |
|
430 <div class="inside"> |
|
431 <label for="author-url"><?php _e('URL') ?></label> |
|
432 <input type="text" id="author-url" name="newcomment_author_url" class="code" size="103" value="" /> |
|
433 </div> |
|
434 </div> |
|
435 |
|
436 <div id="replysubmit" class="submit"> |
|
437 <p> |
|
438 <a href="#comments-form" class="save button button-primary alignright"> |
|
439 <span id="addbtn" style="display: none;"><?php _e( 'Add Comment' ); ?></span> |
|
440 <span id="savebtn" style="display: none;"><?php _e( 'Update Comment' ); ?></span> |
|
441 <span id="replybtn" style="display: none;"><?php _e( 'Submit Reply' ); ?></span> |
|
442 </a> |
|
443 <a href="#comments-form" class="cancel button alignleft"><?php _e( 'Cancel' ); ?></a> |
|
444 <span class="waiting spinner"></span> |
|
445 </p> |
|
446 <br class="clear" /> |
|
447 <div class="notice notice-error notice-alt inline hidden"> |
|
448 <p class="error"></p> |
|
449 </div> |
|
450 </div> |
520 |
451 |
521 <input type="hidden" name="action" id="action" value="" /> |
452 <input type="hidden" name="action" id="action" value="" /> |
522 <input type="hidden" name="comment_ID" id="comment_ID" value="" /> |
453 <input type="hidden" name="comment_ID" id="comment_ID" value="" /> |
523 <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" /> |
454 <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" /> |
524 <input type="hidden" name="status" id="status" value="" /> |
455 <input type="hidden" name="status" id="status" value="" /> |
654 /** |
588 /** |
655 * Prints the form in the Custom Fields meta box. |
589 * Prints the form in the Custom Fields meta box. |
656 * |
590 * |
657 * @since 1.2.0 |
591 * @since 1.2.0 |
658 * |
592 * |
|
593 * @global wpdb $wpdb WordPress database abstraction object. |
|
594 * |
659 * @param WP_Post $post Optional. The post being edited. |
595 * @param WP_Post $post Optional. The post being edited. |
660 */ |
596 */ |
661 function meta_form( $post = null ) { |
597 function meta_form( $post = null ) { |
662 global $wpdb; |
598 global $wpdb; |
663 $post = get_post( $post ); |
599 $post = get_post( $post ); |
664 |
600 |
665 /** |
601 /** |
666 * Filter the number of custom fields to retrieve for the drop-down |
602 * Filters values for the meta key dropdown in the Custom Fields meta box. |
667 * in the Custom Fields meta box. |
|
668 * |
603 * |
669 * @since 2.1.0 |
604 * Returning a non-null value will effectively short-circuit and avoid a |
|
605 * potentially expensive query against postmeta. |
670 * |
606 * |
671 * @param int $limit Number of custom fields to retrieve. Default 30. |
607 * @since 4.4.0 |
|
608 * |
|
609 * @param array|null $keys Pre-defined meta keys to be used in place of a postmeta query. Default null. |
|
610 * @param WP_Post $post The current post object. |
672 */ |
611 */ |
673 $limit = apply_filters( 'postmeta_form_limit', 30 ); |
612 $keys = apply_filters( 'postmeta_form_keys', null, $post ); |
674 $sql = "SELECT meta_key |
613 |
675 FROM $wpdb->postmeta |
614 if ( null === $keys ) { |
676 GROUP BY meta_key |
615 /** |
677 HAVING meta_key NOT LIKE %s |
616 * Filters the number of custom fields to retrieve for the drop-down |
678 ORDER BY meta_key |
617 * in the Custom Fields meta box. |
679 LIMIT %d"; |
618 * |
680 $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) ); |
619 * @since 2.1.0 |
|
620 * |
|
621 * @param int $limit Number of custom fields to retrieve. Default 30. |
|
622 */ |
|
623 $limit = apply_filters( 'postmeta_form_limit', 30 ); |
|
624 $sql = "SELECT DISTINCT meta_key |
|
625 FROM $wpdb->postmeta |
|
626 WHERE meta_key NOT BETWEEN '_' AND '_z' |
|
627 HAVING meta_key NOT LIKE %s |
|
628 ORDER BY meta_key |
|
629 LIMIT %d"; |
|
630 $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) ); |
|
631 } |
|
632 |
681 if ( $keys ) { |
633 if ( $keys ) { |
682 natcasesort( $keys ); |
634 natcasesort( $keys ); |
683 $meta_key_input_id = 'metakeyselect'; |
635 $meta_key_input_id = 'metakeyselect'; |
684 } else { |
636 } else { |
685 $meta_key_input_id = 'metakeyinput'; |
637 $meta_key_input_id = 'metakeyinput'; |
756 |
711 |
757 // todo: Remove this? |
712 // todo: Remove this? |
758 // 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 />'; |
713 // 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 />'; |
759 |
714 |
760 $time_adj = current_time('timestamp'); |
715 $time_adj = current_time('timestamp'); |
761 $post_date = ($for_post) ? $post->post_date : $comment->comment_date; |
716 $post_date = ($for_post) ? $post->post_date : get_comment()->comment_date; |
762 $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj ); |
717 $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj ); |
763 $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj ); |
718 $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj ); |
764 $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj ); |
719 $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj ); |
765 $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj ); |
720 $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj ); |
766 $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj ); |
721 $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj ); |
770 $cur_mm = gmdate( 'm', $time_adj ); |
725 $cur_mm = gmdate( 'm', $time_adj ); |
771 $cur_aa = gmdate( 'Y', $time_adj ); |
726 $cur_aa = gmdate( 'Y', $time_adj ); |
772 $cur_hh = gmdate( 'H', $time_adj ); |
727 $cur_hh = gmdate( 'H', $time_adj ); |
773 $cur_mn = gmdate( 'i', $time_adj ); |
728 $cur_mn = gmdate( 'i', $time_adj ); |
774 |
729 |
775 $month = '<label for="mm" class="screen-reader-text">' . __( 'Month' ) . '</label><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n"; |
730 $month = '<label><span class="screen-reader-text">' . __( 'Month' ) . '</span><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n"; |
776 for ( $i = 1; $i < 13; $i = $i +1 ) { |
731 for ( $i = 1; $i < 13; $i = $i +1 ) { |
777 $monthnum = zeroise($i, 2); |
732 $monthnum = zeroise($i, 2); |
778 $month .= "\t\t\t" . '<option value="' . $monthnum . '" ' . selected( $monthnum, $mm, false ) . '>'; |
733 $monthtext = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ); |
|
734 $month .= "\t\t\t" . '<option value="' . $monthnum . '" data-text="' . $monthtext . '" ' . selected( $monthnum, $mm, false ) . '>'; |
779 /* translators: 1: month number (01, 02, etc.), 2: month abbreviation */ |
735 /* translators: 1: month number (01, 02, etc.), 2: month abbreviation */ |
780 $month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) ) . "</option>\n"; |
736 $month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $monthtext ) . "</option>\n"; |
781 } |
737 } |
782 $month .= '</select>'; |
738 $month .= '</select></label>'; |
783 |
739 |
784 $day = '<label for="jj" class="screen-reader-text">' . __( 'Day' ) . '</label><input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />'; |
740 $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>'; |
785 $year = '<label for="aa" class="screen-reader-text">' . __( 'Year' ) . '</label><input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" />'; |
741 $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>'; |
786 $hour = '<label for="hh" class="screen-reader-text">' . __( 'Hour' ) . '</label><input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />'; |
742 $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>'; |
787 $minute = '<label for="mn" class="screen-reader-text">' . __( 'Minute' ) . '</label><input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />'; |
743 $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>'; |
788 |
744 |
789 echo '<div class="timestamp-wrap">'; |
745 echo '<div class="timestamp-wrap">'; |
790 /* translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */ |
746 /* translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */ |
791 printf( __( '%1$s %2$s, %3$s @ %4$s : %5$s' ), $month, $day, $year, $hour, $minute ); |
747 printf( __( '%1$s %2$s, %3$s @ %4$s:%5$s' ), $month, $day, $year, $hour, $minute ); |
792 |
748 |
793 echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />'; |
749 echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />'; |
794 |
750 |
795 if ( $multi ) return; |
751 if ( $multi ) return; |
796 |
752 |
820 |
776 |
821 /** |
777 /** |
822 * Print out option HTML elements for the page templates drop-down. |
778 * Print out option HTML elements for the page templates drop-down. |
823 * |
779 * |
824 * @since 1.5.0 |
780 * @since 1.5.0 |
825 * |
781 * @since 4.7.0 Added the `$post_type` parameter. |
826 * @param string $default Optional. The template file name. Default empty. |
782 * |
827 */ |
783 * @param string $default Optional. The template file name. Default empty. |
828 function page_template_dropdown( $default = '' ) { |
784 * @param string $post_type Optional. Post type to get templates for. Default 'post'. |
829 $templates = get_page_templates( get_post() ); |
785 */ |
|
786 function page_template_dropdown( $default = '', $post_type = 'page' ) { |
|
787 $templates = get_page_templates( null, $post_type ); |
830 ksort( $templates ); |
788 ksort( $templates ); |
831 foreach ( array_keys( $templates ) as $template ) { |
789 foreach ( array_keys( $templates ) as $template ) { |
832 $selected = selected( $default, $templates[ $template ], false ); |
790 $selected = selected( $default, $templates[ $template ], false ); |
833 echo "\n\t<option value='" . $templates[ $template ] . "' $selected>$template</option>"; |
791 echo "\n\t<option value='" . esc_attr( $templates[ $template ] ) . "' $selected>" . esc_html( $template ) . "</option>"; |
834 } |
792 } |
835 } |
793 } |
836 |
794 |
837 /** |
795 /** |
838 * Print out option HTML elements for the page parents drop-down. |
796 * Print out option HTML elements for the page parents drop-down. |
839 * |
797 * |
840 * @since 1.5.0 |
798 * @since 1.5.0 |
841 * |
799 * @since 4.4.0 `$post` argument was added. |
842 * @param int $default Optional. The default page ID to be pre-selected. Default 0. |
800 * |
843 * @param int $parent Optional. The parent page ID. Default 0. |
801 * @global wpdb $wpdb WordPress database abstraction object. |
844 * @param int $level Optional. Page depth level. Default 0. |
802 * |
|
803 * @param int $default Optional. The default page ID to be pre-selected. Default 0. |
|
804 * @param int $parent Optional. The parent page ID. Default 0. |
|
805 * @param int $level Optional. Page depth level. Default 0. |
|
806 * @param int|WP_Post $post Post ID or WP_Post object. |
845 * |
807 * |
846 * @return null|false Boolean False if page has no children, otherwise print out html elements |
808 * @return null|false Boolean False if page has no children, otherwise print out html elements |
847 */ |
809 */ |
848 function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) { |
810 function parent_dropdown( $default = 0, $parent = 0, $level = 0, $post = null ) { |
849 global $wpdb; |
811 global $wpdb; |
850 $post = get_post(); |
812 $post = get_post( $post ); |
851 $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) ); |
813 $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) ); |
852 |
814 |
853 if ( $items ) { |
815 if ( $items ) { |
854 foreach ( $items as $item ) { |
816 foreach ( $items as $item ) { |
855 // A page cannot be its own parent. |
817 // A page cannot be its own parent. |
921 <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>) |
885 <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>) |
922 <input type="file" id="upload" name="import" size="25" /> |
886 <input type="file" id="upload" name="import" size="25" /> |
923 <input type="hidden" name="action" value="save" /> |
887 <input type="hidden" name="action" value="save" /> |
924 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" /> |
888 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" /> |
925 </p> |
889 </p> |
926 <?php submit_button( __('Upload file and import'), 'button' ); ?> |
890 <?php submit_button( __('Upload file and import'), 'primary' ); ?> |
927 </form> |
891 </form> |
928 <?php |
892 <?php |
929 endif; |
893 endif; |
930 } |
894 } |
931 |
895 |
932 /** |
896 /** |
933 * Add a meta box to an edit form. |
897 * Adds a meta box to one or more screens. |
934 * |
898 * |
935 * @since 2.5.0 |
899 * @since 2.5.0 |
936 * |
900 * @since 4.4.0 The `$screen` parameter now accepts an array of screen IDs. |
937 * @param string $id String for use in the 'id' attribute of tags. |
901 * |
938 * @param string $title Title of the meta box. |
902 * @global array $wp_meta_boxes |
939 * @param callback $callback Function that fills the box with the desired content. |
903 * |
940 * The function should echo its output. |
904 * @param string $id Meta box ID (used in the 'id' attribute for the meta box). |
941 * @param string|WP_Screen $screen Optional. The screen on which to show the box (like a post |
905 * @param string $title Title of the meta box. |
942 * type, 'link', or 'comment'). Default is the current screen. |
906 * @param callable $callback Function that fills the box with the desired content. |
943 * @param string $context Optional. The context within the screen where the boxes |
907 * The function should echo its output. |
944 * should display. Available contexts vary from screen to |
908 * @param string|array|WP_Screen $screen Optional. The screen or screens on which to show the box |
945 * screen. Post edit screen contexts include 'normal', 'side', |
909 * (such as a post type, 'link', or 'comment'). Accepts a single |
946 * and 'advanced'. Comments screen contexts include 'normal' |
910 * screen ID, WP_Screen object, or array of screen IDs. Default |
947 * and 'side'. Menus meta boxes (accordion sections) all use |
911 * is the current screen. If you have used add_menu_page() or |
948 * the 'side' context. Global default is 'advanced'. |
912 * add_submenu_page() to create a new screen (and hence screen_id), |
949 * @param string $priority Optional. The priority within the context where the boxes |
913 * make sure your menu slug conforms to the limits of sanitize_key() |
950 * should show ('high', 'low'). Default 'default'. |
914 * otherwise the 'screen' menu may not correctly render on your page. |
951 * @param array $callback_args Optional. Data that should be set as the $args property |
915 * @param string $context Optional. The context within the screen where the boxes |
952 * of the box array (which is the second parameter passed |
916 * should display. Available contexts vary from screen to |
953 * to your callback). Default null. |
917 * screen. Post edit screen contexts include 'normal', 'side', |
|
918 * and 'advanced'. Comments screen contexts include 'normal' |
|
919 * and 'side'. Menus meta boxes (accordion sections) all use |
|
920 * the 'side' context. Global default is 'advanced'. |
|
921 * @param string $priority Optional. The priority within the context where the boxes |
|
922 * should show ('high', 'low'). Default 'default'. |
|
923 * @param array $callback_args Optional. Data that should be set as the $args property |
|
924 * of the box array (which is the second parameter passed |
|
925 * to your callback). Default null. |
954 */ |
926 */ |
955 function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) { |
927 function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) { |
956 global $wp_meta_boxes; |
928 global $wp_meta_boxes; |
957 |
929 |
958 if ( empty( $screen ) ) |
930 if ( empty( $screen ) ) { |
959 $screen = get_current_screen(); |
931 $screen = get_current_screen(); |
960 elseif ( is_string( $screen ) ) |
932 } elseif ( is_string( $screen ) ) { |
961 $screen = convert_to_screen( $screen ); |
933 $screen = convert_to_screen( $screen ); |
|
934 } elseif ( is_array( $screen ) ) { |
|
935 foreach ( $screen as $single_screen ) { |
|
936 add_meta_box( $id, $title, $callback, $single_screen, $context, $priority, $callback_args ); |
|
937 } |
|
938 } |
|
939 |
|
940 if ( ! isset( $screen->id ) ) { |
|
941 return; |
|
942 } |
962 |
943 |
963 $page = $screen->id; |
944 $page = $screen->id; |
964 |
945 |
965 if ( !isset($wp_meta_boxes) ) |
946 if ( !isset($wp_meta_boxes) ) |
966 $wp_meta_boxes = array(); |
947 $wp_meta_boxes = array(); |
1084 return $i; |
1083 return $i; |
1085 |
1084 |
1086 } |
1085 } |
1087 |
1086 |
1088 /** |
1087 /** |
1089 * Remove a meta box from an edit form. |
1088 * Removes a meta box from one or more screens. |
1090 * |
1089 * |
1091 * @since 2.6.0 |
1090 * @since 2.6.0 |
1092 * |
1091 * @since 4.4.0 The `$screen` parameter now accepts an array of screen IDs. |
1093 * @param string $id String for use in the 'id' attribute of tags. |
1092 * |
1094 * @param string|object $screen The screen on which to show the box (post, page, link). |
1093 * @global array $wp_meta_boxes |
1095 * @param string $context The context within the page where the boxes should show ('normal', 'advanced'). |
1094 * |
1096 */ |
1095 * @param string $id Meta box ID (used in the 'id' attribute for the meta box). |
1097 function remove_meta_box($id, $screen, $context) { |
1096 * @param string|array|WP_Screen $screen The screen or screens on which the meta box is shown (such as a |
|
1097 * post type, 'link', or 'comment'). Accepts a single screen ID, |
|
1098 * WP_Screen object, or array of screen IDs. |
|
1099 * @param string $context The context within the screen where the box is set to display. |
|
1100 * Contexts vary from screen to screen. Post edit screen contexts |
|
1101 * include 'normal', 'side', and 'advanced'. Comments screen contexts |
|
1102 * include 'normal' and 'side'. Menus meta boxes (accordion sections) |
|
1103 * all use the 'side' context. |
|
1104 */ |
|
1105 function remove_meta_box( $id, $screen, $context ) { |
1098 global $wp_meta_boxes; |
1106 global $wp_meta_boxes; |
1099 |
1107 |
1100 if ( empty( $screen ) ) |
1108 if ( empty( $screen ) ) { |
1101 $screen = get_current_screen(); |
1109 $screen = get_current_screen(); |
1102 elseif ( is_string( $screen ) ) |
1110 } elseif ( is_string( $screen ) ) { |
1103 $screen = convert_to_screen( $screen ); |
1111 $screen = convert_to_screen( $screen ); |
|
1112 } elseif ( is_array( $screen ) ) { |
|
1113 foreach ( $screen as $single_screen ) { |
|
1114 remove_meta_box( $id, $single_screen, $context ); |
|
1115 } |
|
1116 } |
|
1117 |
|
1118 if ( ! isset( $screen->id ) ) { |
|
1119 return; |
|
1120 } |
1104 |
1121 |
1105 $page = $screen->id; |
1122 $page = $screen->id; |
1106 |
1123 |
1107 if ( !isset($wp_meta_boxes) ) |
1124 if ( !isset($wp_meta_boxes) ) |
1108 $wp_meta_boxes = array(); |
1125 $wp_meta_boxes = array(); |
1202 * |
1219 * |
1203 * @since 2.7.0 |
1220 * @since 2.7.0 |
1204 * |
1221 * |
1205 * @global $wp_settings_sections Storage array of all settings sections added to admin pages |
1222 * @global $wp_settings_sections Storage array of all settings sections added to admin pages |
1206 * |
1223 * |
1207 * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags. |
1224 * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags. |
1208 * @param string $title Formatted title of the section. Shown as the heading for the section. |
1225 * @param string $title Formatted title of the section. Shown as the heading for the section. |
1209 * @param string $callback Function that echos out any content at the top of the section (between heading and fields). |
1226 * @param callable $callback Function that echos out any content at the top of the section (between heading and fields). |
1210 * @param string $page The slug-name of the settings page on which to show the section. Built-in pages include 'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using add_options_page(); |
1227 * @param string $page The slug-name of the settings page on which to show the section. Built-in pages include |
|
1228 * 'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using |
|
1229 * add_options_page(); |
1211 */ |
1230 */ |
1212 function add_settings_section($id, $title, $callback, $page) { |
1231 function add_settings_section($id, $title, $callback, $page) { |
1213 global $wp_settings_sections; |
1232 global $wp_settings_sections; |
1214 |
1233 |
1215 if ( 'misc' == $page ) { |
1234 if ( 'misc' == $page ) { |
1216 _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) ); |
1235 _deprecated_argument( __FUNCTION__, '3.0.0', |
|
1236 /* translators: %s: misc */ |
|
1237 sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), |
|
1238 'misc' |
|
1239 ) |
|
1240 ); |
1217 $page = 'general'; |
1241 $page = 'general'; |
1218 } |
1242 } |
1219 |
1243 |
1220 if ( 'privacy' == $page ) { |
1244 if ( 'privacy' == $page ) { |
1221 _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) ); |
1245 _deprecated_argument( __FUNCTION__, '3.5.0', |
|
1246 /* translators: %s: privacy */ |
|
1247 sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), |
|
1248 'privacy' |
|
1249 ) |
|
1250 ); |
1222 $page = 'reading'; |
1251 $page = 'reading'; |
1223 } |
1252 } |
1224 |
1253 |
1225 $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback); |
1254 $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback); |
1226 } |
1255 } |
1239 * @since 2.7.0 |
1268 * @since 2.7.0 |
1240 * @since 4.2.0 The `$class` argument was added. |
1269 * @since 4.2.0 The `$class` argument was added. |
1241 * |
1270 * |
1242 * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections |
1271 * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections |
1243 * |
1272 * |
1244 * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags. |
1273 * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags. |
1245 * @param string $title Formatted title of the field. Shown as the label for the field |
1274 * @param string $title Formatted title of the field. Shown as the label for the field |
1246 * during output. |
1275 * during output. |
1247 * @param string $callback Function that fills the field with the desired form inputs. The |
1276 * @param callable $callback Function that fills the field with the desired form inputs. The |
1248 * function should echo its output. |
1277 * function should echo its output. |
1249 * @param string $page The slug-name of the settings page on which to show the section |
1278 * @param string $page The slug-name of the settings page on which to show the section |
1250 * (general, reading, writing, ...). |
1279 * (general, reading, writing, ...). |
1251 * @param string $section Optional. The slug-name of the section of the settings page |
1280 * @param string $section Optional. The slug-name of the section of the settings page |
1252 * in which to show the box. Default 'default'. |
1281 * in which to show the box. Default 'default'. |
1253 * @param array $args { |
1282 * @param array $args { |
1254 * Optional. Extra arguments used when outputting the field. |
1283 * Optional. Extra arguments used when outputting the field. |
1255 * |
1284 * |
1256 * @type string $label_for When supplied, the setting title will be wrapped |
1285 * @type string $label_for When supplied, the setting title will be wrapped |
1257 * in a `<label>` element, its `for` attribute populated |
1286 * in a `<label>` element, its `for` attribute populated |
1258 * with this value. |
1287 * with this value. |
1684 |
1745 |
1685 if ( !empty($post->post_password) ) |
1746 if ( !empty($post->post_password) ) |
1686 $post_states['protected'] = __('Password protected'); |
1747 $post_states['protected'] = __('Password protected'); |
1687 if ( 'private' == $post->post_status && 'private' != $post_status ) |
1748 if ( 'private' == $post->post_status && 'private' != $post_status ) |
1688 $post_states['private'] = __('Private'); |
1749 $post_states['private'] = __('Private'); |
1689 if ( 'draft' == $post->post_status && 'draft' != $post_status ) |
1750 if ( 'draft' === $post->post_status ) { |
1690 $post_states['draft'] = __('Draft'); |
1751 if ( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) { |
|
1752 $post_states[] = __( 'Customization Draft' ); |
|
1753 } elseif ( 'draft' !== $post_status ) { |
|
1754 $post_states['draft'] = __( 'Draft' ); |
|
1755 } |
|
1756 } elseif ( 'trash' === $post->post_status && get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) { |
|
1757 $post_states[] = __( 'Customization Draft' ); |
|
1758 } |
1691 if ( 'pending' == $post->post_status && 'pending' != $post_status ) |
1759 if ( 'pending' == $post->post_status && 'pending' != $post_status ) |
1692 /* translators: post state */ |
1760 $post_states['pending'] = _x('Pending', 'post status'); |
1693 $post_states['pending'] = _x('Pending', 'post state'); |
|
1694 if ( is_sticky($post->ID) ) |
1761 if ( is_sticky($post->ID) ) |
1695 $post_states['sticky'] = __('Sticky'); |
1762 $post_states['sticky'] = __('Sticky'); |
1696 |
1763 |
1697 if ( get_option( 'page_on_front' ) == $post->ID ) { |
1764 if ( 'future' === $post->post_status ) { |
1698 $post_states['page_on_front'] = __( 'Front Page' ); |
1765 $post_states['scheduled'] = __( 'Scheduled' ); |
1699 } |
1766 } |
1700 |
1767 |
1701 if ( get_option( 'page_for_posts' ) == $post->ID ) { |
1768 if ( 'page' === get_option( 'show_on_front' ) ) { |
1702 $post_states['page_for_posts'] = __( 'Posts Page' ); |
1769 if ( intval( get_option( 'page_on_front' ) ) === $post->ID ) { |
|
1770 $post_states['page_on_front'] = __( 'Front Page' ); |
|
1771 } |
|
1772 |
|
1773 if ( intval( get_option( 'page_for_posts' ) ) === $post->ID ) { |
|
1774 $post_states['page_for_posts'] = __( 'Posts Page' ); |
|
1775 } |
|
1776 } |
|
1777 |
|
1778 if ( intval( get_option( 'wp_page_for_privacy_policy' ) ) === $post->ID ) { |
|
1779 $post_states['page_for_privacy_policy'] = __( 'Privacy Policy Page' ); |
1703 } |
1780 } |
1704 |
1781 |
1705 /** |
1782 /** |
1706 * Filter the default post display states used in the posts list table. |
1783 * Filters the default post display states used in the posts list table. |
1707 * |
1784 * |
1708 * @since 2.8.0 |
1785 * @since 2.8.0 |
|
1786 * @since 3.6.0 Added the `$post` parameter. |
1709 * |
1787 * |
1710 * @param array $post_states An array of post display states. |
1788 * @param array $post_states An array of post display states. |
1711 * @param int $post The post ID. |
1789 * @param WP_Post $post The current post object. |
1712 */ |
1790 */ |
1713 $post_states = apply_filters( 'display_post_states', $post_states, $post ); |
1791 $post_states = apply_filters( 'display_post_states', $post_states, $post ); |
1714 |
1792 |
1715 if ( ! empty($post_states) ) { |
1793 if ( ! empty($post_states) ) { |
1716 $state_count = count($post_states); |
1794 $state_count = count($post_states); |
1717 $i = 0; |
1795 $i = 0; |
1718 echo ' - '; |
1796 echo ' — '; |
1719 foreach ( $post_states as $state ) { |
1797 foreach ( $post_states as $state ) { |
1720 ++$i; |
1798 ++$i; |
1721 ( $i == $state_count ) ? $sep = '' : $sep = ', '; |
1799 ( $i == $state_count ) ? $sep = '' : $sep = ', '; |
1722 echo "<span class='post-state'>$state$sep</span>"; |
1800 echo "<span class='post-state'>$state$sep</span>"; |
1723 } |
1801 } |
1724 } |
1802 } |
1725 |
1803 |
1726 } |
1804 } |
1727 |
1805 |
|
1806 /** |
|
1807 * |
|
1808 * @param WP_Post $post |
|
1809 */ |
1728 function _media_states( $post ) { |
1810 function _media_states( $post ) { |
1729 $media_states = array(); |
1811 $media_states = array(); |
1730 $stylesheet = get_option('stylesheet'); |
1812 $stylesheet = get_option('stylesheet'); |
1731 |
1813 |
1732 if ( current_theme_supports( 'custom-header') ) { |
1814 if ( current_theme_supports( 'custom-header') ) { |
1733 $meta_header = get_post_meta($post->ID, '_wp_attachment_is_custom_header', true ); |
1815 $meta_header = get_post_meta($post->ID, '_wp_attachment_is_custom_header', true ); |
1734 if ( ! empty( $meta_header ) && $meta_header == $stylesheet ) |
1816 |
1735 $media_states[] = __( 'Header Image' ); |
1817 if ( is_random_header_image() ) { |
|
1818 $header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' ); |
|
1819 |
|
1820 if ( $meta_header == $stylesheet && in_array( $post->ID, $header_images ) ) { |
|
1821 $media_states[] = __( 'Header Image' ); |
|
1822 } |
|
1823 } else { |
|
1824 $header_image = get_header_image(); |
|
1825 |
|
1826 // Display "Header Image" if the image was ever used as a header image |
|
1827 if ( ! empty( $meta_header ) && $meta_header == $stylesheet && $header_image !== wp_get_attachment_url( $post->ID ) ) { |
|
1828 $media_states[] = __( 'Header Image' ); |
|
1829 } |
|
1830 |
|
1831 // Display "Current Header Image" if the image is currently the header image |
|
1832 if ( $header_image && $header_image == wp_get_attachment_url( $post->ID ) ) { |
|
1833 $media_states[] = __( 'Current Header Image' ); |
|
1834 } |
|
1835 } |
1736 } |
1836 } |
1737 |
1837 |
1738 if ( current_theme_supports( 'custom-background') ) { |
1838 if ( current_theme_supports( 'custom-background') ) { |
1739 $meta_background = get_post_meta($post->ID, '_wp_attachment_is_custom_background', true ); |
1839 $meta_background = get_post_meta($post->ID, '_wp_attachment_is_custom_background', true ); |
1740 if ( ! empty( $meta_background ) && $meta_background == $stylesheet ) |
1840 |
|
1841 if ( ! empty( $meta_background ) && $meta_background == $stylesheet ) { |
1741 $media_states[] = __( 'Background Image' ); |
1842 $media_states[] = __( 'Background Image' ); |
|
1843 |
|
1844 $background_image = get_background_image(); |
|
1845 if ( $background_image && $background_image == wp_get_attachment_url( $post->ID ) ) { |
|
1846 $media_states[] = __( 'Current Background Image' ); |
|
1847 } |
|
1848 } |
|
1849 } |
|
1850 |
|
1851 if ( $post->ID == get_option( 'site_icon' ) ) { |
|
1852 $media_states[] = __( 'Site Icon' ); |
|
1853 } |
|
1854 |
|
1855 if ( $post->ID == get_theme_mod( 'custom_logo' ) ) { |
|
1856 $media_states[] = __( 'Logo' ); |
1742 } |
1857 } |
1743 |
1858 |
1744 /** |
1859 /** |
1745 * Filter the default media display states for items in the Media list table. |
1860 * Filters the default media display states for items in the Media list table. |
1746 * |
1861 * |
1747 * @since 3.2.0 |
1862 * @since 3.2.0 |
|
1863 * @since 4.8.0 Added the `$post` parameter. |
1748 * |
1864 * |
1749 * @param array $media_states An array of media states. Default 'Header Image', |
1865 * @param array $media_states An array of media states. Default 'Header Image', |
1750 * 'Background Image'. |
1866 * 'Background Image', 'Site Icon', 'Logo'. |
|
1867 * @param WP_Post $post The current attachment object. |
1751 */ |
1868 */ |
1752 $media_states = apply_filters( 'display_media_states', $media_states ); |
1869 $media_states = apply_filters( 'display_media_states', $media_states, $post ); |
1753 |
1870 |
1754 if ( ! empty( $media_states ) ) { |
1871 if ( ! empty( $media_states ) ) { |
1755 $state_count = count( $media_states ); |
1872 $state_count = count( $media_states ); |
1756 $i = 0; |
1873 $i = 0; |
1757 echo ' - '; |
1874 echo ' — '; |
1758 foreach ( $media_states as $state ) { |
1875 foreach ( $media_states as $state ) { |
1759 ++$i; |
1876 ++$i; |
1760 ( $i == $state_count ) ? $sep = '' : $sep = ', '; |
1877 ( $i == $state_count ) ? $sep = '' : $sep = ', '; |
1761 echo "<span class='post-state'>$state$sep</span>"; |
1878 echo "<span class='post-state'>$state$sep</span>"; |
1762 } |
1879 } |
1950 <head> |
2070 <head> |
1951 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" /> |
2071 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" /> |
1952 <?php |
2072 <?php |
1953 } |
2073 } |
1954 |
2074 |
1955 final class WP_Internal_Pointers { |
|
1956 /** |
|
1957 * Initializes the new feature pointers. |
|
1958 * |
|
1959 * @since 3.3.0 |
|
1960 * |
|
1961 * All pointers can be disabled using the following: |
|
1962 * remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) ); |
|
1963 * |
|
1964 * Individual pointers (e.g. wp390_widgets) can be disabled using the following: |
|
1965 * remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp390_widgets' ) ); |
|
1966 * |
|
1967 * @param string $hook_suffix The current admin page. |
|
1968 */ |
|
1969 public static function enqueue_scripts( $hook_suffix ) { |
|
1970 /* |
|
1971 * Register feature pointers |
|
1972 * Format: array( hook_suffix => pointer_id ) |
|
1973 */ |
|
1974 |
|
1975 $registered_pointers = array( |
|
1976 'post-new.php' => 'wp410_dfw', |
|
1977 'post.php' => 'wp410_dfw', |
|
1978 'edit.php' => 'wp360_locks', |
|
1979 'widgets.php' => 'wp390_widgets', |
|
1980 'themes.php' => 'wp390_widgets', |
|
1981 ); |
|
1982 |
|
1983 // Check if screen related pointer is registered |
|
1984 if ( empty( $registered_pointers[ $hook_suffix ] ) ) |
|
1985 return; |
|
1986 |
|
1987 $pointers = (array) $registered_pointers[ $hook_suffix ]; |
|
1988 |
|
1989 $caps_required = array( |
|
1990 'wp390_widgets' => array( 'edit_theme_options' ), |
|
1991 ); |
|
1992 |
|
1993 // Get dismissed pointers |
|
1994 $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ); |
|
1995 |
|
1996 $got_pointers = false; |
|
1997 foreach ( array_diff( $pointers, $dismissed ) as $pointer ) { |
|
1998 if ( isset( $caps_required[ $pointer ] ) ) { |
|
1999 foreach ( $caps_required[ $pointer ] as $cap ) { |
|
2000 if ( ! current_user_can( $cap ) ) |
|
2001 continue 2; |
|
2002 } |
|
2003 } |
|
2004 |
|
2005 // Bind pointer print function |
|
2006 add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) ); |
|
2007 $got_pointers = true; |
|
2008 } |
|
2009 |
|
2010 if ( ! $got_pointers ) |
|
2011 return; |
|
2012 |
|
2013 // Add pointers script and style to queue |
|
2014 wp_enqueue_style( 'wp-pointer' ); |
|
2015 wp_enqueue_script( 'wp-pointer' ); |
|
2016 } |
|
2017 |
|
2018 /** |
|
2019 * Print the pointer JavaScript data. |
|
2020 * |
|
2021 * @since 3.3.0 |
|
2022 * |
|
2023 * @param string $pointer_id The pointer ID. |
|
2024 * @param string $selector The HTML elements, on which the pointer should be attached. |
|
2025 * @param array $args Arguments to be passed to the pointer JS (see wp-pointer.js). |
|
2026 */ |
|
2027 private static function print_js( $pointer_id, $selector, $args ) { |
|
2028 if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) ) |
|
2029 return; |
|
2030 |
|
2031 ?> |
|
2032 <script type="text/javascript"> |
|
2033 (function($){ |
|
2034 var options = <?php echo wp_json_encode( $args ); ?>, setup; |
|
2035 |
|
2036 if ( ! options ) |
|
2037 return; |
|
2038 |
|
2039 options = $.extend( options, { |
|
2040 close: function() { |
|
2041 $.post( ajaxurl, { |
|
2042 pointer: '<?php echo $pointer_id; ?>', |
|
2043 action: 'dismiss-wp-pointer' |
|
2044 }); |
|
2045 } |
|
2046 }); |
|
2047 |
|
2048 setup = function() { |
|
2049 $('<?php echo $selector; ?>').first().pointer( options ).pointer('open'); |
|
2050 }; |
|
2051 |
|
2052 if ( options.position && options.position.defer_loading ) |
|
2053 $(window).bind( 'load.wp-pointers', setup ); |
|
2054 else |
|
2055 $(document).ready( setup ); |
|
2056 |
|
2057 })( jQuery ); |
|
2058 </script> |
|
2059 <?php |
|
2060 } |
|
2061 |
|
2062 public static function pointer_wp330_toolbar() {} |
|
2063 public static function pointer_wp330_media_uploader() {} |
|
2064 public static function pointer_wp330_saving_widgets() {} |
|
2065 public static function pointer_wp340_customize_current_theme_link() {} |
|
2066 public static function pointer_wp340_choose_image_from_library() {} |
|
2067 public static function pointer_wp350_media() {} |
|
2068 public static function pointer_wp360_revisions() {} |
|
2069 |
|
2070 public static function pointer_wp360_locks() { |
|
2071 if ( ! is_multi_author() ) { |
|
2072 return; |
|
2073 } |
|
2074 |
|
2075 $content = '<h3>' . __( 'Edit Lock' ) . '</h3>'; |
|
2076 $content .= '<p>' . __( 'Someone else is editing this. No need to refresh; the lock will disappear when they’re done.' ) . '</p>'; |
|
2077 |
|
2078 self::print_js( 'wp360_locks', 'tr.wp-locked .locked-indicator', array( |
|
2079 'content' => $content, |
|
2080 'position' => array( 'edge' => 'left', 'align' => 'left' ), |
|
2081 ) ); |
|
2082 } |
|
2083 |
|
2084 public static function pointer_wp390_widgets() { |
|
2085 if ( ! current_theme_supports( 'widgets' ) ) { |
|
2086 return; |
|
2087 } |
|
2088 |
|
2089 $content = '<h3>' . __( 'New Feature: Live Widget Previews' ) . '</h3>'; |
|
2090 $content .= '<p>' . __( 'Add, edit, and play around with your widgets from the Customizer.' ) . ' ' . __( 'Preview your changes in real-time and only save them when you’re ready.' ) . '</p>'; |
|
2091 |
|
2092 if ( 'themes' === get_current_screen()->id ) { |
|
2093 $selector = '.theme.active .customize'; |
|
2094 $position = array( 'edge' => is_rtl() ? 'right' : 'left', 'align' => 'center' ); |
|
2095 } else { |
|
2096 $selector = 'a[href^="customize.php"]'; |
|
2097 if ( is_rtl() ) { |
|
2098 $position = array( 'edge' => 'right', 'align' => 'center', 'my' => 'right-5px' ); |
|
2099 } else { |
|
2100 $position = array( 'edge' => 'left', 'align' => 'center', 'my' => 'left-5px' ); |
|
2101 } |
|
2102 } |
|
2103 |
|
2104 self::print_js( 'wp390_widgets', $selector, array( |
|
2105 'content' => $content, |
|
2106 'position' => $position, |
|
2107 ) ); |
|
2108 } |
|
2109 |
|
2110 public static function pointer_wp410_dfw() { |
|
2111 // Don't show when editor-scrolling is not used. |
|
2112 if ( empty( $GLOBALS['_wp_editor_expand'] ) ) { |
|
2113 return; |
|
2114 } |
|
2115 |
|
2116 $content = '<h3>' . __( 'Distraction-Free Writing' ) . '</h3>'; |
|
2117 $content .= '<p>' . __( 'Enable distraction-free writing mode, and everything surrounding the editor will fade away when you start typing. Move your mouse out of the editor to reveal everything again.' ) . '</p>'; |
|
2118 |
|
2119 if ( is_rtl() ) { |
|
2120 $position = array( 'edge' => 'left', 'align' => 'center', 'my' => 'left+40 top-11', 'at' => 'left top' ); |
|
2121 } else { |
|
2122 $position = array( 'edge' => 'right', 'align' => 'center', 'my' => 'right-40 top-11', 'at' => 'right top' ); |
|
2123 } |
|
2124 |
|
2125 self::print_js( 'wp410_dfw', '#wp-content-wrap', array( |
|
2126 'content' => $content, |
|
2127 'position' => $position, |
|
2128 ) ); |
|
2129 } |
|
2130 |
|
2131 /** |
|
2132 * Prevents new users from seeing existing 'new feature' pointers. |
|
2133 * |
|
2134 * @since 3.3.0 |
|
2135 * |
|
2136 * @param int $user_id User ID. |
|
2137 */ |
|
2138 public static function dismiss_pointers_for_new_users( $user_id ) { |
|
2139 add_user_meta( $user_id, 'dismissed_wp_pointers', 'wp360_locks,wp390_widgets' ); |
|
2140 } |
|
2141 } |
|
2142 |
|
2143 add_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) ); |
|
2144 add_action( 'user_register', array( 'WP_Internal_Pointers', 'dismiss_pointers_for_new_users' ) ); |
|
2145 |
|
2146 /** |
2075 /** |
2147 * Convert a screen string to a screen object |
2076 * Convert a screen string to a screen object |
2148 * |
2077 * |
2149 * @since 3.0.0 |
2078 * @since 3.0.0 |
2150 * |
2079 * |
2151 * @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen. |
2080 * @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen. |
2152 * @return WP_Screen Screen object. |
2081 * @return WP_Screen Screen object. |
2153 */ |
2082 */ |
2154 function convert_to_screen( $hook_name ) { |
2083 function convert_to_screen( $hook_name ) { |
2155 if ( ! class_exists( 'WP_Screen' ) ) { |
2084 if ( ! class_exists( 'WP_Screen' ) ) { |
2156 _doing_it_wrong( 'convert_to_screen(), add_meta_box()', __( "Likely direct inclusion of wp-admin/includes/template.php in order to use add_meta_box(). This is very wrong. Hook the add_meta_box() call into the add_meta_boxes action instead." ), '3.3' ); |
2085 _doing_it_wrong( |
|
2086 'convert_to_screen(), add_meta_box()', |
|
2087 sprintf( |
|
2088 /* translators: 1: wp-admin/includes/template.php 2: add_meta_box() 3: add_meta_boxes */ |
|
2089 __( 'Likely direct inclusion of %1$s in order to use %2$s. This is very wrong. Hook the %2$s call into the %3$s action instead.' ), |
|
2090 '<code>wp-admin/includes/template.php</code>', |
|
2091 '<code>add_meta_box()</code>', |
|
2092 '<code>add_meta_boxes</code>' |
|
2093 ), |
|
2094 '3.3.0' |
|
2095 ); |
2157 return (object) array( 'id' => '_invalid', 'base' => '_are_belong_to_us' ); |
2096 return (object) array( 'id' => '_invalid', 'base' => '_are_belong_to_us' ); |
2158 } |
2097 } |
2159 |
2098 |
2160 return WP_Screen::get( $hook_name ); |
2099 return WP_Screen::get( $hook_name ); |
2161 } |
2100 } |
2187 * Outputs a HTML element with the star rating exposed on a 0..5 scale in |
2125 * Outputs a HTML element with the star rating exposed on a 0..5 scale in |
2188 * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the |
2126 * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the |
2189 * number of ratings may also be displayed by passing the $number parameter. |
2127 * number of ratings may also be displayed by passing the $number parameter. |
2190 * |
2128 * |
2191 * @since 3.8.0 |
2129 * @since 3.8.0 |
|
2130 * @since 4.4.0 Introduced the `echo` parameter. |
|
2131 * |
2192 * @param array $args { |
2132 * @param array $args { |
2193 * Optional. Array of star ratings arguments. |
2133 * Optional. Array of star ratings arguments. |
2194 * |
2134 * |
2195 * @type int $rating The rating to display, expressed in either a 0.5 rating increment, |
2135 * @type int|float $rating The rating to display, expressed in either a 0.5 rating increment, |
2196 * or percentage. Default 0. |
2136 * or percentage. Default 0. |
2197 * @type string $type Format that the $rating is in. Valid values are 'rating' (default), |
2137 * @type string $type Format that the $rating is in. Valid values are 'rating' (default), |
2198 * or, 'percent'. Default 'rating'. |
2138 * or, 'percent'. Default 'rating'. |
2199 * @type int $number The number of ratings that makes up this rating. Default 0. |
2139 * @type int $number The number of ratings that makes up this rating. Default 0. |
|
2140 * @type bool $echo Whether to echo the generated markup. False to return the markup instead |
|
2141 * of echoing it. Default true. |
2200 * } |
2142 * } |
|
2143 * @return string Star rating HTML. |
2201 */ |
2144 */ |
2202 function wp_star_rating( $args = array() ) { |
2145 function wp_star_rating( $args = array() ) { |
2203 $defaults = array( |
2146 $defaults = array( |
2204 'rating' => 0, |
2147 'rating' => 0, |
2205 'type' => 'rating', |
2148 'type' => 'rating', |
2206 'number' => 0, |
2149 'number' => 0, |
|
2150 'echo' => true, |
2207 ); |
2151 ); |
2208 $r = wp_parse_args( $args, $defaults ); |
2152 $r = wp_parse_args( $args, $defaults ); |
2209 |
2153 |
2210 // Non-english decimal places when the $rating is coming from a string |
2154 // Non-English decimal places when the $rating is coming from a string |
2211 $rating = str_replace( ',', '.', $r['rating'] ); |
2155 $rating = (float) str_replace( ',', '.', $r['rating'] ); |
2212 |
2156 |
2213 // Convert Percentage to star rating, 0..5 in .5 increments |
2157 // Convert Percentage to star rating, 0..5 in .5 increments |
2214 if ( 'percent' == $r['type'] ) { |
2158 if ( 'percent' === $r['type'] ) { |
2215 $rating = round( $rating / 10, 0 ) / 2; |
2159 $rating = round( $rating / 10, 0 ) / 2; |
2216 } |
2160 } |
2217 |
2161 |
2218 // Calculate the number of each type of star needed |
2162 // Calculate the number of each type of star needed |
2219 $full_stars = floor( $rating ); |
2163 $full_stars = floor( $rating ); |