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 var $tree_type = 'category';
25 var $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 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 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 function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
74 if ( empty($taxonomy) )
75 $taxonomy = 'category';
77 if ( $taxonomy == 'category' )
78 $name = 'post_category';
80 $name = 'tax_input['.$taxonomy.']';
82 $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
84 /** This filter is documented in wp-includes/category-template.php */
85 $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . checked( in_array( $category->term_id, $selected_cats ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>';
89 * Ends the element output, if needed.
91 * @see Walker::end_el()
95 * @param string $output Passed by reference. Used to append additional content.
96 * @param object $category The current term object.
97 * @param int $depth Depth of the term in reference to parents. Default 0.
98 * @param array $args An array of arguments. @see wp_terms_checklist()
100 function end_el( &$output, $category, $depth = 0, $args = array() ) {
101 $output .= "</li>\n";
106 * Output an unordered list of checkbox <input> elements labelled
107 * with category names.
109 * @see wp_terms_checklist()
112 * @param int $post_id Mark categories associated with this post as checked. $selected_cats must not be an array.
113 * @param int $descendants_and_self ID of the category to output along with its descendents.
114 * @param bool|array $selected_cats List of categories to mark as checked.
115 * @param bool|array $popular_cats Override the list of categories that receive the "popular-category" class.
116 * @param object $walker Walker object to use to build the output.
117 * @param bool $checked_ontop Move checked items out of the hierarchy and to the top of the list.
119 function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) {
120 wp_terms_checklist( $post_id, array(
121 'taxonomy' => 'category',
122 'descendants_and_self' => $descendants_and_self,
123 'selected_cats' => $selected_cats,
124 'popular_cats' => $popular_cats,
126 'checked_ontop' => $checked_ontop
131 * Output an unordered list of checkbox <input> elements labelled
132 * with term names. Taxonomy independent version of wp_category_checklist().
136 * @param int $post_id
139 function wp_terms_checklist($post_id = 0, $args = array()) {
141 'descendants_and_self' => 0,
142 'selected_cats' => false,
143 'popular_cats' => false,
145 'taxonomy' => 'category',
146 'checked_ontop' => true
150 * Filter the taxonomy terms checklist arguments.
154 * @see wp_terms_checklist()
156 * @param array $args An array of arguments.
157 * @param int $post_id The post ID.
159 $args = apply_filters( 'wp_terms_checklist_args', $args, $post_id );
161 extract( wp_parse_args($args, $defaults), EXTR_SKIP );
163 if ( empty($walker) || !is_a($walker, 'Walker') )
164 $walker = new Walker_Category_Checklist;
166 $descendants_and_self = (int) $descendants_and_self;
168 $args = array('taxonomy' => $taxonomy);
170 $tax = get_taxonomy($taxonomy);
171 $args['disabled'] = !current_user_can($tax->cap->assign_terms);
173 if ( is_array( $selected_cats ) )
174 $args['selected_cats'] = $selected_cats;
176 $args['selected_cats'] = wp_get_object_terms($post_id, $taxonomy, array_merge($args, array('fields' => 'ids')));
178 $args['selected_cats'] = array();
180 if ( is_array( $popular_cats ) )
181 $args['popular_cats'] = $popular_cats;
183 $args['popular_cats'] = get_terms( $taxonomy, array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
185 if ( $descendants_and_self ) {
186 $categories = (array) get_terms($taxonomy, array( 'child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0 ) );
187 $self = get_term( $descendants_and_self, $taxonomy );
188 array_unshift( $categories, $self );
190 $categories = (array) get_terms($taxonomy, array('get' => 'all'));
193 if ( $checked_ontop ) {
194 // 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)
195 $checked_categories = array();
196 $keys = array_keys( $categories );
198 foreach( $keys as $k ) {
199 if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) {
200 $checked_categories[] = $categories[$k];
201 unset( $categories[$k] );
205 // Put checked cats on top
206 echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args));
208 // Then the rest of them
209 echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args));
213 * Retrieve a list of the most popular terms from the specified taxonomy.
215 * If the $echo argument is true then the elements for a list of checkbox
216 * <input> elements labelled with the names of the selected terms is output.
217 * If the $post_ID global isn't empty then the terms associated with that
218 * post will be marked as checked.
222 * @param string $taxonomy Taxonomy to retrieve terms from.
223 * @param int $default Unused.
224 * @param int $number Number of terms to retrieve. Defaults to 10.
225 * @param bool $echo Optionally output the list as well. Defaults to true.
226 * @return array List of popular term IDs.
228 function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
231 if ( $post && $post->ID )
232 $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields'=>'ids'));
234 $checked_terms = array();
236 $terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
238 $tax = get_taxonomy($taxonomy);
240 $popular_ids = array();
241 foreach ( (array) $terms as $term ) {
242 $popular_ids[] = $term->term_id;
243 if ( !$echo ) // hack for AJAX use
245 $id = "popular-$taxonomy-$term->term_id";
246 $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : '';
249 <li id="<?php echo $id; ?>" class="popular-category">
250 <label class="selectit">
251 <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 ) ); ?> />
253 /** This filter is documented in wp-includes/category-template.php */
254 echo esc_html( apply_filters( 'the_category', $term->name ) );
265 * {@internal Missing Short Description}}
269 * @param unknown_type $link_id
271 function wp_link_category_checklist( $link_id = 0 ) {
275 $checked_categories = wp_get_link_cats( $link_id );
276 // No selected categories, strange
277 if ( ! count( $checked_categories ) )
278 $checked_categories[] = $default;
280 $checked_categories[] = $default;
283 $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) );
285 if ( empty( $categories ) )
288 foreach ( $categories as $category ) {
289 $cat_id = $category->term_id;
291 /** This filter is documented in wp-includes/category-template.php */
292 $name = esc_html( apply_filters( 'the_category', $category->name ) );
293 $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : '';
294 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>";
298 // adds hidden fields with the data for use in the inline editor for posts and pages
300 * {@internal Missing Short Description}}
304 * @param unknown_type $post
306 function get_inline_data($post) {
307 $post_type_object = get_post_type_object($post->post_type);
308 if ( ! current_user_can( 'edit_post', $post->ID ) )
311 $title = esc_textarea( trim( $post->post_title ) );
313 /** This filter is documented in wp-admin/edit-tag-form.php */
315 <div class="hidden" id="inline_' . $post->ID . '">
316 <div class="post_title">' . $title . '</div>
317 <div class="post_name">' . apply_filters( 'editable_slug', $post->post_name ) . '</div>
318 <div class="post_author">' . $post->post_author . '</div>
319 <div class="comment_status">' . esc_html( $post->comment_status ) . '</div>
320 <div class="ping_status">' . esc_html( $post->ping_status ) . '</div>
321 <div class="_status">' . esc_html( $post->post_status ) . '</div>
322 <div class="jj">' . mysql2date( 'd', $post->post_date, false ) . '</div>
323 <div class="mm">' . mysql2date( 'm', $post->post_date, false ) . '</div>
324 <div class="aa">' . mysql2date( 'Y', $post->post_date, false ) . '</div>
325 <div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div>
326 <div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div>
327 <div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div>
328 <div class="post_password">' . esc_html( $post->post_password ) . '</div>';
330 if ( $post_type_object->hierarchical )
331 echo '<div class="post_parent">' . $post->post_parent . '</div>';
333 if ( $post->post_type == 'page' )
334 echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>';
336 if ( post_type_supports( $post->post_type, 'page-attributes' ) )
337 echo '<div class="menu_order">' . $post->menu_order . '</div>';
339 $taxonomy_names = get_object_taxonomies( $post->post_type );
340 foreach ( $taxonomy_names as $taxonomy_name) {
341 $taxonomy = get_taxonomy( $taxonomy_name );
343 if ( $taxonomy->hierarchical && $taxonomy->show_ui ) {
344 echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">'
345 . implode( ',', wp_get_object_terms( $post->ID, $taxonomy_name, array( 'fields' => 'ids' ) ) ) . '</div>';
346 } elseif ( $taxonomy->show_ui ) {
347 echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">'
348 . esc_html( str_replace( ',', ', ', get_terms_to_edit( $post->ID, $taxonomy_name ) ) ) . '</div>';
352 if ( !$post_type_object->hierarchical )
353 echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
355 if ( post_type_supports( $post->post_type, 'post-formats' ) )
356 echo '<div class="post_format">' . esc_html( get_post_format( $post->ID ) ) . '</div>';
362 * {@internal Missing Short Description}}
366 * @param unknown_type $position
367 * @param unknown_type $checkbox
368 * @param unknown_type $mode
370 function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single', $table_row = true) {
373 * Filter the in-line comment reply-to form output in the Comments
376 * Returning a non-empty value here will short-circuit display
377 * of the in-line comment-reply form in the Comments list table,
378 * echoing the returned value instead.
382 * @see wp_comment_reply()
384 * @param string $content The reply-to form content.
385 * @param array $args An array of default args.
387 $content = apply_filters( 'wp_comment_reply', '', array( 'position' => $position, 'checkbox' => $checkbox, 'mode' => $mode ) );
389 if ( ! empty($content) ) {
394 if ( $mode == 'single' ) {
395 $wp_list_table = _get_list_table('WP_Post_Comments_List_Table');
397 $wp_list_table = _get_list_table('WP_Comments_List_Table');
401 <form method="get" action="">
402 <?php if ( $table_row ) : ?>
403 <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">
405 <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;">
407 <div id="replyhead" style="display:none;"><h5><?php _e( 'Reply to Comment' ); ?></h5></div>
408 <div id="addhead" style="display:none;"><h5><?php _e('Add new Comment'); ?></h5></div>
409 <div id="edithead" style="display:none;">
411 <label for="author"><?php _e('Name') ?></label>
412 <input type="text" name="newcomment_author" size="50" value="" id="author" />
416 <label for="author-email"><?php _e('E-mail') ?></label>
417 <input type="text" name="newcomment_author_email" size="50" value="" id="author-email" />
421 <label for="author-url"><?php _e('URL') ?></label>
422 <input type="text" id="author-url" name="newcomment_author_url" size="103" value="" />
424 <div style="clear:both;"></div>
427 <div id="replycontainer">
429 $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' );
430 wp_editor( '', 'replycontent', array( 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings ) );
434 <p id="replysubmit" class="submit">
435 <a href="#comments-form" class="save button-primary alignright">
436 <span id="addbtn" style="display:none;"><?php _e('Add Comment'); ?></span>
437 <span id="savebtn" style="display:none;"><?php _e('Update Comment'); ?></span>
438 <span id="replybtn" style="display:none;"><?php _e('Submit Reply'); ?></span></a>
439 <a href="#comments-form" class="cancel button-secondary alignleft"><?php _e('Cancel'); ?></a>
440 <span class="waiting spinner"></span>
441 <span class="error" style="display:none;"></span>
445 <input type="hidden" name="user_ID" id="user_ID" value="<?php echo get_current_user_id(); ?>" />
446 <input type="hidden" name="action" id="action" value="" />
447 <input type="hidden" name="comment_ID" id="comment_ID" value="" />
448 <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" />
449 <input type="hidden" name="status" id="status" value="" />
450 <input type="hidden" name="position" id="position" value="<?php echo $position; ?>" />
451 <input type="hidden" name="checkbox" id="checkbox" value="<?php echo $checkbox ? 1 : 0; ?>" />
452 <input type="hidden" name="mode" id="mode" value="<?php echo esc_attr($mode); ?>" />
454 wp_nonce_field( 'replyto-comment', '_ajax_nonce-replyto-comment', false );
455 if ( current_user_can( 'unfiltered_html' ) )
456 wp_nonce_field( 'unfiltered-html-comment', '_wp_unfiltered_html_comment', false );
458 <?php if ( $table_row ) : ?>
459 </td></tr></tbody></table>
468 * Output 'undo move to trash' text for comments
472 function wp_comment_trashnotice() {
474 <div class="hidden" id="trash-undo-holder">
475 <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>
477 <div class="hidden" id="spam-undo-holder">
478 <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>
484 * {@internal Missing Short Description}}
488 * @param unknown_type $meta
490 function list_meta( $meta ) {
494 <table id="list-table" style="display: none;">
497 <th class="left">' . _x( 'Name', 'meta name' ) . '</th>
498 <th>' . __( 'Value' ) . '</th>
501 <tbody id="the-list" data-wp-lists="list:meta">
504 </table>'; //TBODY needed for list-manipulation JS
509 <table id="list-table">
512 <th class="left"><?php _ex( 'Name', 'meta name' ) ?></th>
513 <th><?php _e( 'Value' ) ?></th>
516 <tbody id='the-list' data-wp-lists='list:meta'>
518 foreach ( $meta as $entry )
519 echo _list_meta_row( $entry, $count );
527 * {@internal Missing Short Description}}
531 * @param unknown_type $entry
532 * @param unknown_type $count
535 function _list_meta_row( $entry, &$count ) {
536 static $update_nonce = false;
538 if ( is_protected_meta( $entry['meta_key'], 'post' ) )
541 if ( !$update_nonce )
542 $update_nonce = wp_create_nonce( 'add-meta' );
547 $style = 'alternate';
551 if ( is_serialized( $entry['meta_value'] ) ) {
552 if ( is_serialized_string( $entry['meta_value'] ) ) {
553 // this is a serialized string, so we should display it
554 $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
556 // this is a serialized array/object so we should NOT display it
562 $entry['meta_key'] = esc_attr($entry['meta_key']);
563 $entry['meta_value'] = esc_textarea( $entry['meta_value'] ); // using a <textarea />
564 $entry['meta_id'] = (int) $entry['meta_id'];
566 $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
568 $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
569 $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']}' />";
571 $r .= "\n\t\t<div class='submit'>";
572 $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" ) );
574 $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" ) );
576 $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
579 $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>";
584 * Prints the form in the Custom Fields meta box.
588 * @param WP_Post $post Optional. The post being edited.
590 function meta_form( $post = null ) {
592 $post = get_post( $post );
595 * Filter the number of custom fields to retrieve for the drop-down
596 * in the Custom Fields meta box.
600 * @param int $limit Number of custom fields to retrieve. Default 30.
602 $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
603 $keys = $wpdb->get_col( "
607 HAVING meta_key NOT LIKE '\_%'
611 natcasesort( $keys );
612 $meta_key_input_id = 'metakeyselect';
614 $meta_key_input_id = 'metakeyinput';
617 <p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p>
621 <th class="left"><label for="<?php echo $meta_key_input_id; ?>"><?php _ex( 'Name', 'meta name' ) ?></label></th>
622 <th><label for="metavalue"><?php _e( 'Value' ) ?></label></th>
628 <td id="newmetaleft" class="left">
629 <?php if ( $keys ) { ?>
630 <select id="metakeyselect" name="metakeyselect">
631 <option value="#NONE#"><?php _e( '— Select —' ); ?></option>
634 foreach ( $keys as $key ) {
635 if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $post->ID, $key ) )
637 echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>";
641 <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" value="" />
642 <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
643 <span id="enternew"><?php _e('Enter new'); ?></span>
644 <span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a>
646 <input type="text" id="metakeyinput" name="metakeyinput" value="" />
649 <td><textarea id="metavalue" name="metavalue" rows="2" cols="25"></textarea></td>
654 <?php submit_button( __( 'Add Custom Field' ), 'secondary', 'addmeta', false, array( 'id' => 'newmeta-submit', 'data-wp-lists' => 'add:the-list:newmeta' ) ); ?>
656 <?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?>
665 * Print out HTML form date elements for editing post or comment publish date.
669 * @param int|bool $edit Accepts 1|true for editing the date, 0|false for adding the date.
670 * @param int|bool $for_post Accepts 1|true for applying the date to a post, 0|false for a comment.
671 * @param int|bool $tab_index The tabindex attribute to add. Default 0.
672 * @param int|bool $multi Optional. Whether the additional fields and buttons should be added.
675 function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
676 global $wp_locale, $comment;
680 $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );
682 $tab_index_attribute = '';
683 if ( (int) $tab_index > 0 )
684 $tab_index_attribute = " tabindex=\"$tab_index\"";
686 // 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 />';
688 $time_adj = current_time('timestamp');
689 $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
690 $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
691 $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
692 $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
693 $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
694 $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
695 $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
697 $cur_jj = gmdate( 'd', $time_adj );
698 $cur_mm = gmdate( 'm', $time_adj );
699 $cur_aa = gmdate( 'Y', $time_adj );
700 $cur_hh = gmdate( 'H', $time_adj );
701 $cur_mn = gmdate( 'i', $time_adj );
703 $month = "<select " . ( $multi ? '' : 'id="mm" ' ) . "name=\"mm\"$tab_index_attribute>\n";
704 for ( $i = 1; $i < 13; $i = $i +1 ) {
705 $monthnum = zeroise($i, 2);
706 $month .= "\t\t\t" . '<option value="' . $monthnum . '" ' . selected( $monthnum, $mm, false ) . '>';
707 /* translators: 1: month number (01, 02, etc.), 2: month abbreviation */
708 $month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) ) . "</option>\n";
710 $month .= '</select>';
712 $day = '<input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
713 $year = '<input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" />';
714 $hour = '<input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
715 $minute = '<input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
717 echo '<div class="timestamp-wrap">';
718 /* translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */
719 printf( __( '%1$s %2$s, %3$s @ %4$s : %5$s' ), $month, $day, $year, $hour, $minute );
721 echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
723 if ( $multi ) return;
726 foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit ) {
727 echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $$timeunit . '" />' . "\n";
728 $cur_timeunit = 'cur_' . $timeunit;
729 echo '<input type="hidden" id="' . $cur_timeunit . '" name="' . $cur_timeunit . '" value="' . $$cur_timeunit . '" />' . "\n";
734 <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a>
735 <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js button-cancel"><?php _e('Cancel'); ?></a>
741 * Print out <option> HTML elements for the page templates drop-down.
745 * @param string $default Optional. The template file name. Default empty.
747 function page_template_dropdown( $default = '' ) {
748 $templates = get_page_templates( get_post() );
750 foreach ( array_keys( $templates ) as $template ) {
751 $selected = selected( $default, $templates[ $template ], false );
752 echo "\n\t<option value='" . $templates[ $template ] . "' $selected>$template</option>";
757 * Print out <option> HTML elements for the page parents drop-down.
761 * @param int $default Optional. The default page ID to be pre-selected. Default 0.
762 * @param int $parent Optional. The parent page ID. Default 0.
763 * @param int $level Optional. Page depth level. Default 0.
765 * @return void|bool Boolean False if page has no children, otherwise print out html elements
767 function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
770 $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) );
773 foreach ( $items as $item ) {
774 // A page cannot be its own parent.
775 if ( $post && $post->ID && $item->ID == $post->ID )
778 $pad = str_repeat( ' ', $level * 3 );
779 $selected = selected( $default, $item->ID, false );
781 echo "\n\t<option class='level-$level' value='$item->ID' $selected>$pad " . esc_html($item->post_title) . "</option>";
782 parent_dropdown( $default, $item->ID, $level +1 );
790 * Print out <option> html elements for role selectors
794 * @param string $selected slug for the role that should be already selected
796 function wp_dropdown_roles( $selected = false ) {
800 $editable_roles = array_reverse( get_editable_roles() );
802 foreach ( $editable_roles as $role => $details ) {
803 $name = translate_user_role($details['name'] );
804 if ( $selected == $role ) // preselect specified role
805 $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
807 $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
813 * Outputs the form used by the importers to accept the data to be imported
817 * @param string $action The action attribute for the form.
819 function wp_import_upload_form( $action ) {
822 * Filter the maximum allowed upload size for import files.
826 * @see wp_max_upload_size()
828 * @param int $max_upload_size Allowed upload size. Default 1 MB.
830 $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
831 $size = size_format( $bytes );
832 $upload_dir = wp_upload_dir();
833 if ( ! empty( $upload_dir['error'] ) ) :
834 ?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
835 <p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
838 <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' ) ); ?>">
840 <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
841 <input type="file" id="upload" name="import" size="25" />
842 <input type="hidden" name="action" value="save" />
843 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
845 <?php submit_button( __('Upload file and import'), 'button' ); ?>
852 * Add a meta box to an edit form.
856 * @param string $id String for use in the 'id' attribute of tags.
857 * @param string $title Title of the meta box.
858 * @param callback $callback Function that fills the box with the desired content.
859 * The function should echo its output.
860 * @param string|WP_Screen $screen Optional. The screen on which to show the box (like a post
861 * type, 'link', or 'comment'). Default is the current screen.
862 * @param string $context Optional. The context within the screen where the boxes
863 * should display. Available contexts vary from screen to
864 * screen. Post edit screen contexts include 'normal', 'side',
865 * and 'advanced'. Comments screen contexts include 'normal'
866 * and 'side'. Menus meta boxes (accordion sections) all use
867 * the 'side' context. Global default is 'advanced'.
868 * @param string $priority Optional. The priority within the context where the boxes
869 * should show ('high', 'low'). Default 'default'.
870 * @param array $callback_args Optional. Data that should be set as the $args property
871 * of the box array (which is the second parameter passed
872 * to your callback). Default null.
874 function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {
875 global $wp_meta_boxes;
877 if ( empty( $screen ) )
878 $screen = get_current_screen();
879 elseif ( is_string( $screen ) )
880 $screen = convert_to_screen( $screen );
884 if ( !isset($wp_meta_boxes) )
885 $wp_meta_boxes = array();
886 if ( !isset($wp_meta_boxes[$page]) )
887 $wp_meta_boxes[$page] = array();
888 if ( !isset($wp_meta_boxes[$page][$context]) )
889 $wp_meta_boxes[$page][$context] = array();
891 foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
892 foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
893 if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
896 // If a core box was previously added or removed by a plugin, don't add.
897 if ( 'core' == $priority ) {
898 // If core box previously deleted, don't add
899 if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
901 // If box was added with default priority, give it core priority to maintain sort order
902 if ( 'default' == $a_priority ) {
903 $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
904 unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
908 // If no priority given and id already present, use existing priority
909 if ( empty($priority) ) {
910 $priority = $a_priority;
911 // else if we're adding to the sorted priority, we don't know the title or callback. Grab them from the previously added context/priority.
912 } elseif ( 'sorted' == $priority ) {
913 $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
914 $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
915 $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
917 // An id can be in only one priority and one context
918 if ( $priority != $a_priority || $context != $a_context )
919 unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
923 if ( empty($priority) )
926 if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
927 $wp_meta_boxes[$page][$context][$priority] = array();
929 $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
933 * Meta-Box template function
937 * @param string|object $screen Screen identifier
938 * @param string $context box context
939 * @param mixed $object gets passed to the box callback function as first parameter
940 * @return int number of meta_boxes
942 function do_meta_boxes( $screen, $context, $object ) {
943 global $wp_meta_boxes;
944 static $already_sorted = false;
946 if ( empty( $screen ) )
947 $screen = get_current_screen();
948 elseif ( is_string( $screen ) )
949 $screen = convert_to_screen( $screen );
953 $hidden = get_hidden_meta_boxes( $screen );
955 printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context));
959 // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
960 if ( !$already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) {
961 foreach ( $sorted as $box_context => $ids ) {
962 foreach ( explode(',', $ids ) as $id ) {
963 if ( $id && 'dashboard_browser_nag' !== $id )
964 add_meta_box( $id, null, null, $screen, $box_context, 'sorted' );
968 $already_sorted = true;
970 if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
973 foreach ( array('high', 'sorted', 'core', 'default', 'low') as $priority ) {
974 if ( isset($wp_meta_boxes[$page][$context][$priority]) ) {
975 foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
976 if ( false == $box || ! $box['title'] )
979 $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : '';
980 echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n";
981 if ( 'dashboard_browser_nag' != $box['id'] )
982 echo '<div class="handlediv" title="' . esc_attr__('Click to toggle') . '"><br /></div>';
983 echo "<h3 class='hndle'><span>{$box['title']}</span></h3>\n";
984 echo '<div class="inside">' . "\n";
985 call_user_func($box['callback'], $object, $box);
1000 * Remove a meta box from an edit form.
1004 * @param string $id String for use in the 'id' attribute of tags.
1005 * @param string|object $screen The screen on which to show the box (post, page, link).
1006 * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
1008 function remove_meta_box($id, $screen, $context) {
1009 global $wp_meta_boxes;
1011 if ( empty( $screen ) )
1012 $screen = get_current_screen();
1013 elseif ( is_string( $screen ) )
1014 $screen = convert_to_screen( $screen );
1016 $page = $screen->id;
1018 if ( !isset($wp_meta_boxes) )
1019 $wp_meta_boxes = array();
1020 if ( !isset($wp_meta_boxes[$page]) )
1021 $wp_meta_boxes[$page] = array();
1022 if ( !isset($wp_meta_boxes[$page][$context]) )
1023 $wp_meta_boxes[$page][$context] = array();
1025 foreach ( array('high', 'core', 'default', 'low') as $priority )
1026 $wp_meta_boxes[$page][$context][$priority][$id] = false;
1030 * Meta Box Accordion Template Function
1032 * Largely made up of abstracted code from {@link do_meta_boxes()}, this
1033 * function serves to build meta boxes as list items for display as
1034 * a collapsible accordion.
1038 * @uses global $wp_meta_boxes Used to retrieve registered meta boxes.
1040 * @param string|object $screen The screen identifier.
1041 * @param string $context The meta box context.
1042 * @param mixed $object gets passed to the section callback function as first parameter.
1043 * @return int number of meta boxes as accordion sections.
1045 function do_accordion_sections( $screen, $context, $object ) {
1046 global $wp_meta_boxes;
1048 wp_enqueue_script( 'accordion' );
1050 if ( empty( $screen ) )
1051 $screen = get_current_screen();
1052 elseif ( is_string( $screen ) )
1053 $screen = convert_to_screen( $screen );
1055 $page = $screen->id;
1057 $hidden = get_hidden_meta_boxes( $screen );
1059 <div id="side-sortables" class="accordion-container">
1060 <ul class="outer-border">
1063 $first_open = false;
1065 if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[$page] ) || ! isset( $wp_meta_boxes[$page][$context] ) )
1068 foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
1069 if ( isset( $wp_meta_boxes[$page][$context][$priority] ) ) {
1070 foreach ( $wp_meta_boxes[$page][$context][$priority] as $box ) {
1071 if ( false == $box || ! $box['title'] )
1074 $hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
1077 if ( ! $first_open && empty( $hidden_class ) ) {
1079 $open_class = 'open';
1082 <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'] ); ?>">
1083 <h3 class="accordion-section-title hndle" tabindex="0" title="<?php echo esc_attr( $box['title'] ); ?>"><?php echo esc_html( $box['title'] ); ?></h3>
1084 <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
1085 <div class="inside">
1086 <?php call_user_func( $box['callback'], $object, $box ); ?>
1087 </div><!-- .inside -->
1088 </div><!-- .accordion-section-content -->
1089 </li><!-- .accordion-section -->
1096 </ul><!-- .outer-border -->
1097 </div><!-- .accordion-container -->
1103 * Add a new section to a settings page.
1105 * Part of the Settings API. Use this to define new settings sections for an admin page.
1106 * Show settings sections in your admin page callback function with do_settings_sections().
1107 * Add settings fields to your section with add_settings_field()
1109 * The $callback argument should be the name of a function that echoes out any
1110 * content you want to show at the top of the settings section before the actual
1111 * fields. It can output nothing if you want.
1115 * @global $wp_settings_sections Storage array of all settings sections added to admin pages
1117 * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags.
1118 * @param string $title Formatted title of the section. Shown as the heading for the section.
1119 * @param string $callback Function that echos out any content at the top of the section (between heading and fields).
1120 * @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();
1122 function add_settings_section($id, $title, $callback, $page) {
1123 global $wp_settings_sections;
1125 if ( 'misc' == $page ) {
1126 _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) );
1130 if ( 'privacy' == $page ) {
1131 _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) );
1135 $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
1139 * Add a new field to a section of a settings page
1141 * Part of the Settings API. Use this to define a settings field that will show
1142 * as part of a settings section inside a settings page. The fields are shown using
1143 * do_settings_fields() in do_settings-sections()
1145 * The $callback argument should be the name of a function that echoes out the
1146 * html input tags for this setting field. Use get_option() to retrieve existing
1151 * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
1153 * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags.
1154 * @param string $title Formatted title of the field. Shown as the label for the field during output.
1155 * @param string $callback Function that fills the field with the desired form inputs. The function should echo its output.
1156 * @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...).
1157 * @param string $section The slug-name of the section of the settings page in which to show the box (default, ...).
1158 * @param array $args Additional arguments
1160 function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
1161 global $wp_settings_fields;
1163 if ( 'misc' == $page ) {
1164 _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
1168 if ( 'privacy' == $page ) {
1169 _deprecated_argument( __FUNCTION__, '3.5', __( 'The privacy options group has been removed. Use another settings group.' ) );
1173 $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
1177 * Prints out all settings sections added to a particular settings page
1179 * Part of the Settings API. Use this in a settings page callback function
1180 * to output all the sections and fields that were added to that $page with
1181 * add_settings_section() and add_settings_field()
1183 * @global $wp_settings_sections Storage array of all settings sections added to admin pages
1184 * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
1187 * @param string $page The slug name of the page whos settings sections you want to output
1189 function do_settings_sections( $page ) {
1190 global $wp_settings_sections, $wp_settings_fields;
1192 if ( ! isset( $wp_settings_sections[$page] ) )
1195 foreach ( (array) $wp_settings_sections[$page] as $section ) {
1196 if ( $section['title'] )
1197 echo "<h3>{$section['title']}</h3>\n";
1199 if ( $section['callback'] )
1200 call_user_func( $section['callback'], $section );
1202 if ( ! isset( $wp_settings_fields ) || !isset( $wp_settings_fields[$page] ) || !isset( $wp_settings_fields[$page][$section['id']] ) )
1204 echo '<table class="form-table">';
1205 do_settings_fields( $page, $section['id'] );
1211 * Print out the settings fields for a particular settings section
1213 * Part of the Settings API. Use this in a settings page to output
1214 * a specific section. Should normally be called by do_settings_sections()
1215 * rather than directly.
1217 * @global $wp_settings_fields Storage array of settings fields and their pages/sections
1221 * @param string $page Slug title of the admin page who's settings fields you want to show.
1222 * @param section $section Slug title of the settings section who's fields you want to show.
1224 function do_settings_fields($page, $section) {
1225 global $wp_settings_fields;
1227 if ( ! isset( $wp_settings_fields[$page][$section] ) )
1230 foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
1232 if ( !empty($field['args']['label_for']) )
1233 echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>';
1235 echo '<th scope="row">' . $field['title'] . '</th>';
1237 call_user_func($field['callback'], $field['args']);
1244 * Register a settings error to be displayed to the user
1246 * Part of the Settings API. Use this to show messages to users about settings validation
1247 * problems, missing settings or anything else.
1249 * Settings errors should be added inside the $sanitize_callback function defined in
1250 * register_setting() for a given setting to give feedback about the submission.
1252 * By default messages will show immediately after the submission that generated the error.
1253 * Additional calls to settings_errors() can be used to show errors even when the settings
1254 * page is first accessed.
1258 * @global array $wp_settings_errors Storage array of errors registered during this pageload
1260 * @param string $setting Slug title of the setting to which this error applies
1261 * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
1262 * @param string $message The formatted message text to display to the user (will be shown inside styled <div> and <p>)
1263 * @param string $type The type of message it is, controls HTML class. Use 'error' or 'updated'.
1265 function add_settings_error( $setting, $code, $message, $type = 'error' ) {
1266 global $wp_settings_errors;
1269 'setting' => $setting,
1271 'message' => $message,
1274 $wp_settings_errors[] = $new_error;
1278 * Fetch settings errors registered by add_settings_error()
1280 * Checks the $wp_settings_errors array for any errors declared during the current
1281 * pageload and returns them.
1283 * If changes were just submitted ($_GET['settings-updated']) and settings errors were saved
1284 * to the 'settings_errors' transient then those errors will be returned instead. This
1285 * is used to pass errors back across pageloads.
1287 * Use the $sanitize argument to manually re-sanitize the option before returning errors.
1288 * This is useful if you have errors or notices you want to show even when the user
1289 * hasn't submitted data (i.e. when they first load an options page, or in admin_notices action hook)
1293 * @global array $wp_settings_errors Storage array of errors registered during this pageload
1295 * @param string $setting Optional slug title of a specific setting who's errors you want.
1296 * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
1297 * @return array Array of settings errors
1299 function get_settings_errors( $setting = '', $sanitize = false ) {
1300 global $wp_settings_errors;
1302 // If $sanitize is true, manually re-run the sanitization for this option
1303 // This allows the $sanitize_callback from register_setting() to run, adding
1304 // any settings errors you want to show by default.
1306 sanitize_option( $setting, get_option( $setting ) );
1308 // If settings were passed back from options.php then use them
1309 if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && get_transient( 'settings_errors' ) ) {
1310 $wp_settings_errors = array_merge( (array) $wp_settings_errors, get_transient( 'settings_errors' ) );
1311 delete_transient( 'settings_errors' );
1314 // Check global in case errors have been added on this pageload
1315 if ( ! count( $wp_settings_errors ) )
1318 // Filter the results to those of a specific setting if one was set
1320 $setting_errors = array();
1321 foreach ( (array) $wp_settings_errors as $key => $details ) {
1322 if ( $setting == $details['setting'] )
1323 $setting_errors[] = $wp_settings_errors[$key];
1325 return $setting_errors;
1328 return $wp_settings_errors;
1332 * Display settings errors registered by add_settings_error()
1334 * Part of the Settings API. Outputs a <div> for each error retrieved by get_settings_errors().
1336 * This is called automatically after a settings page based on the Settings API is submitted.
1337 * Errors should be added during the validation callback function for a setting defined in register_setting()
1339 * The $sanitize option is passed into get_settings_errors() and will re-run the setting sanitization
1340 * on its current value.
1342 * The $hide_on_update option will cause errors to only show when the settings page is first loaded.
1343 * if the user has already saved new values it will be hidden to avoid repeating messages already
1344 * shown in the default error reporting after submission. This is useful to show general errors like missing
1345 * settings when the user arrives at the settings page.
1349 * @param string $setting Optional slug title of a specific setting who's errors you want.
1350 * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
1351 * @param boolean $hide_on_update If set to true errors will not be shown if the settings page has already been submitted.
1353 function settings_errors( $setting = '', $sanitize = false, $hide_on_update = false ) {
1355 if ( $hide_on_update && ! empty( $_GET['settings-updated'] ) )
1358 $settings_errors = get_settings_errors( $setting, $sanitize );
1360 if ( empty( $settings_errors ) )
1364 foreach ( $settings_errors as $key => $details ) {
1365 $css_id = 'setting-error-' . $details['code'];
1366 $css_class = $details['type'] . ' settings-error';
1367 $output .= "<div id='$css_id' class='$css_class'> \n";
1368 $output .= "<p><strong>{$details['message']}</strong></p>";
1369 $output .= "</div> \n";
1375 * {@internal Missing Short Description}}
1379 * @param unknown_type $found_action
1381 function find_posts_div($found_action = '') {
1383 <div id="find-posts" class="find-box" style="display: none;">
1384 <div id="find-posts-head" class="find-box-head">
1385 <?php _e( 'Find Posts or Pages' ); ?>
1386 <div id="find-posts-close"></div>
1388 <div class="find-box-inside">
1389 <div class="find-box-search">
1390 <?php if ( $found_action ) { ?>
1391 <input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" />
1393 <input type="hidden" name="affected" id="affected" value="" />
1394 <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
1395 <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
1396 <input type="text" id="find-posts-input" name="ps" value="" />
1397 <span class="spinner"></span>
1398 <input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" />
1399 <div class="clear"></div>
1401 <div id="find-posts-response"></div>
1403 <div class="find-box-buttons">
1404 <?php submit_button( __( 'Select' ), 'button-primary alignright', 'find-posts-submit', false ); ?>
1405 <div class="clear"></div>
1412 * Display the post password.
1414 * The password is passed through {@link esc_attr()} to ensure that it
1415 * is safe for placing in an html attribute.
1420 function the_post_password() {
1422 if ( isset( $post->post_password ) )
1423 echo esc_attr( $post->post_password );
1427 * Get the post title.
1429 * The post title is fetched and if it is blank then a default string is
1433 * @param mixed $post Post id or object. If not supplied the global $post is used.
1434 * @return string The post title if set
1436 function _draft_or_post_title( $post = 0 ) {
1437 $title = get_the_title( $post );
1438 if ( empty( $title ) )
1439 $title = __( '(no title)' );
1444 * Display the search query.
1446 * A simple wrapper to display the "s" parameter in a GET URI. This function
1447 * should only be used when {@link the_search_query()} cannot.
1453 function _admin_search_query() {
1454 echo isset($_REQUEST['s']) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : '';
1458 * Generic Iframe header for use with Thickbox
1461 * @param string $title Title of the Iframe page.
1462 * @param bool $limit_styles Limit styles to colour-related styles only (unless others are enqueued).
1465 function iframe_header( $title = '', $limit_styles = false ) {
1466 show_admin_bar( false );
1467 global $hook_suffix, $current_user, $admin_body_class, $wp_locale;
1468 $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
1470 $current_screen = get_current_screen();
1472 @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
1473 _wp_admin_html_begin();
1475 <title><?php bloginfo('name') ?> › <?php echo $title ?> — <?php _e('WordPress'); ?></title>
1477 wp_enqueue_style( 'colors' );
1479 <script type="text/javascript">
1481 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();}}};
1482 function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
1483 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>',
1484 pagenow = '<?php echo $current_screen->id; ?>',
1485 typenow = '<?php echo $current_screen->post_type; ?>',
1486 adminpage = '<?php echo $admin_body_class; ?>',
1487 thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
1488 decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
1489 isRtl = <?php echo (int) is_rtl(); ?>;
1493 /** This action is documented in wp-admin/admin-header.php */
1494 do_action( 'admin_enqueue_scripts', $hook_suffix );
1496 /** This action is documented in wp-admin/admin-header.php */
1497 do_action( "admin_print_styles-$hook_suffix" );
1499 /** This action is documented in wp-admin/admin-header.php */
1500 do_action( 'admin_print_styles' );
1502 /** This action is documented in wp-admin/admin-header.php */
1503 do_action( "admin_print_scripts-$hook_suffix" );
1505 /** This action is documented in wp-admin/admin-header.php */
1506 do_action( 'admin_print_scripts' );
1508 /** This action is documented in wp-admin/admin-header.php */
1509 do_action( "admin_head-$hook_suffix" );
1511 /** This action is documented in wp-admin/admin-header.php */
1512 do_action( 'admin_head' );
1514 $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
1517 $admin_body_class .= ' rtl';
1521 <?php /** This filter is documented in wp-admin/admin-header.php */ ?>
1522 <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; ?>">
1523 <script type="text/javascript">
1526 var c = document.body.className;
1527 c = c.replace(/no-js/, 'js');
1528 document.body.className = c;
1536 * Generic Iframe footer for use with Thickbox
1541 function iframe_footer() {
1543 * We're going to hide any footer output on iFrame pages,
1544 * but run the hooks anyway since they output Javascript
1545 * or other needed content.
1548 <div class="hidden">
1550 /** This action is documented in wp-admin/admin-footer.php */
1551 do_action( 'admin_footer', '' );
1553 /** This action is documented in wp-admin/admin-footer.php */
1554 do_action( 'admin_print_footer_scripts' );
1557 <script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script>
1563 function _post_states($post) {
1564 $post_states = array();
1565 if ( isset( $_REQUEST['post_status'] ) )
1566 $post_status = $_REQUEST['post_status'];
1570 if ( !empty($post->post_password) )
1571 $post_states['protected'] = __('Password protected');
1572 if ( 'private' == $post->post_status && 'private' != $post_status )
1573 $post_states['private'] = __('Private');
1574 if ( 'draft' == $post->post_status && 'draft' != $post_status )
1575 $post_states['draft'] = __('Draft');
1576 if ( 'pending' == $post->post_status && 'pending' != $post_status )
1577 /* translators: post state */
1578 $post_states['pending'] = _x('Pending', 'post state');
1579 if ( is_sticky($post->ID) )
1580 $post_states['sticky'] = __('Sticky');
1583 * Filter the default post display states used in the Posts list table.
1587 * @param array $post_states An array of post display states. Values include 'Password protected',
1588 * 'Private', 'Draft', 'Pending', and 'Sticky'.
1589 * @param int $post The post ID.
1591 $post_states = apply_filters( 'display_post_states', $post_states, $post );
1593 if ( ! empty($post_states) ) {
1594 $state_count = count($post_states);
1597 foreach ( $post_states as $state ) {
1599 ( $i == $state_count ) ? $sep = '' : $sep = ', ';
1600 echo "<span class='post-state'>$state$sep</span>";
1606 function _media_states( $post ) {
1607 $media_states = array();
1608 $stylesheet = get_option('stylesheet');
1610 if ( current_theme_supports( 'custom-header') ) {
1611 $meta_header = get_post_meta($post->ID, '_wp_attachment_is_custom_header', true );
1612 if ( ! empty( $meta_header ) && $meta_header == $stylesheet )
1613 $media_states[] = __( 'Header Image' );
1616 if ( current_theme_supports( 'custom-background') ) {
1617 $meta_background = get_post_meta($post->ID, '_wp_attachment_is_custom_background', true );
1618 if ( ! empty( $meta_background ) && $meta_background == $stylesheet )
1619 $media_states[] = __( 'Background Image' );
1623 * Filter the default media display states for items in the Media list table.
1627 * @param array $media_states An array of media states. Default 'Header Image',
1628 * 'Background Image'.
1630 $media_states = apply_filters( 'display_media_states', $media_states );
1632 if ( ! empty( $media_states ) ) {
1633 $state_count = count( $media_states );
1636 foreach ( $media_states as $state ) {
1638 ( $i == $state_count ) ? $sep = '' : $sep = ', ';
1639 echo "<span class='post-state'>$state$sep</span>";
1645 * Test support for compressing JavaScript from PHP
1647 * Outputs JavaScript that tests if compression from PHP works as expected
1648 * and sets an option with the result. Has no effect when the current user
1649 * is not an administrator. To run the test again the option 'can_compress_scripts'
1650 * has to be deleted.
1654 function compression_test() {
1656 <script type="text/javascript">
1658 var testCompression = {
1659 get : function(test) {
1661 if ( window.XMLHttpRequest ) {
1662 x = new XMLHttpRequest();
1664 try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
1668 x.onreadystatechange = function() {
1670 if ( x.readyState == 4 ) {
1671 r = x.responseText.substr(0, 18);
1672 h = x.getResponseHeader('Content-Encoding');
1673 testCompression.check(r, h, test);
1677 x.open('GET', ajaxurl + '?action=wp-compression-test&test='+test+'&'+(new Date()).getTime(), true);
1682 check : function(r, h, test) {
1683 if ( ! r && ! test )
1687 if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) )
1696 if ( '"wpCompressionTest' == r )
1703 testCompression.check();
1710 * Echoes a submit button, with provided text and appropriate class(es).
1714 * @see get_submit_button()
1716 * @param string $text The text of the button (defaults to 'Save Changes')
1717 * @param string $type Optional. The type and CSS class(es) of the button. Core values
1718 * include 'primary', 'secondary', 'delete'. Default 'primary'
1719 * @param string $name The HTML name of the submit button. Defaults to "submit". If no
1720 * id attribute is given in $other_attributes below, $name will be
1721 * used as the button's id.
1722 * @param bool $wrap True if the output button should be wrapped in a paragraph tag,
1723 * false otherwise. Defaults to true
1724 * @param array|string $other_attributes Other attributes that should be output with the button, mapping
1725 * attributes to their values, such as setting tabindex to 1, etc.
1726 * These key/value attribute pairs will be output as attribute="value",
1727 * where attribute is the key. Other attributes can also be provided
1728 * as a string such as 'tabindex="1"', though the array format is
1729 * preferred. Default null.
1731 function submit_button( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null ) {
1732 echo get_submit_button( $text, $type, $name, $wrap, $other_attributes );
1736 * Returns a submit button, with provided text and appropriate class
1740 * @param string $text The text of the button (defaults to 'Save Changes')
1741 * @param string $type The type of button. One of: primary, secondary, delete
1742 * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute
1743 * is given in $other_attributes below, $name will be used as the button's id.
1744 * @param bool $wrap True if the output button should be wrapped in a paragraph tag,
1745 * false otherwise. Defaults to true
1746 * @param array|string $other_attributes Other attributes that should be output with the button,
1747 * mapping attributes to their values, such as array( 'tabindex' => '1' ).
1748 * These attributes will be output as attribute="value", such as tabindex="1".
1749 * Defaults to no other attributes. Other attributes can also be provided as a
1750 * string such as 'tabindex="1"', though the array format is typically cleaner.
1752 function get_submit_button( $text = null, $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = null ) {
1753 if ( ! is_array( $type ) )
1754 $type = explode( ' ', $type );
1756 $button_shorthand = array( 'primary', 'small', 'large' );
1757 $classes = array( 'button' );
1758 foreach ( $type as $t ) {
1759 if ( 'secondary' === $t || 'button-secondary' === $t )
1761 $classes[] = in_array( $t, $button_shorthand ) ? 'button-' . $t : $t;
1763 $class = implode( ' ', array_unique( $classes ) );
1765 if ( 'delete' === $type )
1766 $class = 'button-secondary delete';
1768 $text = $text ? $text : __( 'Save Changes' );
1770 // Default the id attribute to $name unless an id was specifically provided in $other_attributes
1772 if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) {
1773 $id = $other_attributes['id'];
1774 unset( $other_attributes['id'] );
1778 if ( is_array( $other_attributes ) ) {
1779 foreach ( $other_attributes as $attribute => $value ) {
1780 $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
1782 } else if ( !empty( $other_attributes ) ) { // Attributes provided as a string
1783 $attributes = $other_attributes;
1786 $button = '<input type="submit" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" class="' . esc_attr( $class );
1787 $button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />';
1790 $button = '<p class="submit">' . $button . '</p>';
1796 function _wp_admin_html_begin() {
1799 $admin_html_class = ( is_admin_bar_showing() ) ? 'wp-toolbar' : '';
1802 @header('X-UA-Compatible: IE=edge');
1805 * Fires inside the HTML tag in the admin header.
1812 <html xmlns="http://www.w3.org/1999/xhtml" class="ie8 <?php echo $admin_html_class; ?>" <?php do_action( 'admin_xml_ns' ); ?> <?php language_attributes(); ?>>
1814 <!--[if !(IE 8) ]><!-->
1815 <?php /** This action is documented in wp-admin/includes/template.php */ ?>
1816 <html xmlns="http://www.w3.org/1999/xhtml" class="<?php echo $admin_html_class; ?>" <?php do_action( 'admin_xml_ns' ); ?> <?php language_attributes(); ?>>
1819 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
1823 final class WP_Internal_Pointers {
1825 * Initializes the new feature pointers.
1829 * All pointers can be disabled using the following:
1830 * remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
1832 * Individual pointers (e.g. wp390_widgets) can be disabled using the following:
1833 * remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp390_widgets' ) );
1835 public static function enqueue_scripts( $hook_suffix ) {
1837 * Register feature pointers
1838 * Format: array( hook_suffix => pointer_id )
1841 $registered_pointers = array(
1842 'post-new.php' => 'wp350_media',
1843 'post.php' => array( 'wp350_media', 'wp360_revisions' ),
1844 'edit.php' => 'wp360_locks',
1845 'widgets.php' => 'wp390_widgets',
1846 'themes.php' => 'wp390_widgets',
1849 // Check if screen related pointer is registered
1850 if ( empty( $registered_pointers[ $hook_suffix ] ) )
1853 $pointers = (array) $registered_pointers[ $hook_suffix ];
1855 $caps_required = array(
1856 'wp350_media' => array( 'upload_files' ),
1857 'wp390_widgets' => array( 'edit_theme_options' ),
1860 // Get dismissed pointers
1861 $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
1863 $got_pointers = false;
1864 foreach ( array_diff( $pointers, $dismissed ) as $pointer ) {
1865 if ( isset( $caps_required[ $pointer ] ) ) {
1866 foreach ( $caps_required[ $pointer ] as $cap ) {
1867 if ( ! current_user_can( $cap ) )
1872 // Bind pointer print function
1873 add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) );
1874 $got_pointers = true;
1877 if ( ! $got_pointers )
1880 // Add pointers script and style to queue
1881 wp_enqueue_style( 'wp-pointer' );
1882 wp_enqueue_script( 'wp-pointer' );
1886 * Print the pointer javascript data.
1890 * @param string $pointer_id The pointer ID.
1891 * @param string $selector The HTML elements, on which the pointer should be attached.
1892 * @param array $args Arguments to be passed to the pointer JS (see wp-pointer.js).
1894 private static function print_js( $pointer_id, $selector, $args ) {
1895 if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) )
1899 <script type="text/javascript">
1902 var options = <?php echo json_encode( $args ); ?>, setup;
1907 options = $.extend( options, {
1910 pointer: '<?php echo $pointer_id; ?>',
1911 action: 'dismiss-wp-pointer'
1916 setup = function() {
1917 $('<?php echo $selector; ?>').first().pointer( options ).pointer('open');
1920 if ( options.position && options.position.defer_loading )
1921 $(window).bind( 'load.wp-pointers', setup );
1923 $(document).ready( setup );
1931 public static function pointer_wp330_toolbar() {}
1932 public static function pointer_wp330_media_uploader() {}
1933 public static function pointer_wp330_saving_widgets() {}
1934 public static function pointer_wp340_customize_current_theme_link() {}
1935 public static function pointer_wp340_choose_image_from_library() {}
1937 public static function pointer_wp350_media() {
1938 $content = '<h3>' . __( 'New Media Manager' ) . '</h3>';
1939 $content .= '<p>' . __( 'Uploading files and creating image galleries has a whole new look. Check it out!' ) . '</p>';
1941 self::print_js( 'wp350_media', '.insert-media', array(
1942 'content' => $content,
1943 'position' => array( 'edge' => is_rtl() ? 'right' : 'left', 'align' => 'center' ),
1947 public static function pointer_wp360_revisions() {
1948 $content = '<h3>' . __( 'Compare Revisions' ) . '</h3>';
1949 $content .= '<p>' . __( 'View, compare, and restore other versions of this content on the improved revisions screen.' ) . '</p>';
1951 self::print_js( 'wp360_revisions', '.misc-pub-section.misc-pub-revisions', array(
1952 'content' => $content,
1953 'position' => array( 'edge' => is_rtl() ? 'left' : 'right', 'align' => 'center', 'my' => is_rtl() ? 'left' : 'right-14px' ),
1957 public static function pointer_wp360_locks() {
1958 if ( ! is_multi_author() ) {
1962 $content = '<h3>' . __( 'Edit Lock' ) . '</h3>';
1963 $content .= '<p>' . __( 'Someone else is editing this. No need to refresh; the lock will disappear when they’re done.' ) . '</p>';
1965 self::print_js( 'wp360_locks', 'tr.wp-locked .locked-indicator', array(
1966 'content' => $content,
1967 'position' => array( 'edge' => 'left', 'align' => 'left' ),
1971 public static function pointer_wp390_widgets() {
1972 if ( ! current_theme_supports( 'widgets' ) ) {
1976 $content = '<h3>' . __( 'New Feature: Live Widget Previews' ) . '</h3>';
1977 $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>';
1979 if ( 'themes' === get_current_screen()->id ) {
1980 $selector = '.theme.active .customize';
1981 $position = array( 'edge' => is_rtl() ? 'right' : 'left', 'align' => 'center', 'my' => is_rtl() ? 'right-13px' : '' );
1983 $selector = 'a[href="customize.php"]';
1985 $position = array( 'edge' => 'right', 'align' => 'center', 'my' => 'right-5px' );
1987 $position = array( 'edge' => 'left', 'align' => 'center', 'my' => 'left-5px' );
1991 self::print_js( 'wp390_widgets', $selector, array(
1992 'content' => $content,
1993 'position' => $position,
1998 * Prevents new users from seeing existing 'new feature' pointers.
2002 public static function dismiss_pointers_for_new_users( $user_id ) {
2003 add_user_meta( $user_id, 'dismissed_wp_pointers', 'wp350_media,wp360_revisions,wp360_locks,wp390_widgets' );
2007 add_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
2008 add_action( 'user_register', array( 'WP_Internal_Pointers', 'dismiss_pointers_for_new_users' ) );
2011 * Convert a screen string to a screen object
2015 * @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen.
2016 * @return WP_Screen Screen object.
2018 function convert_to_screen( $hook_name ) {
2019 if ( ! class_exists( 'WP_Screen' ) ) {
2020 _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' );
2021 return (object) array( 'id' => '_invalid', 'base' => '_are_belong_to_us' );
2024 return WP_Screen::get( $hook_name );
2028 * Output the HTML for restoring the post data from DOM storage
2033 function _local_storage_notice() {
2035 <div id="local-storage-notice" class="hidden">
2036 <p class="local-restore">
2037 <?php _e('The backup of this post in your browser is different from the version below.'); ?>
2038 <a class="restore-backup" href="#"><?php _e('Restore the backup.'); ?></a>
2040 <p class="undo-restore hidden">
2041 <?php _e('Post restored successfully.'); ?>
2042 <a class="undo-restore-backup" href="#"><?php _e('Undo.'); ?></a>
2049 * Output a HTML element with a star rating for a given rating.
2051 * Outputs a HTML element with the star rating exposed on a 0..5 scale in
2052 * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the
2053 * number of ratings may also be displayed by passing the $number parameter.
2056 * @param array $args {
2057 * Optional. Array of star ratings arguments.
2059 * @type int $rating The rating to display, expressed in either a 0.5 rating increment,
2060 * or percentage. Default 0.
2061 * @type string $type Format that the $rating is in. Valid values are 'rating' (default),
2062 * or, 'percent'. Default 'rating'.
2063 * @type int $number The number of ratings that makes up this rating. Default 0.
2066 function wp_star_rating( $args = array() ) {
2072 $r = wp_parse_args( $args, $defaults );
2073 extract( $r, EXTR_SKIP );
2075 // Non-english decimal places when the $rating is coming from a string
2076 $rating = str_replace( ',', '.', $rating );
2078 // Convert Percentage to star rating, 0..5 in .5 increments
2079 if ( 'percent' == $type ) {
2080 $rating = round( $rating / 10, 0 ) / 2;
2083 // Calculate the number of each type of star needed
2084 $full_stars = floor( $rating );
2085 $half_stars = ceil( $rating - $full_stars );
2086 $empty_stars = 5 - $full_stars - $half_stars;
2089 /* translators: 1: The rating, 2: The number of ratings */
2090 $title = _n( '%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $number );
2091 $title = sprintf( $title, number_format_i18n( $rating, 1 ), number_format_i18n( $number ) );
2093 /* translators: 1: The rating */
2094 $title = sprintf( __( '%s rating' ), number_format_i18n( $rating, 1 ) );
2097 echo '<div class="star-rating" title="' . esc_attr( $title ) . '">';
2098 echo str_repeat( '<div class="star star-full"></div>', $full_stars );
2099 echo str_repeat( '<div class="star star-half"></div>', $half_stars );
2100 echo str_repeat( '<div class="star star-empty"></div>', $empty_stars);