3
* Template WordPress Administration API.
5
* A Big Mess. Also some neat functions that are nicely written.
8
* @subpackage Administration
12
// Category Checklists
16
* Walker to output an unordered list of category checkbox <input> elements.
19
* @see wp_category_checklist()
20
* @see wp_terms_checklist()
23
class Walker_Category_Checklist extends Walker {
24
public $tree_type = 'category';
25
public $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
28
* Starts the list before the elements are added.
30
* @see Walker:start_lvl()
34
* @param string $output Passed by reference. Used to append additional content.
35
* @param int $depth Depth of category. Used for tab indentation.
36
* @param array $args An array of arguments. @see wp_terms_checklist()
38
public function start_lvl( &$output, $depth = 0, $args = array() ) {
39
$indent = str_repeat("\t", $depth);
40
$output .= "$indent<ul class='children'>\n";
44
* Ends the list of after the elements are added.
46
* @see Walker::end_lvl()
50
* @param string $output Passed by reference. Used to append additional content.
51
* @param int $depth Depth of category. Used for tab indentation.
52
* @param array $args An array of arguments. @see wp_terms_checklist()
54
public function end_lvl( &$output, $depth = 0, $args = array() ) {
55
$indent = str_repeat("\t", $depth);
56
$output .= "$indent</ul>\n";
60
* Start the element output.
62
* @see Walker::start_el()
66
* @param string $output Passed by reference. Used to append additional content.
67
* @param object $category The current term object.
68
* @param int $depth Depth of the term in reference to parents. Default 0.
69
* @param array $args An array of arguments. @see wp_terms_checklist()
70
* @param int $id ID of the current term.
72
public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
73
if ( empty( $args['taxonomy'] ) ) {
74
$taxonomy = 'category';
76
$taxonomy = $args['taxonomy'];
79
if ( $taxonomy == 'category' ) {
80
$name = 'post_category';
82
$name = 'tax_input[' . $taxonomy . ']';
84
$args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
85
$class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';
87
$args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
89
/** This filter is documented in wp-includes/category-template.php */
90
$output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
91
'<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' .
92
checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) .
93
disabled( empty( $args['disabled'] ), false, false ) . ' /> ' .
94
esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>';
98
* Ends the element output, if needed.
100
* @see Walker::end_el()
104
* @param string $output Passed by reference. Used to append additional content.
105
* @param object $category The current term object.
106
* @param int $depth Depth of the term in reference to parents. Default 0.
107
* @param array $args An array of arguments. @see wp_terms_checklist()
109
public function end_el( &$output, $category, $depth = 0, $args = array() ) {
110
$output .= "</li>\n";
115
* Output an unordered list of checkbox <input> elements labelled
116
* with category names.
118
* @see wp_terms_checklist()
121
* @param int $post_id Mark categories associated with this post as checked. $selected_cats must not be an array.
122
* @param int $descendants_and_self ID of the category to output along with its descendents.
123
* @param bool|array $selected_cats List of categories to mark as checked.
124
* @param bool|array $popular_cats Override the list of categories that receive the "popular-category" class.
125
* @param object $walker Walker object to use to build the output.
126
* @param bool $checked_ontop Move checked items out of the hierarchy and to the top of the list.
128
function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) {
129
wp_terms_checklist( $post_id, array(
130
'taxonomy' => 'category',
131
'descendants_and_self' => $descendants_and_self,
132
'selected_cats' => $selected_cats,
133
'popular_cats' => $popular_cats,
135
'checked_ontop' => $checked_ontop
140
* Output an unordered list of checkbox <input> elements labelled
141
* with term names. Taxonomy independent version of wp_category_checklist().
145
* @param int $post_id
148
function wp_terms_checklist( $post_id = 0, $args = array() ) {
150
'descendants_and_self' => 0,
151
'selected_cats' => false,
152
'popular_cats' => false,
154
'taxonomy' => 'category',
155
'checked_ontop' => true
159
* Filter the taxonomy terms checklist arguments.
163
* @see wp_terms_checklist()
165
* @param array $args An array of arguments.
166
* @param int $post_id The post ID.
168
$params = apply_filters( 'wp_terms_checklist_args', $args, $post_id );
170
$r = wp_parse_args( $params, $defaults );
172
if ( empty( $r['walker'] ) || ! is_a( $r['walker'], 'Walker' ) ) {
173
$walker = new Walker_Category_Checklist;
175
$walker = $r['walker'];
178
$taxonomy = $r['taxonomy'];
179
$descendants_and_self = (int) $r['descendants_and_self'];
181
$args = array( 'taxonomy' => $taxonomy );
183
$tax = get_taxonomy( $taxonomy );
184
$args['disabled'] = ! current_user_can( $tax->cap->assign_terms );
186
if ( is_array( $r['selected_cats'] ) ) {
187
$args['selected_cats'] = $r['selected_cats'];
188
} elseif ( $post_id ) {
189
$args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) );
191
$args['selected_cats'] = array();
193
if ( is_array( $r['popular_cats'] ) ) {
194
$args['popular_cats'] = $r['popular_cats'];
196
$args['popular_cats'] = get_terms( $taxonomy, array(
198
'orderby' => 'count',
201
'hierarchical' => false
204
if ( $descendants_and_self ) {
205
$categories = (array) get_terms( $taxonomy, array(
206
'child_of' => $descendants_and_self,
210
$self = get_term( $descendants_and_self, $taxonomy );
211
array_unshift( $categories, $self );
213
$categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) );
216
if ( $r['checked_ontop'] ) {
217
// 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)
218
$checked_categories = array();
219
$keys = array_keys( $categories );
221
foreach( $keys as $k ) {
222
if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) {
223
$checked_categories[] = $categories[$k];
224
unset( $categories[$k] );
228
// Put checked cats on top
229
echo call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) );
231
// Then the rest of them
232
echo call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) );
236
* Retrieve a list of the most popular terms from the specified taxonomy.
238
* If the $echo argument is true then the elements for a list of checkbox
239
* <input> elements labelled with the names of the selected terms is output.
240
* If the $post_ID global isn't empty then the terms associated with that
241
* post will be marked as checked.
245
* @param string $taxonomy Taxonomy to retrieve terms from.
246
* @param int $default Unused.
247
* @param int $number Number of terms to retrieve. Defaults to 10.
248
* @param bool $echo Optionally output the list as well. Defaults to true.
249
* @return array List of popular term IDs.
251
function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
254
if ( $post && $post->ID )
255
$checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields'=>'ids'));
257
$checked_terms = array();
259
$terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
261
$tax = get_taxonomy($taxonomy);
263
$popular_ids = array();
264
foreach ( (array) $terms as $term ) {
265
$popular_ids[] = $term->term_id;
266
if ( !$echo ) // hack for AJAX use
268
$id = "popular-$taxonomy-$term->term_id";
269
$checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : '';
272
<li id="<?php echo $id; ?>" class="popular-category">
273
<label class="selectit">
274
<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 ) ); ?> />
276
/** This filter is documented in wp-includes/category-template.php */
277
echo esc_html( apply_filters( 'the_category', $term->name ) );
288
* {@internal Missing Short Description}}
292
* @param unknown_type $link_id
294
function wp_link_category_checklist( $link_id = 0 ) {
298
$checked_categories = wp_get_link_cats( $link_id );
299
// No selected categories, strange
300
if ( ! count( $checked_categories ) )
301
$checked_categories[] = $default;
303
$checked_categories[] = $default;
306
$categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) );
308
if ( empty( $categories ) )
311
foreach ( $categories as $category ) {
312
$cat_id = $category->term_id;
314
/** This filter is documented in wp-includes/category-template.php */
315
$name = esc_html( apply_filters( 'the_category', $category->name ) );
316
$checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : '';
317
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>";
321
// adds hidden fields with the data for use in the inline editor for posts and pages
323
* {@internal Missing Short Description}}
327
* @param unknown_type $post
329
function get_inline_data($post) {
330
$post_type_object = get_post_type_object($post->post_type);
331
if ( ! current_user_can( 'edit_post', $post->ID ) )
334
$title = esc_textarea( trim( $post->post_title ) );
336
/** This filter is documented in wp-admin/edit-tag-form.php */
338
<div class="hidden" id="inline_' . $post->ID . '">
339
<div class="post_title">' . $title . '</div>
340
<div class="post_name">' . apply_filters( 'editable_slug', $post->post_name ) . '</div>
341
<div class="post_author">' . $post->post_author . '</div>
342
<div class="comment_status">' . esc_html( $post->comment_status ) . '</div>
343
<div class="ping_status">' . esc_html( $post->ping_status ) . '</div>
344
<div class="_status">' . esc_html( $post->post_status ) . '</div>
345
<div class="jj">' . mysql2date( 'd', $post->post_date, false ) . '</div>
346
<div class="mm">' . mysql2date( 'm', $post->post_date, false ) . '</div>
347
<div class="aa">' . mysql2date( 'Y', $post->post_date, false ) . '</div>
348
<div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div>
349
<div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div>
350
<div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div>
351
<div class="post_password">' . esc_html( $post->post_password ) . '</div>';
353
if ( $post_type_object->hierarchical )
354
echo '<div class="post_parent">' . $post->post_parent . '</div>';
356
if ( $post->post_type == 'page' )
357
echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>';
359
if ( post_type_supports( $post->post_type, 'page-attributes' ) )
360
echo '<div class="menu_order">' . $post->menu_order . '</div>';
362
$taxonomy_names = get_object_taxonomies( $post->post_type );
363
foreach ( $taxonomy_names as $taxonomy_name) {
364
$taxonomy = get_taxonomy( $taxonomy_name );
366
if ( $taxonomy->hierarchical && $taxonomy->show_ui ) {
368
$terms = get_object_term_cache( $post->ID, $taxonomy_name );
369
if ( false === $terms ) {
370
$terms = wp_get_object_terms( $post->ID, $taxonomy_name );
371
wp_cache_add( $post->ID, $terms, $taxonomy_name . '_relationships' );
373
$term_ids = empty( $terms ) ? array() : wp_list_pluck( $terms, 'term_id' );
375
echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode( ',', $term_ids ) . '</div>';
377
} elseif ( $taxonomy->show_ui ) {
379
echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">'
380
. esc_html( str_replace( ',', ', ', get_terms_to_edit( $post->ID, $taxonomy_name ) ) ) . '</div>';
385
if ( !$post_type_object->hierarchical )
386
echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
388
if ( post_type_supports( $post->post_type, 'post-formats' ) )
389
echo '<div class="post_format">' . esc_html( get_post_format( $post->ID ) ) . '</div>';
395
* {@internal Missing Short Description}}
399
* @param unknown_type $position
400
* @param unknown_type $checkbox
401
* @param unknown_type $mode
403
function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single', $table_row = true) {
406
* Filter the in-line comment reply-to form output in the Comments
409
* Returning a non-empty value here will short-circuit display
410
* of the in-line comment-reply form in the Comments list table,
411
* echoing the returned value instead.
415
* @see wp_comment_reply()
417
* @param string $content The reply-to form content.
418
* @param array $args An array of default args.
420
$content = apply_filters( 'wp_comment_reply', '', array( 'position' => $position, 'checkbox' => $checkbox, 'mode' => $mode ) );
422
if ( ! empty($content) ) {
427
if ( $mode == 'single' ) {
428
$wp_list_table = _get_list_table('WP_Post_Comments_List_Table');
430
$wp_list_table = _get_list_table('WP_Comments_List_Table');
434
<form method="get" action="">
435
<?php if ( $table_row ) : ?>
436
<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">
438
<div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;">
440
<div id="replyhead" style="display:none;"><h5><?php _e( 'Reply to Comment' ); ?></h5></div>
441
<div id="addhead" style="display:none;"><h5><?php _e('Add new Comment'); ?></h5></div>
442
<div id="edithead" style="display:none;">
444
<label for="author"><?php _e('Name') ?></label>
445
<input type="text" name="newcomment_author" size="50" value="" id="author" />
449
<label for="author-email"><?php _e('E-mail') ?></label>
450
<input type="text" name="newcomment_author_email" size="50" value="" id="author-email" />
454
<label for="author-url"><?php _e('URL') ?></label>
455
<input type="text" id="author-url" name="newcomment_author_url" class="code" size="103" value="" />
457
<div style="clear:both;"></div>
460
<div id="replycontainer">
462
$quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' );
463
wp_editor( '', 'replycontent', array( 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings ) );
467
<p id="replysubmit" class="submit">
468
<a href="#comments-form" class="save button-primary alignright">
469
<span id="addbtn" style="display:none;"><?php _e('Add Comment'); ?></span>
470
<span id="savebtn" style="display:none;"><?php _e('Update Comment'); ?></span>
471
<span id="replybtn" style="display:none;"><?php _e('Submit Reply'); ?></span></a>
472
<a href="#comments-form" class="cancel button-secondary alignleft"><?php _e('Cancel'); ?></a>
473
<span class="waiting spinner"></span>
474
<span class="error" style="display:none;"></span>
478
<input type="hidden" name="user_ID" id="user_ID" value="<?php echo get_current_user_id(); ?>" />
479
<input type="hidden" name="action" id="action" value="" />
480
<input type="hidden" name="comment_ID" id="comment_ID" value="" />
481
<input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" />
482
<input type="hidden" name="status" id="status" value="" />
483
<input type="hidden" name="position" id="position" value="<?php echo $position; ?>" />
484
<input type="hidden" name="checkbox" id="checkbox" value="<?php echo $checkbox ? 1 : 0; ?>" />
485
<input type="hidden" name="mode" id="mode" value="<?php echo esc_attr($mode); ?>" />
487
wp_nonce_field( 'replyto-comment', '_ajax_nonce-replyto-comment', false );
488
if ( current_user_can( 'unfiltered_html' ) )
489
wp_nonce_field( 'unfiltered-html-comment', '_wp_unfiltered_html_comment', false );
491
<?php if ( $table_row ) : ?>
492
</td></tr></tbody></table>
501
* Output 'undo move to trash' text for comments
505
function wp_comment_trashnotice() {
507
<div class="hidden" id="trash-undo-holder">
508
<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>
510
<div class="hidden" id="spam-undo-holder">
511
<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>
517
* {@internal Missing Short Description}}
521
* @param unknown_type $meta
523
function list_meta( $meta ) {
527
<table id="list-table" style="display: none;">
530
<th class="left">' . _x( 'Name', 'meta name' ) . '</th>
531
<th>' . __( 'Value' ) . '</th>
534
<tbody id="the-list" data-wp-lists="list:meta">
537
</table>'; //TBODY needed for list-manipulation JS
542
<table id="list-table">
545
<th class="left"><?php _ex( 'Name', 'meta name' ) ?></th>
546
<th><?php _e( 'Value' ) ?></th>
549
<tbody id='the-list' data-wp-lists='list:meta'>
551
foreach ( $meta as $entry )
552
echo _list_meta_row( $entry, $count );
560
* {@internal Missing Short Description}}
564
* @param unknown_type $entry
565
* @param unknown_type $count
568
function _list_meta_row( $entry, &$count ) {
569
static $update_nonce = false;
571
if ( is_protected_meta( $entry['meta_key'], 'post' ) )
574
if ( !$update_nonce )
575
$update_nonce = wp_create_nonce( 'add-meta' );
580
$style = 'alternate';
584
if ( is_serialized( $entry['meta_value'] ) ) {
585
if ( is_serialized_string( $entry['meta_value'] ) ) {
586
// This is a serialized string, so we should display it.
587
$entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
589
// This is a serialized array/object so we should NOT display it.
595
$entry['meta_key'] = esc_attr($entry['meta_key']);
596
$entry['meta_value'] = esc_textarea( $entry['meta_value'] ); // using a <textarea />
597
$entry['meta_id'] = (int) $entry['meta_id'];
599
$delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
601
$r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
602
$r .= "\n\t\t<td class='left'><label class='screen-reader-text' for='meta-{$entry['meta_id']}-key'>" . __( 'Key' ) . "</label><input name='meta[{$entry['meta_id']}][key]' id='meta-{$entry['meta_id']}-key' type='text' size='20' value='{$entry['meta_key']}' />";
604
$r .= "\n\t\t<div class='submit'>";
605
$r .= get_submit_button( __( 'Delete' ), 'deletemeta small', "deletemeta[{$entry['meta_id']}]", false, array( 'data-wp-lists' => "delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce" ) );
607
$r .= get_submit_button( __( 'Update' ), 'updatemeta small', "meta-{$entry['meta_id']}-submit", false, array( 'data-wp-lists' => "add:the-list:meta-{$entry['meta_id']}::_ajax_nonce-add-meta=$update_nonce" ) );
609
$r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
612
$r .= "\n\t\t<td><label class='screen-reader-text' for='meta-{$entry['meta_id']}-value'>" . __( 'Value' ) . "</label><textarea name='meta[{$entry['meta_id']}][value]' id='meta-{$entry['meta_id']}-value' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>\n\t</tr>";
617
* Prints the form in the Custom Fields meta box.
621
* @param WP_Post $post Optional. The post being edited.
623
function meta_form( $post = null ) {
625
$post = get_post( $post );
628
* Filter the number of custom fields to retrieve for the drop-down
629
* in the Custom Fields meta box.
633
* @param int $limit Number of custom fields to retrieve. Default 30.
635
$limit = apply_filters( 'postmeta_form_limit', 30 );
636
$sql = "SELECT meta_key
639
HAVING meta_key NOT LIKE %s
642
$keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) );
644
natcasesort( $keys );
645
$meta_key_input_id = 'metakeyselect';
647
$meta_key_input_id = 'metakeyinput';
650
<p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p>
654
<th class="left"><label for="<?php echo $meta_key_input_id; ?>"><?php _ex( 'Name', 'meta name' ) ?></label></th>
655
<th><label for="metavalue"><?php _e( 'Value' ) ?></label></th>
661
<td id="newmetaleft" class="left">
662
<?php if ( $keys ) { ?>
663
<select id="metakeyselect" name="metakeyselect">
664
<option value="#NONE#"><?php _e( '— Select —' ); ?></option>
667
foreach ( $keys as $key ) {
668
if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $post->ID, $key ) )
670
echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>";
674
<input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" value="" />
675
<a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
676
<span id="enternew"><?php _e('Enter new'); ?></span>
677
<span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a>
679
<input type="text" id="metakeyinput" name="metakeyinput" value="" />
682
<td><textarea id="metavalue" name="metavalue" rows="2" cols="25"></textarea></td>
687
<?php submit_button( __( 'Add Custom Field' ), 'secondary', 'addmeta', false, array( 'id' => 'newmeta-submit', 'data-wp-lists' => 'add:the-list:newmeta' ) ); ?>
689
<?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?>
698
* Print out HTML form date elements for editing post or comment publish date.
702
* @param int|bool $edit Accepts 1|true for editing the date, 0|false for adding the date.
703
* @param int|bool $for_post Accepts 1|true for applying the date to a post, 0|false for a comment.
704
* @param int|bool $tab_index The tabindex attribute to add. Default 0.
705
* @param int|bool $multi Optional. Whether the additional fields and buttons should be added.
708
function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
709
global $wp_locale, $comment;
713
$edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );
715
$tab_index_attribute = '';
716
if ( (int) $tab_index > 0 )
717
$tab_index_attribute = " tabindex=\"$tab_index\"";
719
// todo: Remove this?
720
// 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 />';
722
$time_adj = current_time('timestamp');
723
$post_date = ($for_post) ? $post->post_date : $comment->comment_date;
724
$jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
725
$mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
726
$aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
727
$hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
728
$mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
729
$ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
731
$cur_jj = gmdate( 'd', $time_adj );
732
$cur_mm = gmdate( 'm', $time_adj );
733
$cur_aa = gmdate( 'Y', $time_adj );
734
$cur_hh = gmdate( 'H', $time_adj );
735
$cur_mn = gmdate( 'i', $time_adj );
737
$month = '<label for="mm" class="screen-reader-text">' . __( 'Month' ) . '</label><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n";
738
for ( $i = 1; $i < 13; $i = $i +1 ) {
739
$monthnum = zeroise($i, 2);
740
$month .= "\t\t\t" . '<option value="' . $monthnum . '" ' . selected( $monthnum, $mm, false ) . '>';
741
/* translators: 1: month number (01, 02, etc.), 2: month abbreviation */
742
$month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) ) . "</option>\n";
744
$month .= '</select>';
746
$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" />';
747
$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" />';
748
$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" />';
749
$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" />';
751
echo '<div class="timestamp-wrap">';
752
/* translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */
753
printf( __( '%1$s %2$s, %3$s @ %4$s : %5$s' ), $month, $day, $year, $hour, $minute );
755
echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
757
if ( $multi ) return;
761
'mm' => array( $mm, $cur_mm ),
762
'jj' => array( $jj, $cur_jj ),
763
'aa' => array( $aa, $cur_aa ),
764
'hh' => array( $hh, $cur_hh ),
765
'mn' => array( $mn, $cur_mn ),
767
foreach ( $map as $timeunit => $value ) {
768
list( $unit, $curr ) = $value;
770
echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $unit . '" />' . "\n";
771
$cur_timeunit = 'cur_' . $timeunit;
772
echo '<input type="hidden" id="' . $cur_timeunit . '" name="' . $cur_timeunit . '" value="' . $curr . '" />' . "\n";
777
<a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a>
778
<a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js button-cancel"><?php _e('Cancel'); ?></a>
784
* Print out <option> HTML elements for the page templates drop-down.
788
* @param string $default Optional. The template file name. Default empty.
790
function page_template_dropdown( $default = '' ) {
791
$templates = get_page_templates( get_post() );
793
foreach ( array_keys( $templates ) as $template ) {
794
$selected = selected( $default, $templates[ $template ], false );
795
echo "\n\t<option value='" . $templates[ $template ] . "' $selected>$template</option>";
800
* Print out <option> HTML elements for the page parents drop-down.
804
* @param int $default Optional. The default page ID to be pre-selected. Default 0.
805
* @param int $parent Optional. The parent page ID. Default 0.
806
* @param int $level Optional. Page depth level. Default 0.
808
* @return void|bool Boolean False if page has no children, otherwise print out html elements
810
function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
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) );
816
foreach ( $items as $item ) {
817
// A page cannot be its own parent.
818
if ( $post && $post->ID && $item->ID == $post->ID )
821
$pad = str_repeat( ' ', $level * 3 );
822
$selected = selected( $default, $item->ID, false );
824
echo "\n\t<option class='level-$level' value='$item->ID' $selected>$pad " . esc_html($item->post_title) . "</option>";
825
parent_dropdown( $default, $item->ID, $level +1 );
833
* Print out <option> html elements for role selectors
837
* @param string $selected slug for the role that should be already selected
839
function wp_dropdown_roles( $selected = false ) {
843
$editable_roles = array_reverse( get_editable_roles() );
845
foreach ( $editable_roles as $role => $details ) {
846
$name = translate_user_role($details['name'] );
847
if ( $selected == $role ) // preselect specified role
848
$p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
850
$r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
856
* Outputs the form used by the importers to accept the data to be imported
860
* @param string $action The action attribute for the form.
862
function wp_import_upload_form( $action ) {
865
* Filter the maximum allowed upload size for import files.
869
* @see wp_max_upload_size()
871
* @param int $max_upload_size Allowed upload size. Default 1 MB.
873
$bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
874
$size = size_format( $bytes );
875
$upload_dir = wp_upload_dir();
876
if ( ! empty( $upload_dir['error'] ) ) :
877
?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
878
<p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
881
<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' ) ); ?>">
883
<label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
884
<input type="file" id="upload" name="import" size="25" />
885
<input type="hidden" name="action" value="save" />
886
<input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
888
<?php submit_button( __('Upload file and import'), 'button' ); ?>
895
* Add a meta box to an edit form.
899
* @param string $id String for use in the 'id' attribute of tags.
900
* @param string $title Title of the meta box.
901
* @param callback $callback Function that fills the box with the desired content.
902
* The function should echo its output.
903
* @param string|WP_Screen $screen Optional. The screen on which to show the box (like a post
904
* type, 'link', or 'comment'). Default is the current screen.
905
* @param string $context Optional. The context within the screen where the boxes
906
* should display. Available contexts vary from screen to
907
* screen. Post edit screen contexts include 'normal', 'side',
908
* and 'advanced'. Comments screen contexts include 'normal'
909
* and 'side'. Menus meta boxes (accordion sections) all use
910
* the 'side' context. Global default is 'advanced'.
911
* @param string $priority Optional. The priority within the context where the boxes
912
* should show ('high', 'low'). Default 'default'.
913
* @param array $callback_args Optional. Data that should be set as the $args property
914
* of the box array (which is the second parameter passed
915
* to your callback). Default null.
917
function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {
918
global $wp_meta_boxes;
920
if ( empty( $screen ) )
921
$screen = get_current_screen();
922
elseif ( is_string( $screen ) )
923
$screen = convert_to_screen( $screen );
927
if ( !isset($wp_meta_boxes) )
928
$wp_meta_boxes = array();
929
if ( !isset($wp_meta_boxes[$page]) )
930
$wp_meta_boxes[$page] = array();
931
if ( !isset($wp_meta_boxes[$page][$context]) )
932
$wp_meta_boxes[$page][$context] = array();
934
foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
935
foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
936
if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
939
// If a core box was previously added or removed by a plugin, don't add.
940
if ( 'core' == $priority ) {
941
// If core box previously deleted, don't add
942
if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
946
* If box was added with default priority, give it core priority to
947
* maintain sort order.
949
if ( 'default' == $a_priority ) {
950
$wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
951
unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
955
// If no priority given and id already present, use existing priority.
956
if ( empty($priority) ) {
957
$priority = $a_priority;
959
* Else, if we're adding to the sorted priority, we don't know the title
960
* or callback. Grab them from the previously added context/priority.
962
} elseif ( 'sorted' == $priority ) {
963
$title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
964
$callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
965
$callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
967
// An id can be in only one priority and one context.
968
if ( $priority != $a_priority || $context != $a_context )
969
unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
973
if ( empty($priority) )
976
if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
977
$wp_meta_boxes[$page][$context][$priority] = array();
979
$wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
983
* Meta-Box template function
987
* @param string|object $screen Screen identifier
988
* @param string $context box context
989
* @param mixed $object gets passed to the box callback function as first parameter
990
* @return int number of meta_boxes
992
function do_meta_boxes( $screen, $context, $object ) {
993
global $wp_meta_boxes;
994
static $already_sorted = false;
996
if ( empty( $screen ) )
997
$screen = get_current_screen();
998
elseif ( is_string( $screen ) )
999
$screen = convert_to_screen( $screen );
1001
$page = $screen->id;
1003
$hidden = get_hidden_meta_boxes( $screen );
1005
printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context));
1009
// Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
1010
if ( !$already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) {
1011
foreach ( $sorted as $box_context => $ids ) {
1012
foreach ( explode(',', $ids ) as $id ) {
1013
if ( $id && 'dashboard_browser_nag' !== $id )
1014
add_meta_box( $id, null, null, $screen, $box_context, 'sorted' );
1018
$already_sorted = true;
1020
if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
1023
foreach ( array('high', 'sorted', 'core', 'default', 'low') as $priority ) {
1024
if ( isset($wp_meta_boxes[$page][$context][$priority]) ) {
1025
foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
1026
if ( false == $box || ! $box['title'] )
1029
$hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : '';
1030
echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n";
1031
if ( 'dashboard_browser_nag' != $box['id'] )
1032
echo '<div class="handlediv" title="' . esc_attr__('Click to toggle') . '"><br /></div>';
1033
echo "<h3 class='hndle'><span>{$box['title']}</span></h3>\n";
1034
echo '<div class="inside">' . "\n";
1035
call_user_func($box['callback'], $object, $box);
1050
* Remove a meta box from an edit form.
1054
* @param string $id String for use in the 'id' attribute of tags.
1055
* @param string|object $screen The screen on which to show the box (post, page, link).
1056
* @param string $context The context within the page where the boxes should show ('normal', 'advanced').
1058
function remove_meta_box($id, $screen, $context) {
1059
global $wp_meta_boxes;
1061
if ( empty( $screen ) )
1062
$screen = get_current_screen();
1063
elseif ( is_string( $screen ) )
1064
$screen = convert_to_screen( $screen );
1066
$page = $screen->id;
1068
if ( !isset($wp_meta_boxes) )
1069
$wp_meta_boxes = array();
1070
if ( !isset($wp_meta_boxes[$page]) )
1071
$wp_meta_boxes[$page] = array();
1072
if ( !isset($wp_meta_boxes[$page][$context]) )
1073
$wp_meta_boxes[$page][$context] = array();
1075
foreach ( array('high', 'core', 'default', 'low') as $priority )
1076
$wp_meta_boxes[$page][$context][$priority][$id] = false;
1080
* Meta Box Accordion Template Function
1082
* Largely made up of abstracted code from {@link do_meta_boxes()}, this
1083
* function serves to build meta boxes as list items for display as
1084
* a collapsible accordion.
1088
* @uses global $wp_meta_boxes Used to retrieve registered meta boxes.
1090
* @param string|object $screen The screen identifier.
1091
* @param string $context The meta box context.
1092
* @param mixed $object gets passed to the section callback function as first parameter.
1093
* @return int number of meta boxes as accordion sections.
1095
function do_accordion_sections( $screen, $context, $object ) {
1096
global $wp_meta_boxes;
1098
wp_enqueue_script( 'accordion' );
1100
if ( empty( $screen ) )
1101
$screen = get_current_screen();
1102
elseif ( is_string( $screen ) )
1103
$screen = convert_to_screen( $screen );
1105
$page = $screen->id;
1107
$hidden = get_hidden_meta_boxes( $screen );
1109
<div id="side-sortables" class="accordion-container">
1110
<ul class="outer-border">
1113
$first_open = false;
1115
if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[$page] ) || ! isset( $wp_meta_boxes[$page][$context] ) )
1118
foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
1119
if ( isset( $wp_meta_boxes[$page][$context][$priority] ) ) {
1120
foreach ( $wp_meta_boxes[$page][$context][$priority] as $box ) {
1121
if ( false == $box || ! $box['title'] )
1124
$hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
1127
if ( ! $first_open && empty( $hidden_class ) ) {
1129
$open_class = 'open';
1132
<li class="control-section accordion-section <?php echo $hidden_class; ?> <?php echo $open_class; ?> <?php echo esc_attr( $box['id'] ); ?>" id="<?php echo esc_attr( $box['id'] ); ?>">
1133
<h3 class="accordion-section-title hndle" tabindex="0">
1134
<?php echo esc_html( $box['title'] ); ?>
1135
<span class="screen-reader-text"><?php _e( 'Press return or enter to expand' ); ?></span>
1137
<div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
1138
<div class="inside">
1139
<?php call_user_func( $box['callback'], $object, $box ); ?>
1140
</div><!-- .inside -->
1141
</div><!-- .accordion-section-content -->
1142
</li><!-- .accordion-section -->
1149
</ul><!-- .outer-border -->
1150
</div><!-- .accordion-container -->
1156
* Add a new section to a settings page.
1158
* Part of the Settings API. Use this to define new settings sections for an admin page.
1159
* Show settings sections in your admin page callback function with do_settings_sections().
1160
* Add settings fields to your section with add_settings_field()
1162
* The $callback argument should be the name of a function that echoes out any
1163
* content you want to show at the top of the settings section before the actual
1164
* fields. It can output nothing if you want.
1168
* @global $wp_settings_sections Storage array of all settings sections added to admin pages
1170
* @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags.
1171
* @param string $title Formatted title of the section. Shown as the heading for the section.
1172
* @param string $callback Function that echos out any content at the top of the section (between heading and fields).
1173
* @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();
1175
function add_settings_section($id, $title, $callback, $page) {
1176
global $wp_settings_sections;
1178
if ( 'misc' == $page ) {
1179
_deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) );
1183
if ( 'privacy' == $page ) {
1184
_deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) );
1188
$wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
1192
* Add a new field to a section of a settings page
1194
* Part of the Settings API. Use this to define a settings field that will show
1195
* as part of a settings section inside a settings page. The fields are shown using
1196
* do_settings_fields() in do_settings-sections()
1198
* The $callback argument should be the name of a function that echoes out the
1199
* html input tags for this setting field. Use get_option() to retrieve existing
1204
* @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
1206
* @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags.
1207
* @param string $title Formatted title of the field. Shown as the label for the field during output.
1208
* @param string $callback Function that fills the field with the desired form inputs. The function should echo its output.
1209
* @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...).
1210
* @param string $section The slug-name of the section of the settings page in which to show the box (default, ...).
1211
* @param array $args Additional arguments
1213
function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
1214
global $wp_settings_fields;
1216
if ( 'misc' == $page ) {
1217
_deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
1221
if ( 'privacy' == $page ) {
1222
_deprecated_argument( __FUNCTION__, '3.5', __( 'The privacy options group has been removed. Use another settings group.' ) );
1226
$wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
1230
* Prints out all settings sections added to a particular settings page
1232
* Part of the Settings API. Use this in a settings page callback function
1233
* to output all the sections and fields that were added to that $page with
1234
* add_settings_section() and add_settings_field()
1236
* @global $wp_settings_sections Storage array of all settings sections added to admin pages
1237
* @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
1240
* @param string $page The slug name of the page whos settings sections you want to output
1242
function do_settings_sections( $page ) {
1243
global $wp_settings_sections, $wp_settings_fields;
1245
if ( ! isset( $wp_settings_sections[$page] ) )
1248
foreach ( (array) $wp_settings_sections[$page] as $section ) {
1249
if ( $section['title'] )
1250
echo "<h3>{$section['title']}</h3>\n";
1252
if ( $section['callback'] )
1253
call_user_func( $section['callback'], $section );
1255
if ( ! isset( $wp_settings_fields ) || !isset( $wp_settings_fields[$page] ) || !isset( $wp_settings_fields[$page][$section['id']] ) )
1257
echo '<table class="form-table">';
1258
do_settings_fields( $page, $section['id'] );
1264
* Print out the settings fields for a particular settings section
1266
* Part of the Settings API. Use this in a settings page to output
1267
* a specific section. Should normally be called by do_settings_sections()
1268
* rather than directly.
1270
* @global $wp_settings_fields Storage array of settings fields and their pages/sections
1274
* @param string $page Slug title of the admin page who's settings fields you want to show.
1275
* @param section $section Slug title of the settings section who's fields you want to show.
1277
function do_settings_fields($page, $section) {
1278
global $wp_settings_fields;
1280
if ( ! isset( $wp_settings_fields[$page][$section] ) )
1283
foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
1285
if ( !empty($field['args']['label_for']) )
1286
echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>';
1288
echo '<th scope="row">' . $field['title'] . '</th>';
1290
call_user_func($field['callback'], $field['args']);
1297
* Register a settings error to be displayed to the user
1299
* Part of the Settings API. Use this to show messages to users about settings validation
1300
* problems, missing settings or anything else.
1302
* Settings errors should be added inside the $sanitize_callback function defined in
1303
* register_setting() for a given setting to give feedback about the submission.
1305
* By default messages will show immediately after the submission that generated the error.
1306
* Additional calls to settings_errors() can be used to show errors even when the settings
1307
* page is first accessed.
1311
* @global array $wp_settings_errors Storage array of errors registered during this pageload
1313
* @param string $setting Slug title of the setting to which this error applies
1314
* @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
1315
* @param string $message The formatted message text to display to the user (will be shown inside styled <div> and <p>)
1316
* @param string $type The type of message it is, controls HTML class. Use 'error' or 'updated'.
1318
function add_settings_error( $setting, $code, $message, $type = 'error' ) {
1319
global $wp_settings_errors;
1321
$wp_settings_errors[] = array(
1322
'setting' => $setting,
1324
'message' => $message,
1330
* Fetch settings errors registered by add_settings_error()
1332
* Checks the $wp_settings_errors array for any errors declared during the current
1333
* pageload and returns them.
1335
* If changes were just submitted ($_GET['settings-updated']) and settings errors were saved
1336
* to the 'settings_errors' transient then those errors will be returned instead. This
1337
* is used to pass errors back across pageloads.
1339
* Use the $sanitize argument to manually re-sanitize the option before returning errors.
1340
* This is useful if you have errors or notices you want to show even when the user
1341
* hasn't submitted data (i.e. when they first load an options page, or in admin_notices action hook)
1345
* @global array $wp_settings_errors Storage array of errors registered during this pageload
1347
* @param string $setting Optional slug title of a specific setting who's errors you want.
1348
* @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
1349
* @return array Array of settings errors
1351
function get_settings_errors( $setting = '', $sanitize = false ) {
1352
global $wp_settings_errors;
1355
* If $sanitize is true, manually re-run the sanitization for this option
1356
* This allows the $sanitize_callback from register_setting() to run, adding
1357
* any settings errors you want to show by default.
1360
sanitize_option( $setting, get_option( $setting ) );
1362
// If settings were passed back from options.php then use them.
1363
if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && get_transient( 'settings_errors' ) ) {
1364
$wp_settings_errors = array_merge( (array) $wp_settings_errors, get_transient( 'settings_errors' ) );
1365
delete_transient( 'settings_errors' );
1368
// Check global in case errors have been added on this pageload.
1369
if ( ! count( $wp_settings_errors ) )
1372
// Filter the results to those of a specific setting if one was set.
1374
$setting_errors = array();
1375
foreach ( (array) $wp_settings_errors as $key => $details ) {
1376
if ( $setting == $details['setting'] )
1377
$setting_errors[] = $wp_settings_errors[$key];
1379
return $setting_errors;
1382
return $wp_settings_errors;
1386
* Display settings errors registered by add_settings_error()
1388
* Part of the Settings API. Outputs a <div> for each error retrieved by get_settings_errors().
1390
* This is called automatically after a settings page based on the Settings API is submitted.
1391
* Errors should be added during the validation callback function for a setting defined in register_setting()
1393
* The $sanitize option is passed into get_settings_errors() and will re-run the setting sanitization
1394
* on its current value.
1396
* The $hide_on_update option will cause errors to only show when the settings page is first loaded.
1397
* if the user has already saved new values it will be hidden to avoid repeating messages already
1398
* shown in the default error reporting after submission. This is useful to show general errors like missing
1399
* settings when the user arrives at the settings page.
1403
* @param string $setting Optional slug title of a specific setting who's errors you want.
1404
* @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
1405
* @param boolean $hide_on_update If set to true errors will not be shown if the settings page has already been submitted.
1407
function settings_errors( $setting = '', $sanitize = false, $hide_on_update = false ) {
1409
if ( $hide_on_update && ! empty( $_GET['settings-updated'] ) )
1412
$settings_errors = get_settings_errors( $setting, $sanitize );
1414
if ( empty( $settings_errors ) )
1418
foreach ( $settings_errors as $key => $details ) {
1419
$css_id = 'setting-error-' . $details['code'];
1420
$css_class = $details['type'] . ' settings-error';
1421
$output .= "<div id='$css_id' class='$css_class'> \n";
1422
$output .= "<p><strong>{$details['message']}</strong></p>";
1423
$output .= "</div> \n";
1429
* {@internal Missing Short Description}}
1433
* @param unknown_type $found_action
1435
function find_posts_div($found_action = '') {
1437
<div id="find-posts" class="find-box" style="display: none;">
1438
<div id="find-posts-head" class="find-box-head">
1439
<?php _e( 'Find Posts or Pages' ); ?>
1440
<div id="find-posts-close"></div>
1442
<div class="find-box-inside">
1443
<div class="find-box-search">
1444
<?php if ( $found_action ) { ?>
1445
<input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" />
1447
<input type="hidden" name="affected" id="affected" value="" />
1448
<?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
1449
<label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
1450
<input type="text" id="find-posts-input" name="ps" value="" />
1451
<span class="spinner"></span>
1452
<input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" />
1453
<div class="clear"></div>
1455
<div id="find-posts-response"></div>
1457
<div class="find-box-buttons">
1458
<?php submit_button( __( 'Select' ), 'button-primary alignright', 'find-posts-submit', false ); ?>
1459
<div class="clear"></div>
1466
* Display the post password.
1468
* The password is passed through {@link esc_attr()} to ensure that it
1469
* is safe for placing in an html attribute.
1474
function the_post_password() {
1476
if ( isset( $post->post_password ) )
1477
echo esc_attr( $post->post_password );
1481
* Get the post title.
1483
* The post title is fetched and if it is blank then a default string is
1488
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
1489
* @return string The post title if set.
1491
function _draft_or_post_title( $post = 0 ) {
1492
$title = get_the_title( $post );
1493
if ( empty( $title ) )
1494
$title = __( '(no title)' );
1499
* Display the search query.
1501
* A simple wrapper to display the "s" parameter in a GET URI. This function
1502
* should only be used when {@link the_search_query()} cannot.
1508
function _admin_search_query() {
1509
echo isset($_REQUEST['s']) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : '';
1513
* Generic Iframe header for use with Thickbox
1516
* @param string $title Title of the Iframe page.
1517
* @param bool $limit_styles Limit styles to colour-related styles only (unless others are enqueued).
1520
function iframe_header( $title = '', $limit_styles = false ) {
1521
show_admin_bar( false );
1522
global $hook_suffix, $current_user, $admin_body_class, $wp_locale;
1523
$admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
1525
$current_screen = get_current_screen();
1527
@header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
1528
_wp_admin_html_begin();
1530
<title><?php bloginfo('name') ?> › <?php echo $title ?> — <?php _e('WordPress'); ?></title>
1532
wp_enqueue_style( 'colors' );
1534
<script type="text/javascript">
1536
addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
1537
function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
1538
var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>',
1539
pagenow = '<?php echo $current_screen->id; ?>',
1540
typenow = '<?php echo $current_screen->post_type; ?>',
1541
adminpage = '<?php echo $admin_body_class; ?>',
1542
thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
1543
decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
1544
isRtl = <?php echo (int) is_rtl(); ?>;
1548
/** This action is documented in wp-admin/admin-header.php */
1549
do_action( 'admin_enqueue_scripts', $hook_suffix );
1551
/** This action is documented in wp-admin/admin-header.php */
1552
do_action( "admin_print_styles-$hook_suffix" );
1554
/** This action is documented in wp-admin/admin-header.php */
1555
do_action( 'admin_print_styles' );
1557
/** This action is documented in wp-admin/admin-header.php */
1558
do_action( "admin_print_scripts-$hook_suffix" );
1560
/** This action is documented in wp-admin/admin-header.php */
1561
do_action( 'admin_print_scripts' );
1563
/** This action is documented in wp-admin/admin-header.php */
1564
do_action( "admin_head-$hook_suffix" );
1566
/** This action is documented in wp-admin/admin-header.php */
1567
do_action( 'admin_head' );
1569
$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
1572
$admin_body_class .= ' rtl';
1576
<?php /** This filter is documented in wp-admin/admin-header.php */ ?>
1577
<body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="wp-admin wp-core-ui no-js iframe <?php echo apply_filters( 'admin_body_class', '' ) . ' ' . $admin_body_class; ?>">
1578
<script type="text/javascript">
1581
var c = document.body.className;
1582
c = c.replace(/no-js/, 'js');
1583
document.body.className = c;
1591
* Generic Iframe footer for use with Thickbox
1596
function iframe_footer() {
1598
* We're going to hide any footer output on iFrame pages,
1599
* but run the hooks anyway since they output Javascript
1600
* or other needed content.
1603
<div class="hidden">
1605
/** This action is documented in wp-admin/admin-footer.php */
1606
do_action( 'admin_footer', '' );
1608
/** This action is documented in wp-admin/admin-footer.php */
1609
do_action( 'admin_print_footer_scripts' );
1612
<script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script>
1618
function _post_states($post) {
1619
$post_states = array();
1620
if ( isset( $_REQUEST['post_status'] ) )
1621
$post_status = $_REQUEST['post_status'];
1625
if ( !empty($post->post_password) )
1626
$post_states['protected'] = __('Password protected');
1627
if ( 'private' == $post->post_status && 'private' != $post_status )
1628
$post_states['private'] = __('Private');
1629
if ( 'draft' == $post->post_status && 'draft' != $post_status )
1630
$post_states['draft'] = __('Draft');
1631
if ( 'pending' == $post->post_status && 'pending' != $post_status )
1632
/* translators: post state */
1633
$post_states['pending'] = _x('Pending', 'post state');
1634
if ( is_sticky($post->ID) )
1635
$post_states['sticky'] = __('Sticky');
1638
* Filter the default post display states used in the Posts list table.
1642
* @param array $post_states An array of post display states. Values include 'Password protected',
1643
* 'Private', 'Draft', 'Pending', and 'Sticky'.
1644
* @param int $post The post ID.
1646
$post_states = apply_filters( 'display_post_states', $post_states, $post );
1648
if ( ! empty($post_states) ) {
1649
$state_count = count($post_states);
1652
foreach ( $post_states as $state ) {
1654
( $i == $state_count ) ? $sep = '' : $sep = ', ';
1655
echo "<span class='post-state'>$state$sep</span>";
1661
function _media_states( $post ) {
1662
$media_states = array();
1663
$stylesheet = get_option('stylesheet');
1665
if ( current_theme_supports( 'custom-header') ) {
1666
$meta_header = get_post_meta($post->ID, '_wp_attachment_is_custom_header', true );
1667
if ( ! empty( $meta_header ) && $meta_header == $stylesheet )
1668
$media_states[] = __( 'Header Image' );
1671
if ( current_theme_supports( 'custom-background') ) {
1672
$meta_background = get_post_meta($post->ID, '_wp_attachment_is_custom_background', true );
1673
if ( ! empty( $meta_background ) && $meta_background == $stylesheet )
1674
$media_states[] = __( 'Background Image' );
1678
* Filter the default media display states for items in the Media list table.
1682
* @param array $media_states An array of media states. Default 'Header Image',
1683
* 'Background Image'.
1685
$media_states = apply_filters( 'display_media_states', $media_states );
1687
if ( ! empty( $media_states ) ) {
1688
$state_count = count( $media_states );
1691
foreach ( $media_states as $state ) {
1693
( $i == $state_count ) ? $sep = '' : $sep = ', ';
1694
echo "<span class='post-state'>$state$sep</span>";
1700
* Test support for compressing JavaScript from PHP
1702
* Outputs JavaScript that tests if compression from PHP works as expected
1703
* and sets an option with the result. Has no effect when the current user
1704
* is not an administrator. To run the test again the option 'can_compress_scripts'
1705
* has to be deleted.
1709
function compression_test() {
1711
<script type="text/javascript">
1713
var testCompression = {
1714
get : function(test) {
1716
if ( window.XMLHttpRequest ) {
1717
x = new XMLHttpRequest();
1719
try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
1723
x.onreadystatechange = function() {
1725
if ( x.readyState == 4 ) {
1726
r = x.responseText.substr(0, 18);
1727
h = x.getResponseHeader('Content-Encoding');
1728
testCompression.check(r, h, test);
1732
x.open('GET', ajaxurl + '?action=wp-compression-test&test='+test+'&'+(new Date()).getTime(), true);
1737
check : function(r, h, test) {
1738
if ( ! r && ! test )
1742
if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) )
1751
if ( '"wpCompressionTest' == r )
1758
testCompression.check();
1765
* Echoes a submit button, with provided text and appropriate class(es).
1769
* @see get_submit_button()
1771
* @param string $text The text of the button (defaults to 'Save Changes')
1772
* @param string $type Optional. The type and CSS class(es) of the button. Core values
1773
* include 'primary', 'secondary', 'delete'. Default 'primary'
1774
* @param string $name The HTML name of the submit button. Defaults to "submit". If no
1775
* id attribute is given in $other_attributes below, $name will be
1776
* used as the button's id.
1777
* @param bool $wrap True if the output button should be wrapped in a paragraph tag,
1778
* false otherwise. Defaults to true
1779
* @param array|string $other_attributes Other attributes that should be output with the button, mapping
1780
* attributes to their values, such as setting tabindex to 1, etc.
1781
* These key/value attribute pairs will be output as attribute="value",
1782
* where attribute is the key. Other attributes can also be provided
1783
* as a string such as 'tabindex="1"', though the array format is
1784
* preferred. Default null.
1786
function submit_button( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null ) {
1787
echo get_submit_button( $text, $type, $name, $wrap, $other_attributes );
1791
* Returns a submit button, with provided text and appropriate class
1795
* @param string $text The text of the button (defaults to 'Save Changes')
1796
* @param string $type The type of button. One of: primary, secondary, delete
1797
* @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute
1798
* is given in $other_attributes below, $name will be used as the button's id.
1799
* @param bool $wrap True if the output button should be wrapped in a paragraph tag,
1800
* false otherwise. Defaults to true
1801
* @param array|string $other_attributes Other attributes that should be output with the button,
1802
* mapping attributes to their values, such as array( 'tabindex' => '1' ).
1803
* These attributes will be output as attribute="value", such as tabindex="1".
1804
* Defaults to no other attributes. Other attributes can also be provided as a
1805
* string such as 'tabindex="1"', though the array format is typically cleaner.
1807
function get_submit_button( $text = null, $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = null ) {
1808
if ( ! is_array( $type ) )
1809
$type = explode( ' ', $type );
1811
$button_shorthand = array( 'primary', 'small', 'large' );
1812
$classes = array( 'button' );
1813
foreach ( $type as $t ) {
1814
if ( 'secondary' === $t || 'button-secondary' === $t )
1816
$classes[] = in_array( $t, $button_shorthand ) ? 'button-' . $t : $t;
1818
$class = implode( ' ', array_unique( $classes ) );
1820
if ( 'delete' === $type )
1821
$class = 'button-secondary delete';
1823
$text = $text ? $text : __( 'Save Changes' );
1825
// Default the id attribute to $name unless an id was specifically provided in $other_attributes
1827
if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) {
1828
$id = $other_attributes['id'];
1829
unset( $other_attributes['id'] );
1833
if ( is_array( $other_attributes ) ) {
1834
foreach ( $other_attributes as $attribute => $value ) {
1835
$attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
1837
} else if ( !empty( $other_attributes ) ) { // Attributes provided as a string
1838
$attributes = $other_attributes;
1841
$button = '<input type="submit" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" class="' . esc_attr( $class );
1842
$button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />';
1845
$button = '<p class="submit">' . $button . '</p>';
1851
function _wp_admin_html_begin() {
1854
$admin_html_class = ( is_admin_bar_showing() ) ? 'wp-toolbar' : '';
1857
@header('X-UA-Compatible: IE=edge');
1860
* Fires inside the HTML tag in the admin header.
1867
<html xmlns="http://www.w3.org/1999/xhtml" class="ie8 <?php echo $admin_html_class; ?>" <?php do_action( 'admin_xml_ns' ); ?> <?php language_attributes(); ?>>
1869
<!--[if !(IE 8) ]><!-->
1870
<?php /** This action is documented in wp-admin/includes/template.php */ ?>
1871
<html xmlns="http://www.w3.org/1999/xhtml" class="<?php echo $admin_html_class; ?>" <?php do_action( 'admin_xml_ns' ); ?> <?php language_attributes(); ?>>
1874
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
1878
final class WP_Internal_Pointers {
1880
* Initializes the new feature pointers.
1884
* All pointers can be disabled using the following:
1885
* remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
1887
* Individual pointers (e.g. wp390_widgets) can be disabled using the following:
1888
* remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp390_widgets' ) );
1890
public static function enqueue_scripts( $hook_suffix ) {
1892
* Register feature pointers
1893
* Format: array( hook_suffix => pointer_id )
1896
$registered_pointers = array(
1897
'post-new.php' => 'wp350_media',
1898
'post.php' => array( 'wp350_media', 'wp360_revisions' ),
1899
'edit.php' => 'wp360_locks',
1900
'widgets.php' => 'wp390_widgets',
1901
'themes.php' => 'wp390_widgets',
1904
// Check if screen related pointer is registered
1905
if ( empty( $registered_pointers[ $hook_suffix ] ) )
1908
$pointers = (array) $registered_pointers[ $hook_suffix ];
1910
$caps_required = array(
1911
'wp350_media' => array( 'upload_files' ),
1912
'wp390_widgets' => array( 'edit_theme_options' ),
1915
// Get dismissed pointers
1916
$dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
1918
$got_pointers = false;
1919
foreach ( array_diff( $pointers, $dismissed ) as $pointer ) {
1920
if ( isset( $caps_required[ $pointer ] ) ) {
1921
foreach ( $caps_required[ $pointer ] as $cap ) {
1922
if ( ! current_user_can( $cap ) )
1927
// Bind pointer print function
1928
add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) );
1929
$got_pointers = true;
1932
if ( ! $got_pointers )
1935
// Add pointers script and style to queue
1936
wp_enqueue_style( 'wp-pointer' );
1937
wp_enqueue_script( 'wp-pointer' );
1941
* Print the pointer javascript data.
1945
* @param string $pointer_id The pointer ID.
1946
* @param string $selector The HTML elements, on which the pointer should be attached.
1947
* @param array $args Arguments to be passed to the pointer JS (see wp-pointer.js).
1949
private static function print_js( $pointer_id, $selector, $args ) {
1950
if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) )
1954
<script type="text/javascript">
1957
var options = <?php echo json_encode( $args ); ?>, setup;
1962
options = $.extend( options, {
1965
pointer: '<?php echo $pointer_id; ?>',
1966
action: 'dismiss-wp-pointer'
1971
setup = function() {
1972
$('<?php echo $selector; ?>').first().pointer( options ).pointer('open');
1975
if ( options.position && options.position.defer_loading )
1976
$(window).bind( 'load.wp-pointers', setup );
1978
$(document).ready( setup );
1986
public static function pointer_wp330_toolbar() {}
1987
public static function pointer_wp330_media_uploader() {}
1988
public static function pointer_wp330_saving_widgets() {}
1989
public static function pointer_wp340_customize_current_theme_link() {}
1990
public static function pointer_wp340_choose_image_from_library() {}
1992
public static function pointer_wp350_media() {
1993
$content = '<h3>' . __( 'New Media Manager' ) . '</h3>';
1994
$content .= '<p>' . __( 'Uploading files and creating image galleries has a whole new look. Check it out!' ) . '</p>';
1996
self::print_js( 'wp350_media', '.insert-media', array(
1997
'content' => $content,
1998
'position' => array( 'edge' => is_rtl() ? 'right' : 'left', 'align' => 'center' ),
2002
public static function pointer_wp360_revisions() {
2003
$content = '<h3>' . __( 'Compare Revisions' ) . '</h3>';
2004
$content .= '<p>' . __( 'View, compare, and restore other versions of this content on the improved revisions screen.' ) . '</p>';
2006
self::print_js( 'wp360_revisions', '.misc-pub-section.misc-pub-revisions', array(
2007
'content' => $content,
2008
'position' => array( 'edge' => is_rtl() ? 'left' : 'right', 'align' => 'center' ),
2012
public static function pointer_wp360_locks() {
2013
if ( ! is_multi_author() ) {
2017
$content = '<h3>' . __( 'Edit Lock' ) . '</h3>';
2018
$content .= '<p>' . __( 'Someone else is editing this. No need to refresh; the lock will disappear when they’re done.' ) . '</p>';
2020
self::print_js( 'wp360_locks', 'tr.wp-locked .locked-indicator', array(
2021
'content' => $content,
2022
'position' => array( 'edge' => 'left', 'align' => 'left' ),
2026
public static function pointer_wp390_widgets() {
2027
if ( ! current_theme_supports( 'widgets' ) ) {
2031
$content = '<h3>' . __( 'New Feature: Live Widget Previews' ) . '</h3>';
2032
$content .= '<p>' . __( 'Add, edit, and play around with your widgets from the theme customizer.' ) . ' ' . __( 'Preview your changes in real-time and only save them when you’re ready.' ) . '</p>';
2034
if ( 'themes' === get_current_screen()->id ) {
2035
$selector = '.theme.active .customize';
2036
$position = array( 'edge' => is_rtl() ? 'right' : 'left', 'align' => 'center' );
2038
$selector = 'a[href="customize.php"]';
2040
$position = array( 'edge' => 'right', 'align' => 'center', 'my' => 'right-5px' );
2042
$position = array( 'edge' => 'left', 'align' => 'center', 'my' => 'left-5px' );
2046
self::print_js( 'wp390_widgets', $selector, array(
2047
'content' => $content,
2048
'position' => $position,
2053
* Prevents new users from seeing existing 'new feature' pointers.
2057
public static function dismiss_pointers_for_new_users( $user_id ) {
2058
add_user_meta( $user_id, 'dismissed_wp_pointers', 'wp350_media,wp360_revisions,wp360_locks,wp390_widgets' );
2062
add_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
2063
add_action( 'user_register', array( 'WP_Internal_Pointers', 'dismiss_pointers_for_new_users' ) );
2066
* Convert a screen string to a screen object
2070
* @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen.
2071
* @return WP_Screen Screen object.
2073
function convert_to_screen( $hook_name ) {
2074
if ( ! class_exists( 'WP_Screen' ) ) {
2075
_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' );
2076
return (object) array( 'id' => '_invalid', 'base' => '_are_belong_to_us' );
2079
return WP_Screen::get( $hook_name );
2083
* Output the HTML for restoring the post data from DOM storage
2088
function _local_storage_notice() {
2090
<div id="local-storage-notice" class="hidden">
2091
<p class="local-restore">
2092
<?php _e('The backup of this post in your browser is different from the version below.'); ?>
2093
<a class="restore-backup" href="#"><?php _e('Restore the backup.'); ?></a>
2095
<p class="undo-restore hidden">
2096
<?php _e('Post restored successfully.'); ?>
2097
<a class="undo-restore-backup" href="#"><?php _e('Undo.'); ?></a>
2104
* Output a HTML element with a star rating for a given rating.
2106
* Outputs a HTML element with the star rating exposed on a 0..5 scale in
2107
* half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the
2108
* number of ratings may also be displayed by passing the $number parameter.
2111
* @param array $args {
2112
* Optional. Array of star ratings arguments.
2114
* @type int $rating The rating to display, expressed in either a 0.5 rating increment,
2115
* or percentage. Default 0.
2116
* @type string $type Format that the $rating is in. Valid values are 'rating' (default),
2117
* or, 'percent'. Default 'rating'.
2118
* @type int $number The number of ratings that makes up this rating. Default 0.
2121
function wp_star_rating( $args = array() ) {
2127
$r = wp_parse_args( $args, $defaults );
2129
// Non-english decimal places when the $rating is coming from a string
2130
$rating = str_replace( ',', '.', $r['rating'] );
2132
// Convert Percentage to star rating, 0..5 in .5 increments
2133
if ( 'percent' == $r['type'] ) {
2134
$rating = round( $rating / 10, 0 ) / 2;
2137
// Calculate the number of each type of star needed
2138
$full_stars = floor( $rating );
2139
$half_stars = ceil( $rating - $full_stars );
2140
$empty_stars = 5 - $full_stars - $half_stars;
2142
if ( $r['number'] ) {
2143
/* translators: 1: The rating, 2: The number of ratings */
2144
$format = _n( '%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $r['number'] );
2145
$title = sprintf( $format, number_format_i18n( $rating, 1 ), number_format_i18n( $r['number'] ) );
2147
/* translators: 1: The rating */
2148
$title = sprintf( __( '%s rating' ), number_format_i18n( $rating, 1 ) );
2151
echo '<div class="star-rating" title="' . esc_attr( $title ) . '">';
2152
echo '<span class="screen-reader-text">' . $title . '</span>';
2153
echo str_repeat( '<div class="star star-full"></div>', $full_stars );
2154
echo str_repeat( '<div class="star star-half"></div>', $half_stars );
2155
echo str_repeat( '<div class="star star-empty"></div>', $empty_stars);