]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/template.php
425e40b0f09bef70bfb25aa619729f0ce54627a5
[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  * @since 2.5.1
19  *
20  * @see Walker
21  * @see wp_category_checklist()
22  * @see wp_terms_checklist()
23  */
24 class Walker_Category_Checklist extends Walker {
25         public $tree_type = 'category';
26         public $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
27
28         /**
29          * Starts the list before the elements are added.
30          *
31          * @see Walker:start_lvl()
32          *
33          * @since 2.5.1
34          *
35          * @param string $output Passed by reference. Used to append additional content.
36          * @param int    $depth  Depth of category. Used for tab indentation.
37          * @param array  $args   An array of arguments. @see wp_terms_checklist()
38          */
39         public function start_lvl( &$output, $depth = 0, $args = array() ) {
40                 $indent = str_repeat("\t", $depth);
41                 $output .= "$indent<ul class='children'>\n";
42         }
43
44         /**
45          * Ends the list of after the elements are added.
46          *
47          * @see Walker::end_lvl()
48          *
49          * @since 2.5.1
50          *
51          * @param string $output Passed by reference. Used to append additional content.
52          * @param int    $depth  Depth of category. Used for tab indentation.
53          * @param array  $args   An array of arguments. @see wp_terms_checklist()
54          */
55         public function end_lvl( &$output, $depth = 0, $args = array() ) {
56                 $indent = str_repeat("\t", $depth);
57                 $output .= "$indent</ul>\n";
58         }
59
60         /**
61          * Start the element output.
62          *
63          * @see Walker::start_el()
64          *
65          * @since 2.5.1
66          *
67          * @param string $output   Passed by reference. Used to append additional content.
68          * @param object $category The current term object.
69          * @param int    $depth    Depth of the term in reference to parents. Default 0.
70          * @param array  $args     An array of arguments. @see wp_terms_checklist()
71          * @param int    $id       ID of the current term.
72          */
73         public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
74                 if ( empty( $args['taxonomy'] ) ) {
75                         $taxonomy = 'category';
76                 } else {
77                         $taxonomy = $args['taxonomy'];
78                 }
79
80                 if ( $taxonomy == 'category' ) {
81                         $name = 'post_category';
82                 } else {
83                         $name = 'tax_input[' . $taxonomy . ']';
84                 }
85                 $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
86                 $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';
87
88                 $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
89
90                 /** This filter is documented in wp-includes/category-template.php */
91                 $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
92                         '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' .
93                         checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) .
94                         disabled( empty( $args['disabled'] ), false, false ) . ' /> ' .
95                         esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>';
96         }
97
98         /**
99          * Ends the element output, if needed.
100          *
101          * @see Walker::end_el()
102          *
103          * @since 2.5.1
104          *
105          * @param string $output   Passed by reference. Used to append additional content.
106          * @param object $category The current term object.
107          * @param int    $depth    Depth of the term in reference to parents. Default 0.
108          * @param array  $args     An array of arguments. @see wp_terms_checklist()
109          */
110         public function end_el( &$output, $category, $depth = 0, $args = array() ) {
111                 $output .= "</li>\n";
112         }
113 }
114
115 /**
116  * Output an unordered list of checkbox input elements labelled
117  * with category names.
118  *
119  * @since 2.5.1
120  *
121  * @todo Properly document optional arguments as such.
122  *
123  * @see wp_terms_checklist()
124  *
125  * @param int $post_id Mark categories associated with this post as checked. $selected_cats must not be an array.
126  * @param int $descendants_and_self ID of the category to output along with its descendents.
127  * @param bool|array $selected_cats List of categories to mark as checked.
128  * @param bool|array $popular_cats Override the list of categories that receive the "popular-category" class.
129  * @param object $walker Walker object to use to build the output.
130  * @param bool $checked_ontop Move checked items out of the hierarchy and to the top of the list.
131  */
132 function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) {
133         wp_terms_checklist( $post_id, array(
134                 'taxonomy' => 'category',
135                 'descendants_and_self' => $descendants_and_self,
136                 'selected_cats' => $selected_cats,
137                 'popular_cats' => $popular_cats,
138                 'walker' => $walker,
139                 'checked_ontop' => $checked_ontop
140         ) );
141 }
142
143 /**
144  * Output an unordered list of checkbox input elements labelled with term names.
145  *
146  * Taxonomy independent version of {@see wp_category_checklist()}.
147  *
148  * @since 3.0.0
149  *
150  * @todo Properly document optional default arguments.
151  *
152  * @param int   $post_id Post ID.
153  * @param array $args    Arguments to form the terms checklist.
154  */
155 function wp_terms_checklist( $post_id = 0, $args = array() ) {
156         $defaults = array(
157                 'descendants_and_self' => 0,
158                 'selected_cats' => false,
159                 'popular_cats' => false,
160                 'walker' => null,
161                 'taxonomy' => 'category',
162                 'checked_ontop' => true
163         );
164
165         /**
166          * Filter the taxonomy terms checklist arguments.
167          *
168          * @since 3.4.0
169          *
170          * @see wp_terms_checklist()
171          *
172          * @param array $args    An array of arguments.
173          * @param int   $post_id The post ID.
174          */
175         $params = apply_filters( 'wp_terms_checklist_args', $args, $post_id );
176
177         $r = wp_parse_args( $params, $defaults );
178
179         if ( empty( $r['walker'] ) || ! is_a( $r['walker'], 'Walker' ) ) {
180                 $walker = new Walker_Category_Checklist;
181         } else {
182                 $walker = $r['walker'];
183         }
184
185         $taxonomy = $r['taxonomy'];
186         $descendants_and_self = (int) $r['descendants_and_self'];
187
188         $args = array( 'taxonomy' => $taxonomy );
189
190         $tax = get_taxonomy( $taxonomy );
191         $args['disabled'] = ! current_user_can( $tax->cap->assign_terms );
192
193         if ( is_array( $r['selected_cats'] ) ) {
194                 $args['selected_cats'] = $r['selected_cats'];
195         } elseif ( $post_id ) {
196                 $args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) );
197         } else {
198                 $args['selected_cats'] = array();
199         }
200         if ( is_array( $r['popular_cats'] ) ) {
201                 $args['popular_cats'] = $r['popular_cats'];
202         } else {
203                 $args['popular_cats'] = get_terms( $taxonomy, array(
204                         'fields' => 'ids',
205                         'orderby' => 'count',
206                         'order' => 'DESC',
207                         'number' => 10,
208                         'hierarchical' => false
209                 ) );
210         }
211         if ( $descendants_and_self ) {
212                 $categories = (array) get_terms( $taxonomy, array(
213                         'child_of' => $descendants_and_self,
214                         'hierarchical' => 0,
215                         'hide_empty' => 0
216                 ) );
217                 $self = get_term( $descendants_and_self, $taxonomy );
218                 array_unshift( $categories, $self );
219         } else {
220                 $categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) );
221         }
222
223         if ( $r['checked_ontop'] ) {
224                 // 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)
225                 $checked_categories = array();
226                 $keys = array_keys( $categories );
227
228                 foreach( $keys as $k ) {
229                         if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) {
230                                 $checked_categories[] = $categories[$k];
231                                 unset( $categories[$k] );
232                         }
233                 }
234
235                 // Put checked cats on top
236                 echo call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) );
237         }
238         // Then the rest of them
239         echo call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) );
240 }
241
242 /**
243  * Retrieve a list of the most popular terms from the specified taxonomy.
244  *
245  * If the $echo argument is true then the elements for a list of checkbox
246  * `<input>` elements labelled with the names of the selected terms is output.
247  * If the $post_ID global isn't empty then the terms associated with that
248  * post will be marked as checked.
249  *
250  * @since 2.5.0
251  *
252  * @param string $taxonomy Taxonomy to retrieve terms from.
253  * @param int $default Unused.
254  * @param int $number Number of terms to retrieve. Defaults to 10.
255  * @param bool $echo Optionally output the list as well. Defaults to true.
256  * @return array List of popular term IDs.
257  */
258 function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
259         $post = get_post();
260
261         if ( $post && $post->ID )
262                 $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields'=>'ids'));
263         else
264                 $checked_terms = array();
265
266         $terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
267
268         $tax = get_taxonomy($taxonomy);
269
270         $popular_ids = array();
271         foreach ( (array) $terms as $term ) {
272                 $popular_ids[] = $term->term_id;
273                 if ( !$echo ) // hack for AJAX use
274                         continue;
275                 $id = "popular-$taxonomy-$term->term_id";
276                 $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : '';
277                 ?>
278
279                 <li id="<?php echo $id; ?>" class="popular-category">
280                         <label class="selectit">
281                                 <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 ) ); ?> />
282                                 <?php
283                                 /** This filter is documented in wp-includes/category-template.php */
284                                 echo esc_html( apply_filters( 'the_category', $term->name ) );
285                                 ?>
286                         </label>
287                 </li>
288
289                 <?php
290         }
291         return $popular_ids;
292 }
293
294 /**
295  * {@internal Missing Short Description}}
296  *
297  * @since 2.5.1
298  *
299  * @param int $link_id
300  */
301 function wp_link_category_checklist( $link_id = 0 ) {
302         $default = 1;
303
304         if ( $link_id ) {
305                 $checked_categories = wp_get_link_cats( $link_id );
306                 // No selected categories, strange
307                 if ( ! count( $checked_categories ) )
308                         $checked_categories[] = $default;
309         } else {
310                 $checked_categories[] = $default;
311         }
312
313         $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) );
314
315         if ( empty( $categories ) )
316                 return;
317
318         foreach ( $categories as $category ) {
319                 $cat_id = $category->term_id;
320
321                 /** This filter is documented in wp-includes/category-template.php */
322                 $name = esc_html( apply_filters( 'the_category', $category->name ) );
323                 $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : '';
324                 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>";
325         }
326 }
327
328 // adds hidden fields with the data for use in the inline editor for posts and pages
329 /**
330  * {@internal Missing Short Description}}
331  *
332  * @since 2.7.0
333  *
334  * @param WP_Post $post
335  */
336 function get_inline_data($post) {
337         $post_type_object = get_post_type_object($post->post_type);
338         if ( ! current_user_can( 'edit_post', $post->ID ) )
339                 return;
340
341         $title = esc_textarea( trim( $post->post_title ) );
342
343         /** This filter is documented in wp-admin/edit-tag-form.php */
344         echo '
345 <div class="hidden" id="inline_' . $post->ID . '">
346         <div class="post_title">' . $title . '</div>
347         <div class="post_name">' . apply_filters( 'editable_slug', $post->post_name ) . '</div>
348         <div class="post_author">' . $post->post_author . '</div>
349         <div class="comment_status">' . esc_html( $post->comment_status ) . '</div>
350         <div class="ping_status">' . esc_html( $post->ping_status ) . '</div>
351         <div class="_status">' . esc_html( $post->post_status ) . '</div>
352         <div class="jj">' . mysql2date( 'd', $post->post_date, false ) . '</div>
353         <div class="mm">' . mysql2date( 'm', $post->post_date, false ) . '</div>
354         <div class="aa">' . mysql2date( 'Y', $post->post_date, false ) . '</div>
355         <div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div>
356         <div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div>
357         <div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div>
358         <div class="post_password">' . esc_html( $post->post_password ) . '</div>';
359
360         if ( $post_type_object->hierarchical )
361                 echo '<div class="post_parent">' . $post->post_parent . '</div>';
362
363         if ( $post->post_type == 'page' )
364                 echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>';
365
366         if ( post_type_supports( $post->post_type, 'page-attributes' ) )
367                 echo '<div class="menu_order">' . $post->menu_order . '</div>';
368
369         $taxonomy_names = get_object_taxonomies( $post->post_type );
370         foreach ( $taxonomy_names as $taxonomy_name) {
371                 $taxonomy = get_taxonomy( $taxonomy_name );
372
373                 if ( $taxonomy->hierarchical && $taxonomy->show_ui ) {
374
375                         $terms = get_object_term_cache( $post->ID, $taxonomy_name );
376                         if ( false === $terms ) {
377                                 $terms = wp_get_object_terms( $post->ID, $taxonomy_name );
378                                 wp_cache_add( $post->ID, $terms, $taxonomy_name . '_relationships' );
379                         }
380                         $term_ids = empty( $terms ) ? array() : wp_list_pluck( $terms, 'term_id' );
381
382                         echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode( ',', $term_ids ) . '</div>';
383
384                 } elseif ( $taxonomy->show_ui ) {
385
386                         echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">'
387                                 . esc_html( str_replace( ',', ', ', get_terms_to_edit( $post->ID, $taxonomy_name ) ) ) . '</div>';
388
389                 }
390         }
391
392         if ( !$post_type_object->hierarchical )
393                 echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
394
395         if ( post_type_supports( $post->post_type, 'post-formats' ) )
396                 echo '<div class="post_format">' . esc_html( get_post_format( $post->ID ) ) . '</div>';
397
398         echo '</div>';
399 }
400
401 /**
402  * {@internal Missing Short Description}}
403  *
404  * @since 2.7.0
405  *
406  * @param int $position
407  * @param bool $checkbox
408  * @param string $mode
409  * @param bool $table_row
410  */
411 function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single', $table_row = true) {
412
413         /**
414          * Filter the in-line comment reply-to form output in the Comments
415          * list table.
416          *
417          * Returning a non-empty value here will short-circuit display
418          * of the in-line comment-reply form in the Comments list table,
419          * echoing the returned value instead.
420          *
421          * @since 2.7.0
422          *
423          * @see wp_comment_reply()
424          *
425          * @param string $content The reply-to form content.
426          * @param array  $args    An array of default args.
427          */
428         $content = apply_filters( 'wp_comment_reply', '', array( 'position' => $position, 'checkbox' => $checkbox, 'mode' => $mode ) );
429
430         if ( ! empty($content) ) {
431                 echo $content;
432                 return;
433         }
434
435         if ( $mode == 'single' ) {
436                 $wp_list_table = _get_list_table('WP_Post_Comments_List_Table');
437         } else {
438                 $wp_list_table = _get_list_table('WP_Comments_List_Table');
439         }
440
441 ?>
442 <form method="get" action="">
443 <?php if ( $table_row ) : ?>
444 <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">
445 <?php else : ?>
446 <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;">
447 <?php endif; ?>
448         <div id="replyhead" style="display:none;"><h5><?php _e( 'Reply to Comment' ); ?></h5></div>
449         <div id="addhead" style="display:none;"><h5><?php _e('Add new Comment'); ?></h5></div>
450         <div id="edithead" style="display:none;">
451                 <div class="inside">
452                 <label for="author"><?php _e('Name') ?></label>
453                 <input type="text" name="newcomment_author" size="50" value="" id="author" />
454                 </div>
455
456                 <div class="inside">
457                 <label for="author-email"><?php _e('E-mail') ?></label>
458                 <input type="text" name="newcomment_author_email" size="50" value="" id="author-email" />
459                 </div>
460
461                 <div class="inside">
462                 <label for="author-url"><?php _e('URL') ?></label>
463                 <input type="text" id="author-url" name="newcomment_author_url" class="code" size="103" value="" />
464                 </div>
465                 <div style="clear:both;"></div>
466         </div>
467
468         <div id="replycontainer">
469         <?php
470         $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' );
471         wp_editor( '', 'replycontent', array( 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings ) );
472         ?>
473         </div>
474
475         <p id="replysubmit" class="submit">
476         <a href="#comments-form" class="save button-primary alignright">
477         <span id="addbtn" style="display:none;"><?php _e('Add Comment'); ?></span>
478         <span id="savebtn" style="display:none;"><?php _e('Update Comment'); ?></span>
479         <span id="replybtn" style="display:none;"><?php _e('Submit Reply'); ?></span></a>
480         <a href="#comments-form" class="cancel button-secondary alignleft"><?php _e('Cancel'); ?></a>
481         <span class="waiting spinner"></span>
482         <span class="error" style="display:none;"></span>
483         <br class="clear" />
484         </p>
485
486         <input type="hidden" name="user_ID" id="user_ID" value="<?php echo get_current_user_id(); ?>" />
487         <input type="hidden" name="action" id="action" value="" />
488         <input type="hidden" name="comment_ID" id="comment_ID" value="" />
489         <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" />
490         <input type="hidden" name="status" id="status" value="" />
491         <input type="hidden" name="position" id="position" value="<?php echo $position; ?>" />
492         <input type="hidden" name="checkbox" id="checkbox" value="<?php echo $checkbox ? 1 : 0; ?>" />
493         <input type="hidden" name="mode" id="mode" value="<?php echo esc_attr($mode); ?>" />
494         <?php
495                 wp_nonce_field( 'replyto-comment', '_ajax_nonce-replyto-comment', false );
496                 if ( current_user_can( 'unfiltered_html' ) )
497                         wp_nonce_field( 'unfiltered-html-comment', '_wp_unfiltered_html_comment', false );
498         ?>
499 <?php if ( $table_row ) : ?>
500 </td></tr></tbody></table>
501 <?php else : ?>
502 </div></div>
503 <?php endif; ?>
504 </form>
505 <?php
506 }
507
508 /**
509  * Output 'undo move to trash' text for comments
510  *
511  * @since 2.9.0
512  */
513 function wp_comment_trashnotice() {
514 ?>
515 <div class="hidden" id="trash-undo-holder">
516         <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>
517 </div>
518 <div class="hidden" id="spam-undo-holder">
519         <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>
520 </div>
521 <?php
522 }
523
524 /**
525  * {@internal Missing Short Description}}
526  *
527  * @since 1.2.0
528  *
529  * @param array $meta
530  */
531 function list_meta( $meta ) {
532         // Exit if no meta
533         if ( ! $meta ) {
534                 echo '
535 <table id="list-table" style="display: none;">
536         <thead>
537         <tr>
538                 <th class="left">' . _x( 'Name', 'meta name' ) . '</th>
539                 <th>' . __( 'Value' ) . '</th>
540         </tr>
541         </thead>
542         <tbody id="the-list" data-wp-lists="list:meta">
543         <tr><td></td></tr>
544         </tbody>
545 </table>'; //TBODY needed for list-manipulation JS
546                 return;
547         }
548         $count = 0;
549 ?>
550 <table id="list-table">
551         <thead>
552         <tr>
553                 <th class="left"><?php _ex( 'Name', 'meta name' ) ?></th>
554                 <th><?php _e( 'Value' ) ?></th>
555         </tr>
556         </thead>
557         <tbody id='the-list' data-wp-lists='list:meta'>
558 <?php
559         foreach ( $meta as $entry )
560                 echo _list_meta_row( $entry, $count );
561 ?>
562         </tbody>
563 </table>
564 <?php
565 }
566
567 /**
568  * {@internal Missing Short Description}}
569  *
570  * @since 2.5.0
571  *
572  * @param array $entry
573  * @param int   $count
574  * @return string
575  */
576 function _list_meta_row( $entry, &$count ) {
577         static $update_nonce = false;
578
579         if ( is_protected_meta( $entry['meta_key'], 'post' ) )
580                 return;
581
582         if ( !$update_nonce )
583                 $update_nonce = wp_create_nonce( 'add-meta' );
584
585         $r = '';
586         ++ $count;
587         if ( $count % 2 )
588                 $style = 'alternate';
589         else
590                 $style = '';
591
592         if ( is_serialized( $entry['meta_value'] ) ) {
593                 if ( is_serialized_string( $entry['meta_value'] ) ) {
594                         // This is a serialized string, so we should display it.
595                         $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
596                 } else {
597                         // This is a serialized array/object so we should NOT display it.
598                         --$count;
599                         return;
600                 }
601         }
602
603         $entry['meta_key'] = esc_attr($entry['meta_key']);
604         $entry['meta_value'] = esc_textarea( $entry['meta_value'] ); // using a <textarea />
605         $entry['meta_id'] = (int) $entry['meta_id'];
606
607         $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
608
609         $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
610         $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']}' />";
611
612         $r .= "\n\t\t<div class='submit'>";
613         $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" ) );
614         $r .= "\n\t\t";
615         $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" ) );
616         $r .= "</div>";
617         $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
618         $r .= "</td>";
619
620         $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>";
621         return $r;
622 }
623
624 /**
625  * Prints the form in the Custom Fields meta box.
626  *
627  * @since 1.2.0
628  *
629  * @param WP_Post $post Optional. The post being edited.
630  */
631 function meta_form( $post = null ) {
632         global $wpdb;
633         $post = get_post( $post );
634
635         /**
636          * Filter the number of custom fields to retrieve for the drop-down
637          * in the Custom Fields meta box.
638          *
639          * @since 2.1.0
640          *
641          * @param int $limit Number of custom fields to retrieve. Default 30.
642          */
643         $limit = apply_filters( 'postmeta_form_limit', 30 );
644         $sql = "SELECT meta_key
645                 FROM $wpdb->postmeta
646                 GROUP BY meta_key
647                 HAVING meta_key NOT LIKE %s
648                 ORDER BY meta_key
649                 LIMIT %d";
650         $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) );
651         if ( $keys ) {
652                 natcasesort( $keys );
653                 $meta_key_input_id = 'metakeyselect';
654         } else {
655                 $meta_key_input_id = 'metakeyinput';
656         }
657 ?>
658 <p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p>
659 <table id="newmeta">
660 <thead>
661 <tr>
662 <th class="left"><label for="<?php echo $meta_key_input_id; ?>"><?php _ex( 'Name', 'meta name' ) ?></label></th>
663 <th><label for="metavalue"><?php _e( 'Value' ) ?></label></th>
664 </tr>
665 </thead>
666
667 <tbody>
668 <tr>
669 <td id="newmetaleft" class="left">
670 <?php if ( $keys ) { ?>
671 <select id="metakeyselect" name="metakeyselect">
672 <option value="#NONE#"><?php _e( '&mdash; Select &mdash;' ); ?></option>
673 <?php
674
675         foreach ( $keys as $key ) {
676                 if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $post->ID, $key ) )
677                         continue;
678                 echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>";
679         }
680 ?>
681 </select>
682 <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" value="" />
683 <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
684 <span id="enternew"><?php _e('Enter new'); ?></span>
685 <span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a>
686 <?php } else { ?>
687 <input type="text" id="metakeyinput" name="metakeyinput" value="" />
688 <?php } ?>
689 </td>
690 <td><textarea id="metavalue" name="metavalue" rows="2" cols="25"></textarea></td>
691 </tr>
692
693 <tr><td colspan="2">
694 <div class="submit">
695 <?php submit_button( __( 'Add Custom Field' ), 'secondary', 'addmeta', false, array( 'id' => 'newmeta-submit', 'data-wp-lists' => 'add:the-list:newmeta' ) ); ?>
696 </div>
697 <?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?>
698 </td></tr>
699 </tbody>
700 </table>
701 <?php
702
703 }
704
705 /**
706  * Print out HTML form date elements for editing post or comment publish date.
707  *
708  * @since 0.71
709  *
710  * @param int $edit      Accepts 1|true for editing the date, 0|false for adding the date.
711  * @param int $for_post  Accepts 1|true for applying the date to a post, 0|false for a comment.
712  * @param int $tab_index The tabindex attribute to add. Default 0.
713  * @param int $multi     Optional. Whether the additional fields and buttons should be added.
714  *                            Default 0|false.
715  */
716 function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
717         global $wp_locale, $comment;
718         $post = get_post();
719
720         if ( $for_post )
721                 $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );
722
723         $tab_index_attribute = '';
724         if ( (int) $tab_index > 0 )
725                 $tab_index_attribute = " tabindex=\"$tab_index\"";
726
727         // todo: Remove this?
728         // 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 />';
729
730         $time_adj = current_time('timestamp');
731         $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
732         $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
733         $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
734         $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
735         $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
736         $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
737         $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
738
739         $cur_jj = gmdate( 'd', $time_adj );
740         $cur_mm = gmdate( 'm', $time_adj );
741         $cur_aa = gmdate( 'Y', $time_adj );
742         $cur_hh = gmdate( 'H', $time_adj );
743         $cur_mn = gmdate( 'i', $time_adj );
744
745         $month = '<label for="mm" class="screen-reader-text">' . __( 'Month' ) . '</label><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n";
746         for ( $i = 1; $i < 13; $i = $i +1 ) {
747                 $monthnum = zeroise($i, 2);
748                 $month .= "\t\t\t" . '<option value="' . $monthnum . '" ' . selected( $monthnum, $mm, false ) . '>';
749                 /* translators: 1: month number (01, 02, etc.), 2: month abbreviation */
750                 $month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) ) . "</option>\n";
751         }
752         $month .= '</select>';
753
754         $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" />';
755         $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" />';
756         $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" />';
757         $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" />';
758
759         echo '<div class="timestamp-wrap">';
760         /* translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */
761         printf( __( '%1$s %2$s, %3$s @ %4$s : %5$s' ), $month, $day, $year, $hour, $minute );
762
763         echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
764
765         if ( $multi ) return;
766
767         echo "\n\n";
768         $map = array(
769                 'mm' => array( $mm, $cur_mm ),
770                 'jj' => array( $jj, $cur_jj ),
771                 'aa' => array( $aa, $cur_aa ),
772                 'hh' => array( $hh, $cur_hh ),
773                 'mn' => array( $mn, $cur_mn ),
774         );
775         foreach ( $map as $timeunit => $value ) {
776                 list( $unit, $curr ) = $value;
777
778                 echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $unit . '" />' . "\n";
779                 $cur_timeunit = 'cur_' . $timeunit;
780                 echo '<input type="hidden" id="' . $cur_timeunit . '" name="' . $cur_timeunit . '" value="' . $curr . '" />' . "\n";
781         }
782 ?>
783
784 <p>
785 <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a>
786 <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js button-cancel"><?php _e('Cancel'); ?></a>
787 </p>
788 <?php
789 }
790
791 /**
792  * Print out option HTML elements for the page templates drop-down.
793  *
794  * @since 1.5.0
795  *
796  * @param string $default Optional. The template file name. Default empty.
797  */
798 function page_template_dropdown( $default = '' ) {
799         $templates = get_page_templates( get_post() );
800         ksort( $templates );
801         foreach ( array_keys( $templates ) as $template ) {
802                 $selected = selected( $default, $templates[ $template ], false );
803                 echo "\n\t<option value='" . $templates[ $template ] . "' $selected>$template</option>";
804         }
805 }
806
807 /**
808  * Print out option HTML elements for the page parents drop-down.
809  *
810  * @since 1.5.0
811  *
812  * @param int $default Optional. The default page ID to be pre-selected. Default 0.
813  * @param int $parent  Optional. The parent page ID. Default 0.
814  * @param int $level   Optional. Page depth level. Default 0.
815  *
816  * @return null|false Boolean False if page has no children, otherwise print out html elements
817  */
818 function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
819         global $wpdb;
820         $post = get_post();
821         $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) );
822
823         if ( $items ) {
824                 foreach ( $items as $item ) {
825                         // A page cannot be its own parent.
826                         if ( $post && $post->ID && $item->ID == $post->ID )
827                                 continue;
828
829                         $pad = str_repeat( '&nbsp;', $level * 3 );
830                         $selected = selected( $default, $item->ID, false );
831
832                         echo "\n\t<option class='level-$level' value='$item->ID' $selected>$pad " . esc_html($item->post_title) . "</option>";
833                         parent_dropdown( $default, $item->ID, $level +1 );
834                 }
835         } else {
836                 return false;
837         }
838 }
839
840 /**
841  * Print out option html elements for role selectors.
842  *
843  * @since 2.1.0
844  *
845  * @param string $selected slug for the role that should be already selected
846  */
847 function wp_dropdown_roles( $selected = false ) {
848         $p = '';
849         $r = '';
850
851         $editable_roles = array_reverse( get_editable_roles() );
852
853         foreach ( $editable_roles as $role => $details ) {
854                 $name = translate_user_role($details['name'] );
855                 if ( $selected == $role ) // preselect specified role
856                         $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
857                 else
858                         $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
859         }
860         echo $p . $r;
861 }
862
863 /**
864  * Outputs the form used by the importers to accept the data to be imported
865  *
866  * @since 2.0.0
867  *
868  * @param string $action The action attribute for the form.
869  */
870 function wp_import_upload_form( $action ) {
871
872         /**
873          * Filter the maximum allowed upload size for import files.
874          *
875          * @since 2.3.0
876          *
877          * @see wp_max_upload_size()
878          *
879          * @param int $max_upload_size Allowed upload size. Default 1 MB.
880          */
881         $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
882         $size = size_format( $bytes );
883         $upload_dir = wp_upload_dir();
884         if ( ! empty( $upload_dir['error'] ) ) :
885                 ?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
886                 <p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
887         else :
888 ?>
889 <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' ) ); ?>">
890 <p>
891 <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
892 <input type="file" id="upload" name="import" size="25" />
893 <input type="hidden" name="action" value="save" />
894 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
895 </p>
896 <?php submit_button( __('Upload file and import'), 'button' ); ?>
897 </form>
898 <?php
899         endif;
900 }
901
902 /**
903  * Add a meta box to an edit form.
904  *
905  * @since 2.5.0
906  *
907  * @param string           $id            String for use in the 'id' attribute of tags.
908  * @param string           $title         Title of the meta box.
909  * @param callback         $callback      Function that fills the box with the desired content.
910  *                                        The function should echo its output.
911  * @param string|WP_Screen $screen        Optional. The screen on which to show the box (like a post
912  *                                        type, 'link', or 'comment'). Default is the current screen.
913  * @param string           $context       Optional. The context within the screen where the boxes
914  *                                        should display. Available contexts vary from screen to
915  *                                        screen. Post edit screen contexts include 'normal', 'side',
916  *                                        and 'advanced'. Comments screen contexts include 'normal'
917  *                                        and 'side'. Menus meta boxes (accordion sections) all use
918  *                                        the 'side' context. Global default is 'advanced'.
919  * @param string           $priority      Optional. The priority within the context where the boxes
920  *                                        should show ('high', 'low'). Default 'default'.
921  * @param array            $callback_args Optional. Data that should be set as the $args property
922  *                                        of the box array (which is the second parameter passed
923  *                                        to your callback). Default null.
924  */
925 function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {
926         global $wp_meta_boxes;
927
928         if ( empty( $screen ) )
929                 $screen = get_current_screen();
930         elseif ( is_string( $screen ) )
931                 $screen = convert_to_screen( $screen );
932
933         $page = $screen->id;
934
935         if ( !isset($wp_meta_boxes) )
936                 $wp_meta_boxes = array();
937         if ( !isset($wp_meta_boxes[$page]) )
938                 $wp_meta_boxes[$page] = array();
939         if ( !isset($wp_meta_boxes[$page][$context]) )
940                 $wp_meta_boxes[$page][$context] = array();
941
942         foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
943                 foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
944                         if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
945                                 continue;
946
947                         // If a core box was previously added or removed by a plugin, don't add.
948                         if ( 'core' == $priority ) {
949                                 // If core box previously deleted, don't add
950                                 if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
951                                         return;
952
953                                 /*
954                                  * If box was added with default priority, give it core priority to
955                                  * maintain sort order.
956                                  */
957                                 if ( 'default' == $a_priority ) {
958                                         $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
959                                         unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
960                                 }
961                                 return;
962                         }
963                         // If no priority given and id already present, use existing priority.
964                         if ( empty($priority) ) {
965                                 $priority = $a_priority;
966                         /*
967                          * Else, if we're adding to the sorted priority, we don't know the title
968                          * or callback. Grab them from the previously added context/priority.
969                          */
970                         } elseif ( 'sorted' == $priority ) {
971                                 $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
972                                 $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
973                                 $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
974                         }
975                         // An id can be in only one priority and one context.
976                         if ( $priority != $a_priority || $context != $a_context )
977                                 unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
978                 }
979         }
980
981         if ( empty($priority) )
982                 $priority = 'low';
983
984         if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
985                 $wp_meta_boxes[$page][$context][$priority] = array();
986
987         $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
988 }
989
990 /**
991  * Meta-Box template function
992  *
993  * @since 2.5.0
994  *
995  * @staticvar bool $already_sorted
996  * @param string|WP_Screen $screen Screen identifier
997  * @param string $context box context
998  * @param mixed $object gets passed to the box callback function as first parameter
999  * @return int number of meta_boxes
1000  */
1001 function do_meta_boxes( $screen, $context, $object ) {
1002         global $wp_meta_boxes;
1003         static $already_sorted = false;
1004
1005         if ( empty( $screen ) )
1006                 $screen = get_current_screen();
1007         elseif ( is_string( $screen ) )
1008                 $screen = convert_to_screen( $screen );
1009
1010         $page = $screen->id;
1011
1012         $hidden = get_hidden_meta_boxes( $screen );
1013
1014         printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context));
1015
1016         // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
1017         if ( ! $already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) {
1018                 foreach ( $sorted as $box_context => $ids ) {
1019                         foreach ( explode( ',', $ids ) as $id ) {
1020                                 if ( $id && 'dashboard_browser_nag' !== $id ) {
1021                                         add_meta_box( $id, null, null, $screen, $box_context, 'sorted' );
1022                                 }
1023                         }
1024                 }
1025         }
1026
1027         $already_sorted = true;
1028
1029         $i = 0;
1030
1031         if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
1032                 foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
1033                         if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ]) ) {
1034                                 foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
1035                                         if ( false == $box || ! $box['title'] )
1036                                                 continue;
1037                                         $i++;
1038                                         $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : '';
1039                                         echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n";
1040                                         if ( 'dashboard_browser_nag' != $box['id'] )
1041                                                 echo '<div class="handlediv" title="' . esc_attr__('Click to toggle') . '"><br /></div>';
1042                                         echo "<h3 class='hndle'><span>{$box['title']}</span></h3>\n";
1043                                         echo '<div class="inside">' . "\n";
1044                                         call_user_func($box['callback'], $object, $box);
1045                                         echo "</div>\n";
1046                                         echo "</div>\n";
1047                                 }
1048                         }
1049                 }
1050         }
1051
1052         echo "</div>";
1053
1054         return $i;
1055
1056 }
1057
1058 /**
1059  * Remove a meta box from an edit form.
1060  *
1061  * @since 2.6.0
1062  *
1063  * @param string $id String for use in the 'id' attribute of tags.
1064  * @param string|object $screen The screen on which to show the box (post, page, link).
1065  * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
1066  */
1067 function remove_meta_box($id, $screen, $context) {
1068         global $wp_meta_boxes;
1069
1070         if ( empty( $screen ) )
1071                 $screen = get_current_screen();
1072         elseif ( is_string( $screen ) )
1073                 $screen = convert_to_screen( $screen );
1074
1075         $page = $screen->id;
1076
1077         if ( !isset($wp_meta_boxes) )
1078                 $wp_meta_boxes = array();
1079         if ( !isset($wp_meta_boxes[$page]) )
1080                 $wp_meta_boxes[$page] = array();
1081         if ( !isset($wp_meta_boxes[$page][$context]) )
1082                 $wp_meta_boxes[$page][$context] = array();
1083
1084         foreach ( array('high', 'core', 'default', 'low') as $priority )
1085                 $wp_meta_boxes[$page][$context][$priority][$id] = false;
1086 }
1087
1088 /**
1089  * Meta Box Accordion Template Function
1090  *
1091  * Largely made up of abstracted code from {@link do_meta_boxes()}, this
1092  * function serves to build meta boxes as list items for display as
1093  * a collapsible accordion.
1094  *
1095  * @since 3.6.0
1096  *
1097  * @uses global $wp_meta_boxes Used to retrieve registered meta boxes.
1098  *
1099  * @param string|object $screen The screen identifier.
1100  * @param string $context The meta box context.
1101  * @param mixed $object gets passed to the section callback function as first parameter.
1102  * @return int number of meta boxes as accordion sections.
1103  */
1104 function do_accordion_sections( $screen, $context, $object ) {
1105         global $wp_meta_boxes;
1106
1107         wp_enqueue_script( 'accordion' );
1108
1109         if ( empty( $screen ) )
1110                 $screen = get_current_screen();
1111         elseif ( is_string( $screen ) )
1112                 $screen = convert_to_screen( $screen );
1113
1114         $page = $screen->id;
1115
1116         $hidden = get_hidden_meta_boxes( $screen );
1117         ?>
1118         <div id="side-sortables" class="accordion-container">
1119                 <ul class="outer-border">
1120         <?php
1121         $i = 0;
1122         $first_open = false;
1123
1124         if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
1125                 foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
1126                         if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
1127                                 foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
1128                                         if ( false == $box || ! $box['title'] )
1129                                                 continue;
1130                                         $i++;
1131                                         $hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
1132
1133                                         $open_class = '';
1134                                         if ( ! $first_open && empty( $hidden_class ) ) {
1135                                                 $first_open = true;
1136                                                 $open_class = 'open';
1137                                         }
1138                                         ?>
1139                                         <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'] ); ?>">
1140                                                 <h3 class="accordion-section-title hndle" tabindex="0">
1141                                                         <?php echo esc_html( $box['title'] ); ?>
1142                                                         <span class="screen-reader-text"><?php _e( 'Press return or enter to expand' ); ?></span>
1143                                                 </h3>
1144                                                 <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
1145                                                         <div class="inside">
1146                                                                 <?php call_user_func( $box['callback'], $object, $box ); ?>
1147                                                         </div><!-- .inside -->
1148                                                 </div><!-- .accordion-section-content -->
1149                                         </li><!-- .accordion-section -->
1150                                         <?php
1151                                 }
1152                         }
1153                 }
1154         }
1155         ?>
1156                 </ul><!-- .outer-border -->
1157         </div><!-- .accordion-container -->
1158         <?php
1159         return $i;
1160 }
1161
1162 /**
1163  * Add a new section to a settings page.
1164  *
1165  * Part of the Settings API. Use this to define new settings sections for an admin page.
1166  * Show settings sections in your admin page callback function with do_settings_sections().
1167  * Add settings fields to your section with add_settings_field()
1168  *
1169  * The $callback argument should be the name of a function that echoes out any
1170  * content you want to show at the top of the settings section before the actual
1171  * fields. It can output nothing if you want.
1172  *
1173  * @since 2.7.0
1174  *
1175  * @global $wp_settings_sections Storage array of all settings sections added to admin pages
1176  *
1177  * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags.
1178  * @param string $title Formatted title of the section. Shown as the heading for the section.
1179  * @param string $callback Function that echos out any content at the top of the section (between heading and fields).
1180  * @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();
1181  */
1182 function add_settings_section($id, $title, $callback, $page) {
1183         global $wp_settings_sections;
1184
1185         if ( 'misc' == $page ) {
1186                 _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) );
1187                 $page = 'general';
1188         }
1189
1190         if ( 'privacy' == $page ) {
1191                 _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) );
1192                 $page = 'reading';
1193         }
1194
1195         $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
1196 }
1197
1198 /**
1199  * Add a new field to a section of a settings page
1200  *
1201  * Part of the Settings API. Use this to define a settings field that will show
1202  * as part of a settings section inside a settings page. The fields are shown using
1203  * do_settings_fields() in do_settings-sections()
1204  *
1205  * The $callback argument should be the name of a function that echoes out the
1206  * html input tags for this setting field. Use get_option() to retrieve existing
1207  * values to show.
1208  *
1209  * @since 2.7.0
1210  *
1211  * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
1212  *
1213  * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags.
1214  * @param string $title Formatted title of the field. Shown as the label for the field during output.
1215  * @param string $callback Function that fills the field with the desired form inputs. The function should echo its output.
1216  * @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...).
1217  * @param string $section The slug-name of the section of the settings page in which to show the box (default, ...).
1218  * @param array $args Additional arguments
1219  */
1220 function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
1221         global $wp_settings_fields;
1222
1223         if ( 'misc' == $page ) {
1224                 _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
1225                 $page = 'general';
1226         }
1227
1228         if ( 'privacy' == $page ) {
1229                 _deprecated_argument( __FUNCTION__, '3.5', __( 'The privacy options group has been removed. Use another settings group.' ) );
1230                 $page = 'reading';
1231         }
1232
1233         $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
1234 }
1235
1236 /**
1237  * Prints out all settings sections added to a particular settings page
1238  *
1239  * Part of the Settings API. Use this in a settings page callback function
1240  * to output all the sections and fields that were added to that $page with
1241  * add_settings_section() and add_settings_field()
1242  *
1243  * @global $wp_settings_sections Storage array of all settings sections added to admin pages
1244  * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
1245  * @since 2.7.0
1246  *
1247  * @param string $page The slug name of the page whos settings sections you want to output
1248  */
1249 function do_settings_sections( $page ) {
1250         global $wp_settings_sections, $wp_settings_fields;
1251
1252         if ( ! isset( $wp_settings_sections[$page] ) )
1253                 return;
1254
1255         foreach ( (array) $wp_settings_sections[$page] as $section ) {
1256                 if ( $section['title'] )
1257                         echo "<h3>{$section['title']}</h3>\n";
1258
1259                 if ( $section['callback'] )
1260                         call_user_func( $section['callback'], $section );
1261
1262                 if ( ! isset( $wp_settings_fields ) || !isset( $wp_settings_fields[$page] ) || !isset( $wp_settings_fields[$page][$section['id']] ) )
1263                         continue;
1264                 echo '<table class="form-table">';
1265                 do_settings_fields( $page, $section['id'] );
1266                 echo '</table>';
1267         }
1268 }
1269
1270 /**
1271  * Print out the settings fields for a particular settings section
1272  *
1273  * Part of the Settings API. Use this in a settings page to output
1274  * a specific section. Should normally be called by do_settings_sections()
1275  * rather than directly.
1276  *
1277  * @global $wp_settings_fields Storage array of settings fields and their pages/sections
1278  *
1279  * @since 2.7.0
1280  *
1281  * @param string $page Slug title of the admin page who's settings fields you want to show.
1282  * @param string $section Slug title of the settings section who's fields you want to show.
1283  */
1284 function do_settings_fields($page, $section) {
1285         global $wp_settings_fields;
1286
1287         if ( ! isset( $wp_settings_fields[$page][$section] ) )
1288                 return;
1289
1290         foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
1291                 echo '<tr>';
1292                 if ( !empty($field['args']['label_for']) )
1293                         echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>';
1294                 else
1295                         echo '<th scope="row">' . $field['title'] . '</th>';
1296                 echo '<td>';
1297                 call_user_func($field['callback'], $field['args']);
1298                 echo '</td>';
1299                 echo '</tr>';
1300         }
1301 }
1302
1303 /**
1304  * Register a settings error to be displayed to the user
1305  *
1306  * Part of the Settings API. Use this to show messages to users about settings validation
1307  * problems, missing settings or anything else.
1308  *
1309  * Settings errors should be added inside the $sanitize_callback function defined in
1310  * register_setting() for a given setting to give feedback about the submission.
1311  *
1312  * By default messages will show immediately after the submission that generated the error.
1313  * Additional calls to settings_errors() can be used to show errors even when the settings
1314  * page is first accessed.
1315  *
1316  * @since 3.0.0
1317  *
1318  * @todo Properly document optional arguments as such.
1319  *
1320  * @global array $wp_settings_errors Storage array of errors registered during this pageload
1321  *
1322  * @param string $setting Slug title of the setting to which this error applies
1323  * @param string $code    Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
1324  * @param string $message The formatted message text to display to the user (will be shown inside styled
1325  *                        `<div>` and `<p>` tags).
1326  * @param string $type    The type of message it is, controls HTML class. Use 'error' or 'updated'.
1327  */
1328 function add_settings_error( $setting, $code, $message, $type = 'error' ) {
1329         global $wp_settings_errors;
1330
1331         $wp_settings_errors[] = array(
1332                 'setting' => $setting,
1333                 'code'    => $code,
1334                 'message' => $message,
1335                 'type'    => $type
1336         );
1337 }
1338
1339 /**
1340  * Fetch settings errors registered by add_settings_error()
1341  *
1342  * Checks the $wp_settings_errors array for any errors declared during the current
1343  * pageload and returns them.
1344  *
1345  * If changes were just submitted ($_GET['settings-updated']) and settings errors were saved
1346  * to the 'settings_errors' transient then those errors will be returned instead. This
1347  * is used to pass errors back across pageloads.
1348  *
1349  * Use the $sanitize argument to manually re-sanitize the option before returning errors.
1350  * This is useful if you have errors or notices you want to show even when the user
1351  * hasn't submitted data (i.e. when they first load an options page, or in admin_notices action hook)
1352  *
1353  * @since 3.0.0
1354  *
1355  * @global array $wp_settings_errors Storage array of errors registered during this pageload
1356  *
1357  * @param string $setting Optional slug title of a specific setting who's errors you want.
1358  * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
1359  * @return array Array of settings errors
1360  */
1361 function get_settings_errors( $setting = '', $sanitize = false ) {
1362         global $wp_settings_errors;
1363
1364         /*
1365          * If $sanitize is true, manually re-run the sanitization for this option
1366          * This allows the $sanitize_callback from register_setting() to run, adding
1367          * any settings errors you want to show by default.
1368          */
1369         if ( $sanitize )
1370                 sanitize_option( $setting, get_option( $setting ) );
1371
1372         // If settings were passed back from options.php then use them.
1373         if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && get_transient( 'settings_errors' ) ) {
1374                 $wp_settings_errors = array_merge( (array) $wp_settings_errors, get_transient( 'settings_errors' ) );
1375                 delete_transient( 'settings_errors' );
1376         }
1377
1378         // Check global in case errors have been added on this pageload.
1379         if ( ! count( $wp_settings_errors ) )
1380                 return array();
1381
1382         // Filter the results to those of a specific setting if one was set.
1383         if ( $setting ) {
1384                 $setting_errors = array();
1385                 foreach ( (array) $wp_settings_errors as $key => $details ) {
1386                         if ( $setting == $details['setting'] )
1387                                 $setting_errors[] = $wp_settings_errors[$key];
1388                 }
1389                 return $setting_errors;
1390         }
1391
1392         return $wp_settings_errors;
1393 }
1394
1395 /**
1396  * Display settings errors registered by {@see add_settings_error()}.
1397  *
1398  * Part of the Settings API. Outputs a div for each error retrieved by
1399  * {@see get_settings_errors()}.
1400  *
1401  * This is called automatically after a settings page based on the
1402  * Settings API is submitted. Errors should be added during the validation
1403  * callback function for a setting defined in {@see register_setting()}
1404  *
1405  * The $sanitize option is passed into {@see get_settings_errors()} and will
1406  * re-run the setting sanitization
1407  * on its current value.
1408  *
1409  * The $hide_on_update option will cause errors to only show when the settings
1410  * page is first loaded. if the user has already saved new values it will be
1411  * hidden to avoid repeating messages already shown in the default error
1412  * reporting after submission. This is useful to show general errors like
1413  * missing settings when the user arrives at the settings page.
1414  *
1415  * @since 3.0.0
1416  *
1417  * @param string $setting Optional slug title of a specific setting who's errors you want.
1418  * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
1419  * @param boolean $hide_on_update If set to true errors will not be shown if the settings page has already been submitted.
1420  */
1421 function settings_errors( $setting = '', $sanitize = false, $hide_on_update = false ) {
1422
1423         if ( $hide_on_update && ! empty( $_GET['settings-updated'] ) )
1424                 return;
1425
1426         $settings_errors = get_settings_errors( $setting, $sanitize );
1427
1428         if ( empty( $settings_errors ) )
1429                 return;
1430
1431         $output = '';
1432         foreach ( $settings_errors as $key => $details ) {
1433                 $css_id = 'setting-error-' . $details['code'];
1434                 $css_class = $details['type'] . ' settings-error';
1435                 $output .= "<div id='$css_id' class='$css_class'> \n";
1436                 $output .= "<p><strong>{$details['message']}</strong></p>";
1437                 $output .= "</div> \n";
1438         }
1439         echo $output;
1440 }
1441
1442 /**
1443  * {@internal Missing Short Description}}
1444  *
1445  * @since 2.7.0
1446  *
1447  * @param string $found_action
1448  */
1449 function find_posts_div($found_action = '') {
1450 ?>
1451         <div id="find-posts" class="find-box" style="display: none;">
1452                 <div id="find-posts-head" class="find-box-head">
1453                         <?php _e( 'Find Posts or Pages' ); ?>
1454                         <div id="find-posts-close"></div>
1455                 </div>
1456                 <div class="find-box-inside">
1457                         <div class="find-box-search">
1458                                 <?php if ( $found_action ) { ?>
1459                                         <input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" />
1460                                 <?php } ?>
1461                                 <input type="hidden" name="affected" id="affected" value="" />
1462                                 <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
1463                                 <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
1464                                 <input type="text" id="find-posts-input" name="ps" value="" />
1465                                 <span class="spinner"></span>
1466                                 <input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" />
1467                                 <div class="clear"></div>
1468                         </div>
1469                         <div id="find-posts-response"></div>
1470                 </div>
1471                 <div class="find-box-buttons">
1472                         <?php submit_button( __( 'Select' ), 'button-primary alignright', 'find-posts-submit', false ); ?>
1473                         <div class="clear"></div>
1474                 </div>
1475         </div>
1476 <?php
1477 }
1478
1479 /**
1480  * Display the post password.
1481  *
1482  * The password is passed through {@link esc_attr()} to ensure that it
1483  * is safe for placing in an html attribute.
1484  *
1485  * @since 2.7.0
1486  */
1487 function the_post_password() {
1488         $post = get_post();
1489         if ( isset( $post->post_password ) )
1490                 echo esc_attr( $post->post_password );
1491 }
1492
1493 /**
1494  * Get the post title.
1495  *
1496  * The post title is fetched and if it is blank then a default string is
1497  * returned.
1498  *
1499  * @since 2.7.0
1500  *
1501  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
1502  * @return string The post title if set.
1503  */
1504 function _draft_or_post_title( $post = 0 ) {
1505         $title = get_the_title( $post );
1506         if ( empty( $title ) )
1507                 $title = __( '(no title)' );
1508         return $title;
1509 }
1510
1511 /**
1512  * Display the search query.
1513  *
1514  * A simple wrapper to display the "s" parameter in a GET URI. This function
1515  * should only be used when {@link the_search_query()} cannot.
1516  *
1517  * @since 2.7.0
1518  *
1519  */
1520 function _admin_search_query() {
1521         echo isset($_REQUEST['s']) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : '';
1522 }
1523
1524 /**
1525  * Generic Iframe header for use with Thickbox
1526  *
1527  * @since 2.7.0
1528  * @param string $title Title of the Iframe page.
1529  * @param bool $limit_styles Limit styles to colour-related styles only (unless others are enqueued).
1530  *
1531  */
1532 function iframe_header( $title = '', $limit_styles = false ) {
1533         show_admin_bar( false );
1534         global $hook_suffix, $current_user, $admin_body_class, $wp_locale;
1535         $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
1536
1537         $current_screen = get_current_screen();
1538
1539         @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
1540         _wp_admin_html_begin();
1541 ?>
1542 <title><?php bloginfo('name') ?> &rsaquo; <?php echo $title ?> &#8212; <?php _e('WordPress'); ?></title>
1543 <?php
1544 wp_enqueue_style( 'colors' );
1545 ?>
1546 <script type="text/javascript">
1547 //<![CDATA[
1548 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();}}};
1549 function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
1550 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>',
1551         pagenow = '<?php echo $current_screen->id; ?>',
1552         typenow = '<?php echo $current_screen->post_type; ?>',
1553         adminpage = '<?php echo $admin_body_class; ?>',
1554         thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
1555         decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
1556         isRtl = <?php echo (int) is_rtl(); ?>;
1557 //]]>
1558 </script>
1559 <?php
1560 /** This action is documented in wp-admin/admin-header.php */
1561 do_action( 'admin_enqueue_scripts', $hook_suffix );
1562
1563 /** This action is documented in wp-admin/admin-header.php */
1564 do_action( "admin_print_styles-$hook_suffix" );
1565
1566 /** This action is documented in wp-admin/admin-header.php */
1567 do_action( 'admin_print_styles' );
1568
1569 /** This action is documented in wp-admin/admin-header.php */
1570 do_action( "admin_print_scripts-$hook_suffix" );
1571
1572 /** This action is documented in wp-admin/admin-header.php */
1573 do_action( 'admin_print_scripts' );
1574
1575 /** This action is documented in wp-admin/admin-header.php */
1576 do_action( "admin_head-$hook_suffix" );
1577
1578 /** This action is documented in wp-admin/admin-header.php */
1579 do_action( 'admin_head' );
1580
1581 $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
1582
1583 if ( is_rtl() )
1584         $admin_body_class .= ' rtl';
1585
1586 ?>
1587 </head>
1588 <?php
1589 /** This filter is documented in wp-admin/admin-header.php */
1590 $admin_body_classes = apply_filters( 'admin_body_class', '' );
1591 ?>
1592 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="wp-admin wp-core-ui no-js iframe <?php echo $admin_body_classes . ' ' . $admin_body_class; ?>">
1593 <script type="text/javascript">
1594 //<![CDATA[
1595 (function(){
1596 var c = document.body.className;
1597 c = c.replace(/no-js/, 'js');
1598 document.body.className = c;
1599 })();
1600 //]]>
1601 </script>
1602 <?php
1603 }
1604
1605 /**
1606  * Generic Iframe footer for use with Thickbox
1607  *
1608  * @since 2.7.0
1609  *
1610  */
1611 function iframe_footer() {
1612         /*
1613          * We're going to hide any footer output on iFrame pages,
1614          * but run the hooks anyway since they output JavaScript
1615          * or other needed content.
1616          */
1617          ?>
1618         <div class="hidden">
1619 <?php
1620         /** This action is documented in wp-admin/admin-footer.php */
1621         do_action( 'admin_footer', '' );
1622
1623         /** This action is documented in wp-admin/admin-footer.php */
1624         do_action( 'admin_print_footer_scripts' );
1625 ?>
1626         </div>
1627 <script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script>
1628 </body>
1629 </html>
1630 <?php
1631 }
1632
1633 function _post_states($post) {
1634         $post_states = array();
1635         if ( isset( $_REQUEST['post_status'] ) )
1636                 $post_status = $_REQUEST['post_status'];
1637         else
1638                 $post_status = '';
1639
1640         if ( !empty($post->post_password) )
1641                 $post_states['protected'] = __('Password protected');
1642         if ( 'private' == $post->post_status && 'private' != $post_status )
1643                 $post_states['private'] = __('Private');
1644         if ( 'draft' == $post->post_status && 'draft' != $post_status )
1645                 $post_states['draft'] = __('Draft');
1646         if ( 'pending' == $post->post_status && 'pending' != $post_status )
1647                 /* translators: post state */
1648                 $post_states['pending'] = _x('Pending', 'post state');
1649         if ( is_sticky($post->ID) )
1650                 $post_states['sticky'] = __('Sticky');
1651
1652         /**
1653          * Filter the default post display states used in the Posts list table.
1654          *
1655          * @since 2.8.0
1656          *
1657          * @param array $post_states An array of post display states. Values include 'Password protected',
1658          *                           'Private', 'Draft', 'Pending', and 'Sticky'.
1659          * @param int   $post        The post ID.
1660          */
1661         $post_states = apply_filters( 'display_post_states', $post_states, $post );
1662
1663         if ( ! empty($post_states) ) {
1664                 $state_count = count($post_states);
1665                 $i = 0;
1666                 echo ' - ';
1667                 foreach ( $post_states as $state ) {
1668                         ++$i;
1669                         ( $i == $state_count ) ? $sep = '' : $sep = ', ';
1670                         echo "<span class='post-state'>$state$sep</span>";
1671                 }
1672         }
1673
1674 }
1675
1676 function _media_states( $post ) {
1677         $media_states = array();
1678         $stylesheet = get_option('stylesheet');
1679
1680         if ( current_theme_supports( 'custom-header') ) {
1681                 $meta_header = get_post_meta($post->ID, '_wp_attachment_is_custom_header', true );
1682                 if ( ! empty( $meta_header ) && $meta_header == $stylesheet )
1683                         $media_states[] = __( 'Header Image' );
1684         }
1685
1686         if ( current_theme_supports( 'custom-background') ) {
1687                 $meta_background = get_post_meta($post->ID, '_wp_attachment_is_custom_background', true );
1688                 if ( ! empty( $meta_background ) && $meta_background == $stylesheet )
1689                         $media_states[] = __( 'Background Image' );
1690         }
1691
1692         /**
1693          * Filter the default media display states for items in the Media list table.
1694          *
1695          * @since 3.2.0
1696          *
1697          * @param array $media_states An array of media states. Default 'Header Image',
1698          *                            'Background Image'.
1699          */
1700         $media_states = apply_filters( 'display_media_states', $media_states );
1701
1702         if ( ! empty( $media_states ) ) {
1703                 $state_count = count( $media_states );
1704                 $i = 0;
1705                 echo ' - ';
1706                 foreach ( $media_states as $state ) {
1707                         ++$i;
1708                         ( $i == $state_count ) ? $sep = '' : $sep = ', ';
1709                         echo "<span class='post-state'>$state$sep</span>";
1710                 }
1711         }
1712 }
1713
1714 /**
1715  * Test support for compressing JavaScript from PHP
1716  *
1717  * Outputs JavaScript that tests if compression from PHP works as expected
1718  * and sets an option with the result. Has no effect when the current user
1719  * is not an administrator. To run the test again the option 'can_compress_scripts'
1720  * has to be deleted.
1721  *
1722  * @since 2.8.0
1723  */
1724 function compression_test() {
1725 ?>
1726         <script type="text/javascript">
1727         /* <![CDATA[ */
1728         var testCompression = {
1729                 get : function(test) {
1730                         var x;
1731                         if ( window.XMLHttpRequest ) {
1732                                 x = new XMLHttpRequest();
1733                         } else {
1734                                 try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
1735                         }
1736
1737                         if (x) {
1738                                 x.onreadystatechange = function() {
1739                                         var r, h;
1740                                         if ( x.readyState == 4 ) {
1741                                                 r = x.responseText.substr(0, 18);
1742                                                 h = x.getResponseHeader('Content-Encoding');
1743                                                 testCompression.check(r, h, test);
1744                                         }
1745                                 }
1746
1747                                 x.open('GET', ajaxurl + '?action=wp-compression-test&test='+test+'&'+(new Date()).getTime(), true);
1748                                 x.send('');
1749                         }
1750                 },
1751
1752                 check : function(r, h, test) {
1753                         if ( ! r && ! test )
1754                                 this.get(1);
1755
1756                         if ( 1 == test ) {
1757                                 if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) )
1758                                         this.get('no');
1759                                 else
1760                                         this.get(2);
1761
1762                                 return;
1763                         }
1764
1765                         if ( 2 == test ) {
1766                                 if ( '"wpCompressionTest' == r )
1767                                         this.get('yes');
1768                                 else
1769                                         this.get('no');
1770                         }
1771                 }
1772         };
1773         testCompression.check();
1774         /* ]]> */
1775         </script>
1776 <?php
1777 }
1778
1779 /**
1780  * Echoes a submit button, with provided text and appropriate class(es).
1781  *
1782  * @since 3.1.0
1783  *
1784  * @see get_submit_button()
1785  *
1786  * @param string       $text             The text of the button (defaults to 'Save Changes')
1787  * @param string       $type             Optional. The type and CSS class(es) of the button. Core values
1788  *                                       include 'primary', 'secondary', 'delete'. Default 'primary'
1789  * @param string       $name             The HTML name of the submit button. Defaults to "submit". If no
1790  *                                       id attribute is given in $other_attributes below, $name will be
1791  *                                       used as the button's id.
1792  * @param bool         $wrap             True if the output button should be wrapped in a paragraph tag,
1793  *                                       false otherwise. Defaults to true
1794  * @param array|string $other_attributes Other attributes that should be output with the button, mapping
1795  *                                       attributes to their values, such as setting tabindex to 1, etc.
1796  *                                       These key/value attribute pairs will be output as attribute="value",
1797  *                                       where attribute is the key. Other attributes can also be provided
1798  *                                       as a string such as 'tabindex="1"', though the array format is
1799  *                                       preferred. Default null.
1800  */
1801 function submit_button( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null ) {
1802         echo get_submit_button( $text, $type, $name, $wrap, $other_attributes );
1803 }
1804
1805 /**
1806  * Returns a submit button, with provided text and appropriate class
1807  *
1808  * @since 3.1.0
1809  *
1810  * @param string $text The text of the button (defaults to 'Save Changes')
1811  * @param string $type The type of button. One of: primary, secondary, delete
1812  * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute
1813  *               is given in $other_attributes below, $name will be used as the button's id.
1814  * @param bool $wrap True if the output button should be wrapped in a paragraph tag,
1815  *                         false otherwise. Defaults to true
1816  * @param array|string $other_attributes Other attributes that should be output with the button,
1817  *                     mapping attributes to their values, such as array( 'tabindex' => '1' ).
1818  *                     These attributes will be output as attribute="value", such as tabindex="1".
1819  *                     Defaults to no other attributes. Other attributes can also be provided as a
1820  *                     string such as 'tabindex="1"', though the array format is typically cleaner.
1821  */
1822 function get_submit_button( $text = null, $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = null ) {
1823         if ( ! is_array( $type ) )
1824                 $type = explode( ' ', $type );
1825
1826         $button_shorthand = array( 'primary', 'small', 'large' );
1827         $classes = array( 'button' );
1828         foreach ( $type as $t ) {
1829                 if ( 'secondary' === $t || 'button-secondary' === $t )
1830                         continue;
1831                 $classes[] = in_array( $t, $button_shorthand ) ? 'button-' . $t : $t;
1832         }
1833         $class = implode( ' ', array_unique( $classes ) );
1834
1835         if ( 'delete' === $type )
1836                 $class = 'button-secondary delete';
1837
1838         $text = $text ? $text : __( 'Save Changes' );
1839
1840         // Default the id attribute to $name unless an id was specifically provided in $other_attributes
1841         $id = $name;
1842         if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) {
1843                 $id = $other_attributes['id'];
1844                 unset( $other_attributes['id'] );
1845         }
1846
1847         $attributes = '';
1848         if ( is_array( $other_attributes ) ) {
1849                 foreach ( $other_attributes as $attribute => $value ) {
1850                         $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
1851                 }
1852         } else if ( !empty( $other_attributes ) ) { // Attributes provided as a string
1853                 $attributes = $other_attributes;
1854         }
1855
1856         $button = '<input type="submit" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" class="' . esc_attr( $class );
1857         $button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />';
1858
1859         if ( $wrap ) {
1860                 $button = '<p class="submit">' . $button . '</p>';
1861         }
1862
1863         return $button;
1864 }
1865
1866 function _wp_admin_html_begin() {
1867         global $is_IE;
1868
1869         $admin_html_class = ( is_admin_bar_showing() ) ? 'wp-toolbar' : '';
1870
1871         if ( $is_IE )
1872                 @header('X-UA-Compatible: IE=edge');
1873
1874 ?>
1875 <!DOCTYPE html>
1876 <!--[if IE 8]>
1877 <html xmlns="http://www.w3.org/1999/xhtml" class="ie8 <?php echo $admin_html_class; ?>" <?php
1878         /**
1879          * Fires inside the HTML tag in the admin header.
1880          *
1881          * @since 2.2.0
1882          */
1883         do_action( 'admin_xml_ns' );
1884 ?> <?php language_attributes(); ?>>
1885 <![endif]-->
1886 <!--[if !(IE 8) ]><!-->
1887 <html xmlns="http://www.w3.org/1999/xhtml" class="<?php echo $admin_html_class; ?>" <?php
1888         /** This action is documented in wp-admin/includes/template.php */
1889         do_action( 'admin_xml_ns' );
1890 ?> <?php language_attributes(); ?>>
1891 <!--<![endif]-->
1892 <head>
1893 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
1894 <?php
1895 }
1896
1897 final class WP_Internal_Pointers {
1898         /**
1899          * Initializes the new feature pointers.
1900          *
1901          * @since 3.3.0
1902          *
1903          * All pointers can be disabled using the following:
1904          *     remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
1905          *
1906          * Individual pointers (e.g. wp390_widgets) can be disabled using the following:
1907          *     remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp390_widgets' ) );
1908          */
1909         public static function enqueue_scripts( $hook_suffix ) {
1910                 /*
1911                  * Register feature pointers
1912                  * Format: array( hook_suffix => pointer_id )
1913                  */
1914
1915                 $registered_pointers = array(
1916                         'post-new.php' => 'wp410_dfw',
1917                         'post.php'     => 'wp410_dfw',
1918                         'edit.php'     => 'wp360_locks',
1919                         'widgets.php'  => 'wp390_widgets',
1920                         'themes.php'   => 'wp390_widgets',
1921                 );
1922
1923                 // Check if screen related pointer is registered
1924                 if ( empty( $registered_pointers[ $hook_suffix ] ) )
1925                         return;
1926
1927                 $pointers = (array) $registered_pointers[ $hook_suffix ];
1928
1929                 $caps_required = array(
1930                         'wp390_widgets' => array( 'edit_theme_options' ),
1931                 );
1932
1933                 // Get dismissed pointers
1934                 $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
1935
1936                 $got_pointers = false;
1937                 foreach ( array_diff( $pointers, $dismissed ) as $pointer ) {
1938                         if ( isset( $caps_required[ $pointer ] ) ) {
1939                                 foreach ( $caps_required[ $pointer ] as $cap ) {
1940                                         if ( ! current_user_can( $cap ) )
1941                                                 continue 2;
1942                                 }
1943                         }
1944
1945                         // Bind pointer print function
1946                         add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) );
1947                         $got_pointers = true;
1948                 }
1949
1950                 if ( ! $got_pointers )
1951                         return;
1952
1953                 // Add pointers script and style to queue
1954                 wp_enqueue_style( 'wp-pointer' );
1955                 wp_enqueue_script( 'wp-pointer' );
1956         }
1957
1958         /**
1959          * Print the pointer JavaScript data.
1960          *
1961          * @since 3.3.0
1962          *
1963          * @param string $pointer_id The pointer ID.
1964          * @param string $selector The HTML elements, on which the pointer should be attached.
1965          * @param array  $args Arguments to be passed to the pointer JS (see wp-pointer.js).
1966          */
1967         private static function print_js( $pointer_id, $selector, $args ) {
1968                 if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) )
1969                         return;
1970
1971                 ?>
1972                 <script type="text/javascript">
1973                 //<![CDATA[
1974                 (function($){
1975                         var options = <?php echo wp_json_encode( $args ); ?>, setup;
1976
1977                         if ( ! options )
1978                                 return;
1979
1980                         options = $.extend( options, {
1981                                 close: function() {
1982                                         $.post( ajaxurl, {
1983                                                 pointer: '<?php echo $pointer_id; ?>',
1984                                                 action: 'dismiss-wp-pointer'
1985                                         });
1986                                 }
1987                         });
1988
1989                         setup = function() {
1990                                 $('<?php echo $selector; ?>').first().pointer( options ).pointer('open');
1991                         };
1992
1993                         if ( options.position && options.position.defer_loading )
1994                                 $(window).bind( 'load.wp-pointers', setup );
1995                         else
1996                                 $(document).ready( setup );
1997
1998                 })( jQuery );
1999                 //]]>
2000                 </script>
2001                 <?php
2002         }
2003
2004         public static function pointer_wp330_toolbar() {}
2005         public static function pointer_wp330_media_uploader() {}
2006         public static function pointer_wp330_saving_widgets() {}
2007         public static function pointer_wp340_customize_current_theme_link() {}
2008         public static function pointer_wp340_choose_image_from_library() {}
2009         public static function pointer_wp350_media() {}
2010         public static function pointer_wp360_revisions() {}
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 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         public static function pointer_wp410_dfw() {
2053                 // Don't show when editor-scrolling is not used.
2054                 if ( empty( $GLOBALS['_wp_editor_expand'] ) ) {
2055                         return;
2056                 }
2057
2058                 $content  = '<h3>' . __( 'Distraction-Free Writing' ) . '</h3>';
2059                 $content .= '<p>' . __( 'Enable distraction-free writing mode, and everything surrounding the editor will fade away when you start typing. Move your mouse out of the editor to reveal everything again.' ) . '</p>';
2060
2061                 if ( is_rtl() ) {
2062                         $position = array( 'edge' => 'left', 'align' => 'center', 'my' => 'left+40 top-11', 'at' => 'left top' );
2063                 } else {
2064                         $position = array( 'edge' => 'right', 'align' => 'center', 'my' => 'right-40 top-11', 'at' => 'right top' );
2065                 }
2066
2067                 self::print_js( 'wp410_dfw', '#wp-content-wrap', array(
2068                         'content' => $content,
2069                         'position' => $position,
2070                 ) );
2071         }
2072
2073         /**
2074          * Prevents new users from seeing existing 'new feature' pointers.
2075          *
2076          * @since 3.3.0
2077          */
2078         public static function dismiss_pointers_for_new_users( $user_id ) {
2079                 add_user_meta( $user_id, 'dismissed_wp_pointers', 'wp360_locks,wp390_widgets' );
2080         }
2081 }
2082
2083 add_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts'                ) );
2084 add_action( 'user_register',         array( 'WP_Internal_Pointers', 'dismiss_pointers_for_new_users' ) );
2085
2086 /**
2087  * Convert a screen string to a screen object
2088  *
2089  * @since 3.0.0
2090  *
2091  * @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen.
2092  * @return WP_Screen Screen object.
2093  */
2094 function convert_to_screen( $hook_name ) {
2095         if ( ! class_exists( 'WP_Screen' ) ) {
2096                 _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' );
2097                 return (object) array( 'id' => '_invalid', 'base' => '_are_belong_to_us' );
2098         }
2099
2100         return WP_Screen::get( $hook_name );
2101 }
2102
2103 /**
2104  * Output the HTML for restoring the post data from DOM storage
2105  *
2106  * @since 3.6.0
2107  * @access private
2108  */
2109 function _local_storage_notice() {
2110         ?>
2111         <div id="local-storage-notice" class="hidden notice">
2112         <p class="local-restore">
2113                 <?php _e('The backup of this post in your browser is different from the version below.'); ?>
2114                 <a class="restore-backup" href="#"><?php _e('Restore the backup.'); ?></a>
2115         </p>
2116         <p class="undo-restore hidden">
2117                 <?php _e('Post restored successfully.'); ?>
2118                 <a class="undo-restore-backup" href="#"><?php _e('Undo.'); ?></a>
2119         </p>
2120         </div>
2121         <?php
2122 }
2123
2124 /**
2125  * Output a HTML element with a star rating for a given rating.
2126  *
2127  * Outputs a HTML element with the star rating exposed on a 0..5 scale in
2128  * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the
2129  * number of ratings may also be displayed by passing the $number parameter.
2130  *
2131  * @since 3.8.0
2132  * @param array $args {
2133  *     Optional. Array of star ratings arguments.
2134  *
2135  *     @type int    $rating The rating to display, expressed in either a 0.5 rating increment,
2136  *                          or percentage. Default 0.
2137  *     @type string $type   Format that the $rating is in. Valid values are 'rating' (default),
2138  *                          or, 'percent'. Default 'rating'.
2139  *     @type int    $number The number of ratings that makes up this rating. Default 0.
2140  * }
2141  */
2142 function wp_star_rating( $args = array() ) {
2143         $defaults = array(
2144                 'rating' => 0,
2145                 'type' => 'rating',
2146                 'number' => 0,
2147         );
2148         $r = wp_parse_args( $args, $defaults );
2149
2150         // Non-english decimal places when the $rating is coming from a string
2151         $rating = str_replace( ',', '.', $r['rating'] );
2152
2153         // Convert Percentage to star rating, 0..5 in .5 increments
2154         if ( 'percent' == $r['type'] ) {
2155                 $rating = round( $rating / 10, 0 ) / 2;
2156         }
2157
2158         // Calculate the number of each type of star needed
2159         $full_stars = floor( $rating );
2160         $half_stars = ceil( $rating - $full_stars );
2161         $empty_stars = 5 - $full_stars - $half_stars;
2162
2163         if ( $r['number'] ) {
2164                 /* translators: 1: The rating, 2: The number of ratings */
2165                 $format = _n( '%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $r['number'] );
2166                 $title = sprintf( $format, number_format_i18n( $rating, 1 ), number_format_i18n( $r['number'] ) );
2167         } else {
2168                 /* translators: 1: The rating */
2169                 $title = sprintf( __( '%s rating' ), number_format_i18n( $rating, 1 ) );
2170         }
2171
2172         echo '<div class="star-rating" title="' . esc_attr( $title ) . '">';
2173         echo '<span class="screen-reader-text">' . $title . '</span>';
2174         echo str_repeat( '<div class="star star-full"></div>', $full_stars );
2175         echo str_repeat( '<div class="star star-half"></div>', $half_stars );
2176         echo str_repeat( '<div class="star star-empty"></div>', $empty_stars);
2177         echo '</div>';
2178 }