]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/template.php
WordPress 4.0
[autoinstalls/wordpress.git] / wp-admin / includes / template.php
1 <?php
2 /**
3  * Template WordPress Administration API.
4  *
5  * A Big Mess. Also some neat functions that are nicely written.
6  *
7  * @package WordPress
8  * @subpackage Administration
9  */
10
11 //
12 // Category Checklists
13 //
14
15 /**
16  * Walker to output an unordered list of category checkbox <input> elements.
17  *
18  * @see Walker
19  * @see wp_category_checklist()
20  * @see wp_terms_checklist()
21  * @since 2.5.1
22  */
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
26
27         /**
28          * Starts the list before the elements are added.
29          *
30          * @see Walker:start_lvl()
31          *
32          * @since 2.5.1
33          *
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()
37          */
38         public function start_lvl( &$output, $depth = 0, $args = array() ) {
39                 $indent = str_repeat("\t", $depth);
40                 $output .= "$indent<ul class='children'>\n";
41         }
42
43         /**
44          * Ends the list of after the elements are added.
45          *
46          * @see Walker::end_lvl()
47          *
48          * @since 2.5.1
49          *
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()
53          */
54         public function end_lvl( &$output, $depth = 0, $args = array() ) {
55                 $indent = str_repeat("\t", $depth);
56                 $output .= "$indent</ul>\n";
57         }
58
59         /**
60          * Start the element output.
61          *
62          * @see Walker::start_el()
63          *
64          * @since 2.5.1
65          *
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.
71          */
72         public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
73                 if ( empty( $args['taxonomy'] ) ) {
74                         $taxonomy = 'category';
75                 } else {
76                         $taxonomy = $args['taxonomy'];
77                 }
78
79                 if ( $taxonomy == 'category' ) {
80                         $name = 'post_category';
81                 } else {
82                         $name = 'tax_input[' . $taxonomy . ']';
83                 }
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"' : '';
86
87                 $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
88
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>';
95         }
96
97         /**
98          * Ends the element output, if needed.
99          *
100          * @see Walker::end_el()
101          *
102          * @since 2.5.1
103          *
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()
108          */
109         public function end_el( &$output, $category, $depth = 0, $args = array() ) {
110                 $output .= "</li>\n";
111         }
112 }
113
114 /**
115  * Output an unordered list of checkbox <input> elements labelled
116  * with category names.
117  *
118  * @see wp_terms_checklist()
119  * @since 2.5.1
120  *
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.
127  */
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,
134                 'walker' => $walker,
135                 'checked_ontop' => $checked_ontop
136         ) );
137 }
138
139 /**
140  * Output an unordered list of checkbox <input> elements labelled
141  * with term names. Taxonomy independent version of wp_category_checklist().
142  *
143  * @since 3.0.0
144  *
145  * @param int $post_id
146  * @param array $args
147  */
148 function wp_terms_checklist( $post_id = 0, $args = array() ) {
149         $defaults = array(
150                 'descendants_and_self' => 0,
151                 'selected_cats' => false,
152                 'popular_cats' => false,
153                 'walker' => null,
154                 'taxonomy' => 'category',
155                 'checked_ontop' => true
156         );
157
158         /**
159          * Filter the taxonomy terms checklist arguments.
160          *
161          * @since 3.4.0
162          *
163          * @see wp_terms_checklist()
164          *
165          * @param array $args    An array of arguments.
166          * @param int   $post_id The post ID.
167          */
168         $params = apply_filters( 'wp_terms_checklist_args', $args, $post_id );
169
170         $r = wp_parse_args( $params, $defaults );
171
172         if ( empty( $r['walker'] ) || ! is_a( $r['walker'], 'Walker' ) ) {
173                 $walker = new Walker_Category_Checklist;
174         } else {
175                 $walker = $r['walker'];
176         }
177
178         $taxonomy = $r['taxonomy'];
179         $descendants_and_self = (int) $r['descendants_and_self'];
180
181         $args = array( 'taxonomy' => $taxonomy );
182
183         $tax = get_taxonomy( $taxonomy );
184         $args['disabled'] = ! current_user_can( $tax->cap->assign_terms );
185
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' ) ) );
190         } else {
191                 $args['selected_cats'] = array();
192         }
193         if ( is_array( $r['popular_cats'] ) ) {
194                 $args['popular_cats'] = $r['popular_cats'];
195         } else {
196                 $args['popular_cats'] = get_terms( $taxonomy, array(
197                         'fields' => 'ids',
198                         'orderby' => 'count',
199                         'order' => 'DESC',
200                         'number' => 10,
201                         'hierarchical' => false
202                 ) );
203         }
204         if ( $descendants_and_self ) {
205                 $categories = (array) get_terms( $taxonomy, array(
206                         'child_of' => $descendants_and_self,
207                         'hierarchical' => 0,
208                         'hide_empty' => 0
209                 ) );
210                 $self = get_term( $descendants_and_self, $taxonomy );
211                 array_unshift( $categories, $self );
212         } else {
213                 $categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) );
214         }
215
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 );
220
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] );
225                         }
226                 }
227
228                 // Put checked cats on top
229                 echo call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) );
230         }
231         // Then the rest of them
232         echo call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) );
233 }
234
235 /**
236  * Retrieve a list of the most popular terms from the specified taxonomy.
237  *
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.
242  *
243  * @since 2.5.0
244  *
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.
250  */
251 function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
252         $post = get_post();
253
254         if ( $post && $post->ID )
255                 $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields'=>'ids'));
256         else
257                 $checked_terms = array();
258
259         $terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
260
261         $tax = get_taxonomy($taxonomy);
262
263         $popular_ids = array();
264         foreach ( (array) $terms as $term ) {
265                 $popular_ids[] = $term->term_id;
266                 if ( !$echo ) // hack for AJAX use
267                         continue;
268                 $id = "popular-$taxonomy-$term->term_id";
269                 $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : '';
270                 ?>
271
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 ) ); ?> />
275                                 <?php
276                                 /** This filter is documented in wp-includes/category-template.php */
277                                 echo esc_html( apply_filters( 'the_category', $term->name ) );
278                                 ?>
279                         </label>
280                 </li>
281
282                 <?php
283         }
284         return $popular_ids;
285 }
286
287 /**
288  * {@internal Missing Short Description}}
289  *
290  * @since 2.5.1
291  *
292  * @param unknown_type $link_id
293  */
294 function wp_link_category_checklist( $link_id = 0 ) {
295         $default = 1;
296
297         if ( $link_id ) {
298                 $checked_categories = wp_get_link_cats( $link_id );
299                 // No selected categories, strange
300                 if ( ! count( $checked_categories ) )
301                         $checked_categories[] = $default;
302         } else {
303                 $checked_categories[] = $default;
304         }
305
306         $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) );
307
308         if ( empty( $categories ) )
309                 return;
310
311         foreach ( $categories as $category ) {
312                 $cat_id = $category->term_id;
313
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>";
318         }
319 }
320
321 // adds hidden fields with the data for use in the inline editor for posts and pages
322 /**
323  * {@internal Missing Short Description}}
324  *
325  * @since 2.7.0
326  *
327  * @param unknown_type $post
328  */
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 ) )
332                 return;
333
334         $title = esc_textarea( trim( $post->post_title ) );
335
336         /** This filter is documented in wp-admin/edit-tag-form.php */
337         echo '
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>';
352
353         if ( $post_type_object->hierarchical )
354                 echo '<div class="post_parent">' . $post->post_parent . '</div>';
355
356         if ( $post->post_type == 'page' )
357                 echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>';
358
359         if ( post_type_supports( $post->post_type, 'page-attributes' ) )
360                 echo '<div class="menu_order">' . $post->menu_order . '</div>';
361
362         $taxonomy_names = get_object_taxonomies( $post->post_type );
363         foreach ( $taxonomy_names as $taxonomy_name) {
364                 $taxonomy = get_taxonomy( $taxonomy_name );
365
366                 if ( $taxonomy->hierarchical && $taxonomy->show_ui ) {
367
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' );
372                         }
373                         $term_ids = empty( $terms ) ? array() : wp_list_pluck( $terms, 'term_id' );
374
375                         echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode( ',', $term_ids ) . '</div>';
376
377                 } elseif ( $taxonomy->show_ui ) {
378
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>';
381
382                 }
383         }
384
385         if ( !$post_type_object->hierarchical )
386                 echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
387
388         if ( post_type_supports( $post->post_type, 'post-formats' ) )
389                 echo '<div class="post_format">' . esc_html( get_post_format( $post->ID ) ) . '</div>';
390
391         echo '</div>';
392 }
393
394 /**
395  * {@internal Missing Short Description}}
396  *
397  * @since 2.7.0
398  *
399  * @param unknown_type $position
400  * @param unknown_type $checkbox
401  * @param unknown_type $mode
402  */
403 function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single', $table_row = true) {
404
405         /**
406          * Filter the in-line comment reply-to form output in the Comments
407          * list table.
408          *
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.
412          *
413          * @since 2.7.0
414          *
415          * @see wp_comment_reply()
416          *
417          * @param string $content The reply-to form content.
418          * @param array  $args    An array of default args.
419          */
420         $content = apply_filters( 'wp_comment_reply', '', array( 'position' => $position, 'checkbox' => $checkbox, 'mode' => $mode ) );
421
422         if ( ! empty($content) ) {
423                 echo $content;
424                 return;
425         }
426
427         if ( $mode == 'single' ) {
428                 $wp_list_table = _get_list_table('WP_Post_Comments_List_Table');
429         } else {
430                 $wp_list_table = _get_list_table('WP_Comments_List_Table');
431         }
432
433 ?>
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">
437 <?php else : ?>
438 <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;">
439 <?php endif; ?>
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;">
443                 <div class="inside">
444                 <label for="author"><?php _e('Name') ?></label>
445                 <input type="text" name="newcomment_author" size="50" value="" id="author" />
446                 </div>
447
448                 <div class="inside">
449                 <label for="author-email"><?php _e('E-mail') ?></label>
450                 <input type="text" name="newcomment_author_email" size="50" value="" id="author-email" />
451                 </div>
452
453                 <div class="inside">
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="" />
456                 </div>
457                 <div style="clear:both;"></div>
458         </div>
459
460         <div id="replycontainer">
461         <?php
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 ) );
464         ?>
465         </div>
466
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>
475         <br class="clear" />
476         </p>
477
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); ?>" />
486         <?php
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 );
490         ?>
491 <?php if ( $table_row ) : ?>
492 </td></tr></tbody></table>
493 <?php else : ?>
494 </div></div>
495 <?php endif; ?>
496 </form>
497 <?php
498 }
499
500 /**
501  * Output 'undo move to trash' text for comments
502  *
503  * @since 2.9.0
504  */
505 function wp_comment_trashnotice() {
506 ?>
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>
509 </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>
512 </div>
513 <?php
514 }
515
516 /**
517  * {@internal Missing Short Description}}
518  *
519  * @since 1.2.0
520  *
521  * @param unknown_type $meta
522  */
523 function list_meta( $meta ) {
524         // Exit if no meta
525         if ( ! $meta ) {
526                 echo '
527 <table id="list-table" style="display: none;">
528         <thead>
529         <tr>
530                 <th class="left">' . _x( 'Name', 'meta name' ) . '</th>
531                 <th>' . __( 'Value' ) . '</th>
532         </tr>
533         </thead>
534         <tbody id="the-list" data-wp-lists="list:meta">
535         <tr><td></td></tr>
536         </tbody>
537 </table>'; //TBODY needed for list-manipulation JS
538                 return;
539         }
540         $count = 0;
541 ?>
542 <table id="list-table">
543         <thead>
544         <tr>
545                 <th class="left"><?php _ex( 'Name', 'meta name' ) ?></th>
546                 <th><?php _e( 'Value' ) ?></th>
547         </tr>
548         </thead>
549         <tbody id='the-list' data-wp-lists='list:meta'>
550 <?php
551         foreach ( $meta as $entry )
552                 echo _list_meta_row( $entry, $count );
553 ?>
554         </tbody>
555 </table>
556 <?php
557 }
558
559 /**
560  * {@internal Missing Short Description}}
561  *
562  * @since 2.5.0
563  *
564  * @param unknown_type $entry
565  * @param unknown_type $count
566  * @return unknown
567  */
568 function _list_meta_row( $entry, &$count ) {
569         static $update_nonce = false;
570
571         if ( is_protected_meta( $entry['meta_key'], 'post' ) )
572                 return;
573
574         if ( !$update_nonce )
575                 $update_nonce = wp_create_nonce( 'add-meta' );
576
577         $r = '';
578         ++ $count;
579         if ( $count % 2 )
580                 $style = 'alternate';
581         else
582                 $style = '';
583
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'] );
588                 } else {
589                         // This is a serialized array/object so we should NOT display it.
590                         --$count;
591                         return;
592                 }
593         }
594
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'];
598
599         $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
600
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']}' />";
603
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" ) );
606         $r .= "\n\t\t";
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" ) );
608         $r .= "</div>";
609         $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
610         $r .= "</td>";
611
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>";
613         return $r;
614 }
615
616 /**
617  * Prints the form in the Custom Fields meta box.
618  *
619  * @since 1.2.0
620  *
621  * @param WP_Post $post Optional. The post being edited.
622  */
623 function meta_form( $post = null ) {
624         global $wpdb;
625         $post = get_post( $post );
626
627         /**
628          * Filter the number of custom fields to retrieve for the drop-down
629          * in the Custom Fields meta box.
630          *
631          * @since 2.1.0
632          *
633          * @param int $limit Number of custom fields to retrieve. Default 30.
634          */
635         $limit = apply_filters( 'postmeta_form_limit', 30 );
636         $sql = "SELECT meta_key
637                 FROM $wpdb->postmeta
638                 GROUP BY meta_key
639                 HAVING meta_key NOT LIKE %s
640                 ORDER BY meta_key
641                 LIMIT %d";
642         $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) );
643         if ( $keys ) {
644                 natcasesort( $keys );
645                 $meta_key_input_id = 'metakeyselect';
646         } else {
647                 $meta_key_input_id = 'metakeyinput';
648         }
649 ?>
650 <p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p>
651 <table id="newmeta">
652 <thead>
653 <tr>
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>
656 </tr>
657 </thead>
658
659 <tbody>
660 <tr>
661 <td id="newmetaleft" class="left">
662 <?php if ( $keys ) { ?>
663 <select id="metakeyselect" name="metakeyselect">
664 <option value="#NONE#"><?php _e( '&mdash; Select &mdash;' ); ?></option>
665 <?php
666
667         foreach ( $keys as $key ) {
668                 if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $post->ID, $key ) )
669                         continue;
670                 echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>";
671         }
672 ?>
673 </select>
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>
678 <?php } else { ?>
679 <input type="text" id="metakeyinput" name="metakeyinput" value="" />
680 <?php } ?>
681 </td>
682 <td><textarea id="metavalue" name="metavalue" rows="2" cols="25"></textarea></td>
683 </tr>
684
685 <tr><td colspan="2">
686 <div class="submit">
687 <?php submit_button( __( 'Add Custom Field' ), 'secondary', 'addmeta', false, array( 'id' => 'newmeta-submit', 'data-wp-lists' => 'add:the-list:newmeta' ) ); ?>
688 </div>
689 <?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?>
690 </td></tr>
691 </tbody>
692 </table>
693 <?php
694
695 }
696
697 /**
698  * Print out HTML form date elements for editing post or comment publish date.
699  *
700  * @since 0.71
701  *
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.
706  *                            Default 0|false.
707  */
708 function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
709         global $wp_locale, $comment;
710         $post = get_post();
711
712         if ( $for_post )
713                 $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );
714
715         $tab_index_attribute = '';
716         if ( (int) $tab_index > 0 )
717                 $tab_index_attribute = " tabindex=\"$tab_index\"";
718
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 />';
721
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 );
730
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 );
736
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";
743         }
744         $month .= '</select>';
745
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" />';
750
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 );
754
755         echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
756
757         if ( $multi ) return;
758
759         echo "\n\n";
760         $map = array(
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 ),
766         );
767         foreach ( $map as $timeunit => $value ) {
768                 list( $unit, $curr ) = $value;
769
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";
773         }
774 ?>
775
776 <p>
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>
779 </p>
780 <?php
781 }
782
783 /**
784  * Print out <option> HTML elements for the page templates drop-down.
785  *
786  * @since 1.5.0
787  *
788  * @param string $default Optional. The template file name. Default empty.
789  */
790 function page_template_dropdown( $default = '' ) {
791         $templates = get_page_templates( get_post() );
792         ksort( $templates );
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>";
796         }
797 }
798
799 /**
800  * Print out <option> HTML elements for the page parents drop-down.
801  *
802  * @since 1.5.0
803  *
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.
807  *
808  * @return void|bool Boolean False if page has no children, otherwise print out html elements
809  */
810 function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
811         global $wpdb;
812         $post = get_post();
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) );
814
815         if ( $items ) {
816                 foreach ( $items as $item ) {
817                         // A page cannot be its own parent.
818                         if ( $post && $post->ID && $item->ID == $post->ID )
819                                 continue;
820
821                         $pad = str_repeat( '&nbsp;', $level * 3 );
822                         $selected = selected( $default, $item->ID, false );
823
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 );
826                 }
827         } else {
828                 return false;
829         }
830 }
831
832 /**
833  * Print out <option> html elements for role selectors
834  *
835  * @since 2.1.0
836  *
837  * @param string $selected slug for the role that should be already selected
838  */
839 function wp_dropdown_roles( $selected = false ) {
840         $p = '';
841         $r = '';
842
843         $editable_roles = array_reverse( get_editable_roles() );
844
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>";
849                 else
850                         $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
851         }
852         echo $p . $r;
853 }
854
855 /**
856  * Outputs the form used by the importers to accept the data to be imported
857  *
858  * @since 2.0.0
859  *
860  * @param string $action The action attribute for the form.
861  */
862 function wp_import_upload_form( $action ) {
863
864         /**
865          * Filter the maximum allowed upload size for import files.
866          *
867          * @since 2.3.0
868          *
869          * @see wp_max_upload_size()
870          *
871          * @param int $max_upload_size Allowed upload size. Default 1 MB.
872          */
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
879         else :
880 ?>
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' ) ); ?>">
882 <p>
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; ?>" />
887 </p>
888 <?php submit_button( __('Upload file and import'), 'button' ); ?>
889 </form>
890 <?php
891         endif;
892 }
893
894 /**
895  * Add a meta box to an edit form.
896  *
897  * @since 2.5.0
898  *
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.
916  */
917 function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {
918         global $wp_meta_boxes;
919
920         if ( empty( $screen ) )
921                 $screen = get_current_screen();
922         elseif ( is_string( $screen ) )
923                 $screen = convert_to_screen( $screen );
924
925         $page = $screen->id;
926
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();
933
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]) )
937                                 continue;
938
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] )
943                                         return;
944
945                                 /*
946                                  * If box was added with default priority, give it core priority to
947                                  * maintain sort order.
948                                  */
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]);
952                                 }
953                                 return;
954                         }
955                         // If no priority given and id already present, use existing priority.
956                         if ( empty($priority) ) {
957                                 $priority = $a_priority;
958                         /*
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.
961                          */
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'];
966                         }
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]);
970                 }
971         }
972
973         if ( empty($priority) )
974                 $priority = 'low';
975
976         if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
977                 $wp_meta_boxes[$page][$context][$priority] = array();
978
979         $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
980 }
981
982 /**
983  * Meta-Box template function
984  *
985  * @since 2.5.0
986  *
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
991  */
992 function do_meta_boxes( $screen, $context, $object ) {
993         global $wp_meta_boxes;
994         static $already_sorted = false;
995
996         if ( empty( $screen ) )
997                 $screen = get_current_screen();
998         elseif ( is_string( $screen ) )
999                 $screen = convert_to_screen( $screen );
1000
1001         $page = $screen->id;
1002
1003         $hidden = get_hidden_meta_boxes( $screen );
1004
1005         printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context));
1006
1007         $i = 0;
1008         do {
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' );
1015                                 }
1016                         }
1017                 }
1018                 $already_sorted = true;
1019
1020                 if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
1021                         break;
1022
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'] )
1027                                                 continue;
1028                                         $i++;
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);
1036                                         echo "</div>\n";
1037                                         echo "</div>\n";
1038                                 }
1039                         }
1040                 }
1041         } while(0);
1042
1043         echo "</div>";
1044
1045         return $i;
1046
1047 }
1048
1049 /**
1050  * Remove a meta box from an edit form.
1051  *
1052  * @since 2.6.0
1053  *
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').
1057  */
1058 function remove_meta_box($id, $screen, $context) {
1059         global $wp_meta_boxes;
1060
1061         if ( empty( $screen ) )
1062                 $screen = get_current_screen();
1063         elseif ( is_string( $screen ) )
1064                 $screen = convert_to_screen( $screen );
1065
1066         $page = $screen->id;
1067
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();
1074
1075         foreach ( array('high', 'core', 'default', 'low') as $priority )
1076                 $wp_meta_boxes[$page][$context][$priority][$id] = false;
1077 }
1078
1079 /**
1080  * Meta Box Accordion Template Function
1081  *
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.
1085  *
1086  * @since 3.6.0
1087  *
1088  * @uses global $wp_meta_boxes Used to retrieve registered meta boxes.
1089  *
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.
1094  */
1095 function do_accordion_sections( $screen, $context, $object ) {
1096         global $wp_meta_boxes;
1097
1098         wp_enqueue_script( 'accordion' );
1099
1100         if ( empty( $screen ) )
1101                 $screen = get_current_screen();
1102         elseif ( is_string( $screen ) )
1103                 $screen = convert_to_screen( $screen );
1104
1105         $page = $screen->id;
1106
1107         $hidden = get_hidden_meta_boxes( $screen );
1108         ?>
1109         <div id="side-sortables" class="accordion-container">
1110                 <ul class="outer-border">
1111         <?php
1112         $i = 0;
1113         $first_open = false;
1114         do {
1115                 if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[$page] ) || ! isset( $wp_meta_boxes[$page][$context] ) )
1116                         break;
1117
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'] )
1122                                                 continue;
1123                                         $i++;
1124                                         $hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
1125
1126                                         $open_class = '';
1127                                         if ( ! $first_open && empty( $hidden_class ) ) {
1128                                                 $first_open = true;
1129                                                 $open_class = 'open';
1130                                         }
1131                                         ?>
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>
1136                                                 </h3>
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 -->
1143                                         <?php
1144                                 }
1145                         }
1146                 }
1147         } while(0);
1148         ?>
1149                 </ul><!-- .outer-border -->
1150         </div><!-- .accordion-container -->
1151         <?php
1152         return $i;
1153 }
1154
1155 /**
1156  * Add a new section to a settings page.
1157  *
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()
1161  *
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.
1165  *
1166  * @since 2.7.0
1167  *
1168  * @global $wp_settings_sections Storage array of all settings sections added to admin pages
1169  *
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();
1174  */
1175 function add_settings_section($id, $title, $callback, $page) {
1176         global $wp_settings_sections;
1177
1178         if ( 'misc' == $page ) {
1179                 _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) );
1180                 $page = 'general';
1181         }
1182
1183         if ( 'privacy' == $page ) {
1184                 _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) );
1185                 $page = 'reading';
1186         }
1187
1188         $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
1189 }
1190
1191 /**
1192  * Add a new field to a section of a settings page
1193  *
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()
1197  *
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
1200  * values to show.
1201  *
1202  * @since 2.7.0
1203  *
1204  * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
1205  *
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
1212  */
1213 function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
1214         global $wp_settings_fields;
1215
1216         if ( 'misc' == $page ) {
1217                 _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
1218                 $page = 'general';
1219         }
1220
1221         if ( 'privacy' == $page ) {
1222                 _deprecated_argument( __FUNCTION__, '3.5', __( 'The privacy options group has been removed. Use another settings group.' ) );
1223                 $page = 'reading';
1224         }
1225
1226         $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
1227 }
1228
1229 /**
1230  * Prints out all settings sections added to a particular settings page
1231  *
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()
1235  *
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
1238  * @since 2.7.0
1239  *
1240  * @param string $page The slug name of the page whos settings sections you want to output
1241  */
1242 function do_settings_sections( $page ) {
1243         global $wp_settings_sections, $wp_settings_fields;
1244
1245         if ( ! isset( $wp_settings_sections[$page] ) )
1246                 return;
1247
1248         foreach ( (array) $wp_settings_sections[$page] as $section ) {
1249                 if ( $section['title'] )
1250                         echo "<h3>{$section['title']}</h3>\n";
1251
1252                 if ( $section['callback'] )
1253                         call_user_func( $section['callback'], $section );
1254
1255                 if ( ! isset( $wp_settings_fields ) || !isset( $wp_settings_fields[$page] ) || !isset( $wp_settings_fields[$page][$section['id']] ) )
1256                         continue;
1257                 echo '<table class="form-table">';
1258                 do_settings_fields( $page, $section['id'] );
1259                 echo '</table>';
1260         }
1261 }
1262
1263 /**
1264  * Print out the settings fields for a particular settings section
1265  *
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.
1269  *
1270  * @global $wp_settings_fields Storage array of settings fields and their pages/sections
1271  *
1272  * @since 2.7.0
1273  *
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.
1276  */
1277 function do_settings_fields($page, $section) {
1278         global $wp_settings_fields;
1279
1280         if ( ! isset( $wp_settings_fields[$page][$section] ) )
1281                 return;
1282
1283         foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
1284                 echo '<tr>';
1285                 if ( !empty($field['args']['label_for']) )
1286                         echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>';
1287                 else
1288                         echo '<th scope="row">' . $field['title'] . '</th>';
1289                 echo '<td>';
1290                 call_user_func($field['callback'], $field['args']);
1291                 echo '</td>';
1292                 echo '</tr>';
1293         }
1294 }
1295
1296 /**
1297  * Register a settings error to be displayed to the user
1298  *
1299  * Part of the Settings API. Use this to show messages to users about settings validation
1300  * problems, missing settings or anything else.
1301  *
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.
1304  *
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.
1308  *
1309  * @since 3.0.0
1310  *
1311  * @global array $wp_settings_errors Storage array of errors registered during this pageload
1312  *
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'.
1317  */
1318 function add_settings_error( $setting, $code, $message, $type = 'error' ) {
1319         global $wp_settings_errors;
1320
1321         $wp_settings_errors[] = array(
1322                 'setting' => $setting,
1323                 'code'    => $code,
1324                 'message' => $message,
1325                 'type'    => $type
1326         );
1327 }
1328
1329 /**
1330  * Fetch settings errors registered by add_settings_error()
1331  *
1332  * Checks the $wp_settings_errors array for any errors declared during the current
1333  * pageload and returns them.
1334  *
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.
1338  *
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)
1342  *
1343  * @since 3.0.0
1344  *
1345  * @global array $wp_settings_errors Storage array of errors registered during this pageload
1346  *
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
1350  */
1351 function get_settings_errors( $setting = '', $sanitize = false ) {
1352         global $wp_settings_errors;
1353
1354         /*
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.
1358          */
1359         if ( $sanitize )
1360                 sanitize_option( $setting, get_option( $setting ) );
1361
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' );
1366         }
1367
1368         // Check global in case errors have been added on this pageload.
1369         if ( ! count( $wp_settings_errors ) )
1370                 return array();
1371
1372         // Filter the results to those of a specific setting if one was set.
1373         if ( $setting ) {
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];
1378                 }
1379                 return $setting_errors;
1380         }
1381
1382         return $wp_settings_errors;
1383 }
1384
1385 /**
1386  * Display settings errors registered by add_settings_error()
1387  *
1388  * Part of the Settings API. Outputs a <div> for each error retrieved by get_settings_errors().
1389  *
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()
1392  *
1393  * The $sanitize option is passed into get_settings_errors() and will re-run the setting sanitization
1394  * on its current value.
1395  *
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.
1400  *
1401  * @since 3.0.0
1402  *
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.
1406  */
1407 function settings_errors( $setting = '', $sanitize = false, $hide_on_update = false ) {
1408
1409         if ( $hide_on_update && ! empty( $_GET['settings-updated'] ) )
1410                 return;
1411
1412         $settings_errors = get_settings_errors( $setting, $sanitize );
1413
1414         if ( empty( $settings_errors ) )
1415                 return;
1416
1417         $output = '';
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";
1424         }
1425         echo $output;
1426 }
1427
1428 /**
1429  * {@internal Missing Short Description}}
1430  *
1431  * @since 2.7.0
1432  *
1433  * @param unknown_type $found_action
1434  */
1435 function find_posts_div($found_action = '') {
1436 ?>
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>
1441                 </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); ?>" />
1446                                 <?php } ?>
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>
1454                         </div>
1455                         <div id="find-posts-response"></div>
1456                 </div>
1457                 <div class="find-box-buttons">
1458                         <?php submit_button( __( 'Select' ), 'button-primary alignright', 'find-posts-submit', false ); ?>
1459                         <div class="clear"></div>
1460                 </div>
1461         </div>
1462 <?php
1463 }
1464
1465 /**
1466  * Display the post password.
1467  *
1468  * The password is passed through {@link esc_attr()} to ensure that it
1469  * is safe for placing in an html attribute.
1470  *
1471  * @uses attr
1472  * @since 2.7.0
1473  */
1474 function the_post_password() {
1475         $post = get_post();
1476         if ( isset( $post->post_password ) )
1477                 echo esc_attr( $post->post_password );
1478 }
1479
1480 /**
1481  * Get the post title.
1482  *
1483  * The post title is fetched and if it is blank then a default string is
1484  * returned.
1485  *
1486  * @since 2.7.0
1487  *
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.
1490  */
1491 function _draft_or_post_title( $post = 0 ) {
1492         $title = get_the_title( $post );
1493         if ( empty( $title ) )
1494                 $title = __( '(no title)' );
1495         return $title;
1496 }
1497
1498 /**
1499  * Display the search query.
1500  *
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.
1503  *
1504  * @uses attr
1505  * @since 2.7.0
1506  *
1507  */
1508 function _admin_search_query() {
1509         echo isset($_REQUEST['s']) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : '';
1510 }
1511
1512 /**
1513  * Generic Iframe header for use with Thickbox
1514  *
1515  * @since 2.7.0
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).
1518  *
1519  */
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);
1524
1525         $current_screen = get_current_screen();
1526
1527         @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
1528         _wp_admin_html_begin();
1529 ?>
1530 <title><?php bloginfo('name') ?> &rsaquo; <?php echo $title ?> &#8212; <?php _e('WordPress'); ?></title>
1531 <?php
1532 wp_enqueue_style( 'colors' );
1533 ?>
1534 <script type="text/javascript">
1535 //<![CDATA[
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(); ?>;
1545 //]]>
1546 </script>
1547 <?php
1548 /** This action is documented in wp-admin/admin-header.php */
1549 do_action( 'admin_enqueue_scripts', $hook_suffix );
1550
1551 /** This action is documented in wp-admin/admin-header.php */
1552 do_action( "admin_print_styles-$hook_suffix" );
1553
1554 /** This action is documented in wp-admin/admin-header.php */
1555 do_action( 'admin_print_styles' );
1556
1557 /** This action is documented in wp-admin/admin-header.php */
1558 do_action( "admin_print_scripts-$hook_suffix" );
1559
1560 /** This action is documented in wp-admin/admin-header.php */
1561 do_action( 'admin_print_scripts' );
1562
1563 /** This action is documented in wp-admin/admin-header.php */
1564 do_action( "admin_head-$hook_suffix" );
1565
1566 /** This action is documented in wp-admin/admin-header.php */
1567 do_action( 'admin_head' );
1568
1569 $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
1570
1571 if ( is_rtl() )
1572         $admin_body_class .= ' rtl';
1573
1574 ?>
1575 </head>
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">
1579 //<![CDATA[
1580 (function(){
1581 var c = document.body.className;
1582 c = c.replace(/no-js/, 'js');
1583 document.body.className = c;
1584 })();
1585 //]]>
1586 </script>
1587 <?php
1588 }
1589
1590 /**
1591  * Generic Iframe footer for use with Thickbox
1592  *
1593  * @since 2.7.0
1594  *
1595  */
1596 function iframe_footer() {
1597         /*
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.
1601          */
1602          ?>
1603         <div class="hidden">
1604 <?php
1605         /** This action is documented in wp-admin/admin-footer.php */
1606         do_action( 'admin_footer', '' );
1607
1608         /** This action is documented in wp-admin/admin-footer.php */
1609         do_action( 'admin_print_footer_scripts' );
1610 ?>
1611         </div>
1612 <script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script>
1613 </body>
1614 </html>
1615 <?php
1616 }
1617
1618 function _post_states($post) {
1619         $post_states = array();
1620         if ( isset( $_REQUEST['post_status'] ) )
1621                 $post_status = $_REQUEST['post_status'];
1622         else
1623                 $post_status = '';
1624
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');
1636
1637         /**
1638          * Filter the default post display states used in the Posts list table.
1639          *
1640          * @since 2.8.0
1641          *
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.
1645          */
1646         $post_states = apply_filters( 'display_post_states', $post_states, $post );
1647
1648         if ( ! empty($post_states) ) {
1649                 $state_count = count($post_states);
1650                 $i = 0;
1651                 echo ' - ';
1652                 foreach ( $post_states as $state ) {
1653                         ++$i;
1654                         ( $i == $state_count ) ? $sep = '' : $sep = ', ';
1655                         echo "<span class='post-state'>$state$sep</span>";
1656                 }
1657         }
1658
1659 }
1660
1661 function _media_states( $post ) {
1662         $media_states = array();
1663         $stylesheet = get_option('stylesheet');
1664
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' );
1669         }
1670
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' );
1675         }
1676
1677         /**
1678          * Filter the default media display states for items in the Media list table.
1679          *
1680          * @since 3.2.0
1681          *
1682          * @param array $media_states An array of media states. Default 'Header Image',
1683          *                            'Background Image'.
1684          */
1685         $media_states = apply_filters( 'display_media_states', $media_states );
1686
1687         if ( ! empty( $media_states ) ) {
1688                 $state_count = count( $media_states );
1689                 $i = 0;
1690                 echo ' - ';
1691                 foreach ( $media_states as $state ) {
1692                         ++$i;
1693                         ( $i == $state_count ) ? $sep = '' : $sep = ', ';
1694                         echo "<span class='post-state'>$state$sep</span>";
1695                 }
1696         }
1697 }
1698
1699 /**
1700  * Test support for compressing JavaScript from PHP
1701  *
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.
1706  *
1707  * @since 2.8.0
1708  */
1709 function compression_test() {
1710 ?>
1711         <script type="text/javascript">
1712         /* <![CDATA[ */
1713         var testCompression = {
1714                 get : function(test) {
1715                         var x;
1716                         if ( window.XMLHttpRequest ) {
1717                                 x = new XMLHttpRequest();
1718                         } else {
1719                                 try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
1720                         }
1721
1722                         if (x) {
1723                                 x.onreadystatechange = function() {
1724                                         var r, h;
1725                                         if ( x.readyState == 4 ) {
1726                                                 r = x.responseText.substr(0, 18);
1727                                                 h = x.getResponseHeader('Content-Encoding');
1728                                                 testCompression.check(r, h, test);
1729                                         }
1730                                 }
1731
1732                                 x.open('GET', ajaxurl + '?action=wp-compression-test&test='+test+'&'+(new Date()).getTime(), true);
1733                                 x.send('');
1734                         }
1735                 },
1736
1737                 check : function(r, h, test) {
1738                         if ( ! r && ! test )
1739                                 this.get(1);
1740
1741                         if ( 1 == test ) {
1742                                 if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) )
1743                                         this.get('no');
1744                                 else
1745                                         this.get(2);
1746
1747                                 return;
1748                         }
1749
1750                         if ( 2 == test ) {
1751                                 if ( '"wpCompressionTest' == r )
1752                                         this.get('yes');
1753                                 else
1754                                         this.get('no');
1755                         }
1756                 }
1757         };
1758         testCompression.check();
1759         /* ]]> */
1760         </script>
1761 <?php
1762 }
1763
1764 /**
1765  * Echoes a submit button, with provided text and appropriate class(es).
1766  *
1767  * @since 3.1.0
1768  *
1769  * @see get_submit_button()
1770  *
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.
1785  */
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 );
1788 }
1789
1790 /**
1791  * Returns a submit button, with provided text and appropriate class
1792  *
1793  * @since 3.1.0
1794  *
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.
1806  */
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 );
1810
1811         $button_shorthand = array( 'primary', 'small', 'large' );
1812         $classes = array( 'button' );
1813         foreach ( $type as $t ) {
1814                 if ( 'secondary' === $t || 'button-secondary' === $t )
1815                         continue;
1816                 $classes[] = in_array( $t, $button_shorthand ) ? 'button-' . $t : $t;
1817         }
1818         $class = implode( ' ', array_unique( $classes ) );
1819
1820         if ( 'delete' === $type )
1821                 $class = 'button-secondary delete';
1822
1823         $text = $text ? $text : __( 'Save Changes' );
1824
1825         // Default the id attribute to $name unless an id was specifically provided in $other_attributes
1826         $id = $name;
1827         if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) {
1828                 $id = $other_attributes['id'];
1829                 unset( $other_attributes['id'] );
1830         }
1831
1832         $attributes = '';
1833         if ( is_array( $other_attributes ) ) {
1834                 foreach ( $other_attributes as $attribute => $value ) {
1835                         $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
1836                 }
1837         } else if ( !empty( $other_attributes ) ) { // Attributes provided as a string
1838                 $attributes = $other_attributes;
1839         }
1840
1841         $button = '<input type="submit" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" class="' . esc_attr( $class );
1842         $button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />';
1843
1844         if ( $wrap ) {
1845                 $button = '<p class="submit">' . $button . '</p>';
1846         }
1847
1848         return $button;
1849 }
1850
1851 function _wp_admin_html_begin() {
1852         global $is_IE;
1853
1854         $admin_html_class = ( is_admin_bar_showing() ) ? 'wp-toolbar' : '';
1855
1856         if ( $is_IE )
1857                 @header('X-UA-Compatible: IE=edge');
1858
1859 /**
1860  * Fires inside the HTML tag in the admin header.
1861  *
1862  * @since 2.2.0
1863  */
1864 ?>
1865 <!DOCTYPE html>
1866 <!--[if IE 8]>
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(); ?>>
1868 <![endif]-->
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(); ?>>
1872 <!--<![endif]-->
1873 <head>
1874 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
1875 <?php
1876 }
1877
1878 final class WP_Internal_Pointers {
1879         /**
1880          * Initializes the new feature pointers.
1881          *
1882          * @since 3.3.0
1883          *
1884          * All pointers can be disabled using the following:
1885          *     remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
1886          *
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' ) );
1889          */
1890         public static function enqueue_scripts( $hook_suffix ) {
1891                 /*
1892                  * Register feature pointers
1893                  * Format: array( hook_suffix => pointer_id )
1894                  */
1895
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',
1902                 );
1903
1904                 // Check if screen related pointer is registered
1905                 if ( empty( $registered_pointers[ $hook_suffix ] ) )
1906                         return;
1907
1908                 $pointers = (array) $registered_pointers[ $hook_suffix ];
1909
1910                 $caps_required = array(
1911                         'wp350_media' => array( 'upload_files' ),
1912                         'wp390_widgets' => array( 'edit_theme_options' ),
1913                 );
1914
1915                 // Get dismissed pointers
1916                 $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
1917
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 ) )
1923                                                 continue 2;
1924                                 }
1925                         }
1926
1927                         // Bind pointer print function
1928                         add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) );
1929                         $got_pointers = true;
1930                 }
1931
1932                 if ( ! $got_pointers )
1933                         return;
1934
1935                 // Add pointers script and style to queue
1936                 wp_enqueue_style( 'wp-pointer' );
1937                 wp_enqueue_script( 'wp-pointer' );
1938         }
1939
1940         /**
1941          * Print the pointer javascript data.
1942          *
1943          * @since 3.3.0
1944          *
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).
1948          */
1949         private static function print_js( $pointer_id, $selector, $args ) {
1950                 if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) )
1951                         return;
1952
1953                 ?>
1954                 <script type="text/javascript">
1955                 //<![CDATA[
1956                 (function($){
1957                         var options = <?php echo json_encode( $args ); ?>, setup;
1958
1959                         if ( ! options )
1960                                 return;
1961
1962                         options = $.extend( options, {
1963                                 close: function() {
1964                                         $.post( ajaxurl, {
1965                                                 pointer: '<?php echo $pointer_id; ?>',
1966                                                 action: 'dismiss-wp-pointer'
1967                                         });
1968                                 }
1969                         });
1970
1971                         setup = function() {
1972                                 $('<?php echo $selector; ?>').first().pointer( options ).pointer('open');
1973                         };
1974
1975                         if ( options.position && options.position.defer_loading )
1976                                 $(window).bind( 'load.wp-pointers', setup );
1977                         else
1978                                 $(document).ready( setup );
1979
1980                 })( jQuery );
1981                 //]]>
1982                 </script>
1983                 <?php
1984         }
1985
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() {}
1991
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>';
1995
1996                 self::print_js( 'wp350_media', '.insert-media', array(
1997                         'content'  => $content,
1998                         'position' => array( 'edge' => is_rtl() ? 'right' : 'left', 'align' => 'center' ),
1999                 ) );
2000         }
2001
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>';
2005
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' ),
2009                 ) );
2010         }
2011
2012         public static function pointer_wp360_locks() {
2013                 if ( ! is_multi_author() ) {
2014                         return;
2015                 }
2016
2017                 $content  = '<h3>' . __( 'Edit Lock' ) . '</h3>';
2018                 $content .= '<p>' . __( 'Someone else is editing this. No need to refresh; the lock will disappear when they&#8217;re done.' ) . '</p>';
2019
2020                 self::print_js( 'wp360_locks', 'tr.wp-locked .locked-indicator', array(
2021                         'content' => $content,
2022                         'position' => array( 'edge' => 'left', 'align' => 'left' ),
2023                 ) );
2024         }
2025
2026         public static function pointer_wp390_widgets() {
2027                 if ( ! current_theme_supports( 'widgets' ) ) {
2028                         return;
2029                 }
2030
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&#8217;re ready.' ) . '</p>';
2033
2034                 if ( 'themes' === get_current_screen()->id ) {
2035                         $selector = '.theme.active .customize';
2036                         $position = array( 'edge' => is_rtl() ? 'right' : 'left', 'align' => 'center' );
2037                 } else {
2038                         $selector = 'a[href="customize.php"]';
2039                         if ( is_rtl() ) {
2040                                 $position = array( 'edge' => 'right', 'align' => 'center', 'my' => 'right-5px' );
2041                         } else {
2042                                 $position = array( 'edge' => 'left', 'align' => 'center', 'my' => 'left-5px' );
2043                         }
2044                 }
2045
2046                 self::print_js( 'wp390_widgets', $selector, array(
2047                         'content' => $content,
2048                         'position' => $position,
2049                 ) );
2050         }
2051
2052         /**
2053          * Prevents new users from seeing existing 'new feature' pointers.
2054          *
2055          * @since 3.3.0
2056          */
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' );
2059         }
2060 }
2061
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' ) );
2064
2065 /**
2066  * Convert a screen string to a screen object
2067  *
2068  * @since 3.0.0
2069  *
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.
2072  */
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' );
2077         }
2078
2079         return WP_Screen::get( $hook_name );
2080 }
2081
2082 /**
2083  * Output the HTML for restoring the post data from DOM storage
2084  *
2085  * @since 3.6.0
2086  * @access private
2087  */
2088 function _local_storage_notice() {
2089         ?>
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>
2094         </p>
2095         <p class="undo-restore hidden">
2096                 <?php _e('Post restored successfully.'); ?>
2097                 <a class="undo-restore-backup" href="#"><?php _e('Undo.'); ?></a>
2098         </p>
2099         </div>
2100         <?php
2101 }
2102
2103 /**
2104  * Output a HTML element with a star rating for a given rating.
2105  *
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.
2109  *
2110  * @since 3.8.0
2111  * @param array $args {
2112  *     Optional. Array of star ratings arguments.
2113  *
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.
2119  * }
2120  */
2121 function wp_star_rating( $args = array() ) {
2122         $defaults = array(
2123                 'rating' => 0,
2124                 'type' => 'rating',
2125                 'number' => 0,
2126         );
2127         $r = wp_parse_args( $args, $defaults );
2128
2129         // Non-english decimal places when the $rating is coming from a string
2130         $rating = str_replace( ',', '.', $r['rating'] );
2131
2132         // Convert Percentage to star rating, 0..5 in .5 increments
2133         if ( 'percent' == $r['type'] ) {
2134                 $rating = round( $rating / 10, 0 ) / 2;
2135         }
2136
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;
2141
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'] ) );
2146         } else {
2147                 /* translators: 1: The rating */
2148                 $title = sprintf( __( '%s rating' ), number_format_i18n( $rating, 1 ) );
2149         }
2150
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);
2156         echo '</div>';
2157 }