3 * Template WordPress Administration API.
5 * A Big Mess. Also some neat functions that are nicely written.
8 * @subpackage Administration
12 // Category Checklists
16 * Walker to output an unordered list of category checkbox input elements.
21 * @see wp_category_checklist()
22 * @see wp_terms_checklist()
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
29 * Starts the list before the elements are added.
31 * @see Walker:start_lvl()
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()
39 public function start_lvl( &$output, $depth = 0, $args = array() ) {
40 $indent = str_repeat("\t", $depth);
41 $output .= "$indent<ul class='children'>\n";
45 * Ends the list of after the elements are added.
47 * @see Walker::end_lvl()
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()
55 public function end_lvl( &$output, $depth = 0, $args = array() ) {
56 $indent = str_repeat("\t", $depth);
57 $output .= "$indent</ul>\n";
61 * Start the element output.
63 * @see Walker::start_el()
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.
73 public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
74 if ( empty( $args['taxonomy'] ) ) {
75 $taxonomy = 'category';
77 $taxonomy = $args['taxonomy'];
80 if ( $taxonomy == 'category' ) {
81 $name = 'post_category';
83 $name = 'tax_input[' . $taxonomy . ']';
86 $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
87 $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';
89 $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
91 /** This filter is documented in wp-includes/category-template.php */
92 if ( ! empty( $args['list_only'] ) ) {
93 $aria_cheched = 'false';
94 $inner_class = 'category';
96 if ( in_array( $category->term_id, $args['selected_cats'] ) ) {
97 $inner_class .= ' selected';
98 $aria_cheched = 'true';
101 $output .= "\n" . '<li' . $class . '>' .
102 '<div class="' . $inner_class . '" data-term-id=' . $category->term_id .
103 ' tabindex="0" role="checkbox" aria-checked="' . $aria_cheched . '">' .
104 esc_html( apply_filters( 'the_category', $category->name ) ) . '</div>';
106 $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
107 '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' .
108 checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) .
109 disabled( empty( $args['disabled'] ), false, false ) . ' /> ' .
110 esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>';
115 * Ends the element output, if needed.
117 * @see Walker::end_el()
121 * @param string $output Passed by reference. Used to append additional content.
122 * @param object $category The current term object.
123 * @param int $depth Depth of the term in reference to parents. Default 0.
124 * @param array $args An array of arguments. @see wp_terms_checklist()
126 public function end_el( &$output, $category, $depth = 0, $args = array() ) {
127 $output .= "</li>\n";
132 * Output an unordered list of checkbox input elements labeled with category names.
136 * @see wp_terms_checklist()
138 * @param int $post_id Optional. Post to generate a categories checklist for. Default 0.
139 * $selected_cats must not be an array. Default 0.
140 * @param int $descendants_and_self Optional. ID of the category to output along with its descendants.
142 * @param array $selected_cats Optional. List of categories to mark as checked. Default false.
143 * @param array $popular_cats Optional. List of categories to receive the "popular-category" class.
145 * @param object $walker Optional. Walker object to use to build the output.
146 * Default is a Walker_Category_Checklist instance.
147 * @param bool $checked_ontop Optional. Whether to move checked items out of the hierarchy and to
148 * the top of the list. Default true.
150 function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) {
151 wp_terms_checklist( $post_id, array(
152 'taxonomy' => 'category',
153 'descendants_and_self' => $descendants_and_self,
154 'selected_cats' => $selected_cats,
155 'popular_cats' => $popular_cats,
157 'checked_ontop' => $checked_ontop
162 * Output an unordered list of checkbox input elements labelled with term names.
164 * Taxonomy-independent version of wp_category_checklist().
168 * @param int $post_id Optional. Post ID. Default 0.
169 * @param array|string $args {
170 * Optional. Array or string of arguments for generating a terms checklist. Default empty array.
172 * @type int $descendants_and_self ID of the category to output along with its descendants.
174 * @type array $selected_cats List of categories to mark as checked. Default false.
175 * @type array $popular_cats List of categories to receive the "popular-category" class.
177 * @type object $walker Walker object to use to build the output.
178 * Default is a Walker_Category_Checklist instance.
179 * @type string $taxonomy Taxonomy to generate the checklist for. Default 'category'.
180 * @type bool $checked_ontop Whether to move checked items out of the hierarchy and to
181 * the top of the list. Default true.
184 function wp_terms_checklist( $post_id = 0, $args = array() ) {
186 'descendants_and_self' => 0,
187 'selected_cats' => false,
188 'popular_cats' => false,
190 'taxonomy' => 'category',
191 'checked_ontop' => true
195 * Filter the taxonomy terms checklist arguments.
199 * @see wp_terms_checklist()
201 * @param array $args An array of arguments.
202 * @param int $post_id The post ID.
204 $params = apply_filters( 'wp_terms_checklist_args', $args, $post_id );
206 $r = wp_parse_args( $params, $defaults );
208 if ( empty( $r['walker'] ) || ! ( $r['walker'] instanceof Walker ) ) {
209 $walker = new Walker_Category_Checklist;
211 $walker = $r['walker'];
214 $taxonomy = $r['taxonomy'];
215 $descendants_and_self = (int) $r['descendants_and_self'];
217 $args = array( 'taxonomy' => $taxonomy );
219 $tax = get_taxonomy( $taxonomy );
220 $args['disabled'] = ! current_user_can( $tax->cap->assign_terms );
222 $args['list_only'] = ! empty( $r['list_only'] );
224 if ( is_array( $r['selected_cats'] ) ) {
225 $args['selected_cats'] = $r['selected_cats'];
226 } elseif ( $post_id ) {
227 $args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) );
229 $args['selected_cats'] = array();
231 if ( is_array( $r['popular_cats'] ) ) {
232 $args['popular_cats'] = $r['popular_cats'];
234 $args['popular_cats'] = get_terms( $taxonomy, array(
236 'orderby' => 'count',
239 'hierarchical' => false
242 if ( $descendants_and_self ) {
243 $categories = (array) get_terms( $taxonomy, array(
244 'child_of' => $descendants_and_self,
248 $self = get_term( $descendants_and_self, $taxonomy );
249 array_unshift( $categories, $self );
251 $categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) );
254 if ( $r['checked_ontop'] ) {
255 // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
256 $checked_categories = array();
257 $keys = array_keys( $categories );
259 foreach( $keys as $k ) {
260 if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) {
261 $checked_categories[] = $categories[$k];
262 unset( $categories[$k] );
266 // Put checked cats on top
267 echo call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) );
269 // Then the rest of them
270 echo call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) );
274 * Retrieve a list of the most popular terms from the specified taxonomy.
276 * If the $echo argument is true then the elements for a list of checkbox
277 * `<input>` elements labelled with the names of the selected terms is output.
278 * If the $post_ID global isn't empty then the terms associated with that
279 * post will be marked as checked.
283 * @param string $taxonomy Taxonomy to retrieve terms from.
284 * @param int $default Not used.
285 * @param int $number Number of terms to retrieve. Defaults to 10.
286 * @param bool $echo Optionally output the list as well. Defaults to true.
287 * @return array List of popular term IDs.
289 function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
292 if ( $post && $post->ID )
293 $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields'=>'ids'));
295 $checked_terms = array();
297 $terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
299 $tax = get_taxonomy($taxonomy);
301 $popular_ids = array();
302 foreach ( (array) $terms as $term ) {
303 $popular_ids[] = $term->term_id;
304 if ( !$echo ) // hack for AJAX use
306 $id = "popular-$taxonomy-$term->term_id";
307 $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : '';
310 <li id="<?php echo $id; ?>" class="popular-category">
311 <label class="selectit">
312 <input id="in-<?php echo $id; ?>" type="checkbox" <?php echo $checked; ?> value="<?php echo (int) $term->term_id; ?>" <?php disabled( ! current_user_can( $tax->cap->assign_terms ) ); ?> />
314 /** This filter is documented in wp-includes/category-template.php */
315 echo esc_html( apply_filters( 'the_category', $term->name ) );
326 * {@internal Missing Short Description}}
330 * @param int $link_id
332 function wp_link_category_checklist( $link_id = 0 ) {
335 $checked_categories = array();
338 $checked_categories = wp_get_link_cats( $link_id );
339 // No selected categories, strange
340 if ( ! count( $checked_categories ) ) {
341 $checked_categories[] = $default;
344 $checked_categories[] = $default;
347 $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) );
349 if ( empty( $categories ) )
352 foreach ( $categories as $category ) {
353 $cat_id = $category->term_id;
355 /** This filter is documented in wp-includes/category-template.php */
356 $name = esc_html( apply_filters( 'the_category', $category->name ) );
357 $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : '';
358 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>";
363 * Adds hidden fields with the data for use in the inline editor for posts and pages.
367 * @param WP_Post $post Post object.
369 function get_inline_data($post) {
370 $post_type_object = get_post_type_object($post->post_type);
371 if ( ! current_user_can( 'edit_post', $post->ID ) )
374 $title = esc_textarea( trim( $post->post_title ) );
376 /** This filter is documented in wp-admin/edit-tag-form.php */
378 <div class="hidden" id="inline_' . $post->ID . '">
379 <div class="post_title">' . $title . '</div>
380 <div class="post_name">' . apply_filters( 'editable_slug', $post->post_name ) . '</div>
381 <div class="post_author">' . $post->post_author . '</div>
382 <div class="comment_status">' . esc_html( $post->comment_status ) . '</div>
383 <div class="ping_status">' . esc_html( $post->ping_status ) . '</div>
384 <div class="_status">' . esc_html( $post->post_status ) . '</div>
385 <div class="jj">' . mysql2date( 'd', $post->post_date, false ) . '</div>
386 <div class="mm">' . mysql2date( 'm', $post->post_date, false ) . '</div>
387 <div class="aa">' . mysql2date( 'Y', $post->post_date, false ) . '</div>
388 <div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div>
389 <div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div>
390 <div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div>
391 <div class="post_password">' . esc_html( $post->post_password ) . '</div>';
393 if ( $post_type_object->hierarchical )
394 echo '<div class="post_parent">' . $post->post_parent . '</div>';
396 if ( $post->post_type == 'page' )
397 echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>';
399 if ( post_type_supports( $post->post_type, 'page-attributes' ) )
400 echo '<div class="menu_order">' . $post->menu_order . '</div>';
402 $taxonomy_names = get_object_taxonomies( $post->post_type );
403 foreach ( $taxonomy_names as $taxonomy_name) {
404 $taxonomy = get_taxonomy( $taxonomy_name );
406 if ( $taxonomy->hierarchical && $taxonomy->show_ui ) {
408 $terms = get_object_term_cache( $post->ID, $taxonomy_name );
409 if ( false === $terms ) {
410 $terms = wp_get_object_terms( $post->ID, $taxonomy_name );
411 wp_cache_add( $post->ID, $terms, $taxonomy_name . '_relationships' );
413 $term_ids = empty( $terms ) ? array() : wp_list_pluck( $terms, 'term_id' );
415 echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode( ',', $term_ids ) . '</div>';
417 } elseif ( $taxonomy->show_ui ) {
419 echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">'
420 . esc_html( str_replace( ',', ', ', get_terms_to_edit( $post->ID, $taxonomy_name ) ) ) . '</div>';
425 if ( !$post_type_object->hierarchical )
426 echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
428 if ( post_type_supports( $post->post_type, 'post-formats' ) )
429 echo '<div class="post_format">' . esc_html( get_post_format( $post->ID ) ) . '</div>';
435 * {@internal Missing Short Description}}
439 * @param int $position
440 * @param bool $checkbox
441 * @param string $mode
442 * @param bool $table_row
444 function wp_comment_reply( $position = 1, $checkbox = false, $mode = 'single', $table_row = true ) {
445 global $wp_list_table;
447 * Filter the in-line comment reply-to form output in the Comments
450 * Returning a non-empty value here will short-circuit display
451 * of the in-line comment-reply form in the Comments list table,
452 * echoing the returned value instead.
456 * @see wp_comment_reply()
458 * @param string $content The reply-to form content.
459 * @param array $args An array of default args.
461 $content = apply_filters( 'wp_comment_reply', '', array( 'position' => $position, 'checkbox' => $checkbox, 'mode' => $mode ) );
463 if ( ! empty($content) ) {
468 if ( ! $wp_list_table ) {
469 if ( $mode == 'single' ) {
470 $wp_list_table = _get_list_table('WP_Post_Comments_List_Table');
472 $wp_list_table = _get_list_table('WP_Comments_List_Table');
478 <?php if ( $table_row ) : ?>
479 <table style="display:none;"><tbody id="com-reply"><tr id="replyrow" style="display:none;"><td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="colspanchange">
481 <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;">
483 <div id="replyhead" style="display:none;"><h5><?php _e( 'Reply to Comment' ); ?></h5></div>
484 <div id="addhead" style="display:none;"><h5><?php _e('Add new Comment'); ?></h5></div>
485 <div id="edithead" style="display:none;">
487 <label for="author"><?php _e('Name') ?></label>
488 <input type="text" name="newcomment_author" size="50" value="" id="author" />
492 <label for="author-email"><?php _e('E-mail') ?></label>
493 <input type="text" name="newcomment_author_email" size="50" value="" id="author-email" />
497 <label for="author-url"><?php _e('URL') ?></label>
498 <input type="text" id="author-url" name="newcomment_author_url" class="code" size="103" value="" />
500 <div style="clear:both;"></div>
503 <div id="replycontainer">
505 $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' );
506 wp_editor( '', 'replycontent', array( 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings ) );
510 <p id="replysubmit" class="submit">
511 <a href="#comments-form" class="save button-primary alignright">
512 <span id="addbtn" style="display:none;"><?php _e('Add Comment'); ?></span>
513 <span id="savebtn" style="display:none;"><?php _e('Update Comment'); ?></span>
514 <span id="replybtn" style="display:none;"><?php _e('Submit Reply'); ?></span></a>
515 <a href="#comments-form" class="cancel button-secondary alignleft"><?php _e('Cancel'); ?></a>
516 <span class="waiting spinner"></span>
517 <span class="error" style="display:none;"></span>
521 <input type="hidden" name="action" id="action" value="" />
522 <input type="hidden" name="comment_ID" id="comment_ID" value="" />
523 <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" />
524 <input type="hidden" name="status" id="status" value="" />
525 <input type="hidden" name="position" id="position" value="<?php echo $position; ?>" />
526 <input type="hidden" name="checkbox" id="checkbox" value="<?php echo $checkbox ? 1 : 0; ?>" />
527 <input type="hidden" name="mode" id="mode" value="<?php echo esc_attr($mode); ?>" />
529 wp_nonce_field( 'replyto-comment', '_ajax_nonce-replyto-comment', false );
530 if ( current_user_can( 'unfiltered_html' ) )
531 wp_nonce_field( 'unfiltered-html-comment', '_wp_unfiltered_html_comment', false );
533 <?php if ( $table_row ) : ?>
534 </td></tr></tbody></table>
543 * Output 'undo move to trash' text for comments
547 function wp_comment_trashnotice() {
549 <div class="hidden" id="trash-undo-holder">
550 <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>
552 <div class="hidden" id="spam-undo-holder">
553 <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>
559 * {@internal Missing Short Description}}
565 function list_meta( $meta ) {
569 <table id="list-table" style="display: none;">
572 <th class="left">' . _x( 'Name', 'meta name' ) . '</th>
573 <th>' . __( 'Value' ) . '</th>
576 <tbody id="the-list" data-wp-lists="list:meta">
579 </table>'; //TBODY needed for list-manipulation JS
584 <table id="list-table">
587 <th class="left"><?php _ex( 'Name', 'meta name' ) ?></th>
588 <th><?php _e( 'Value' ) ?></th>
591 <tbody id='the-list' data-wp-lists='list:meta'>
593 foreach ( $meta as $entry )
594 echo _list_meta_row( $entry, $count );
602 * {@internal Missing Short Description}}
606 * @param array $entry
610 function _list_meta_row( $entry, &$count ) {
611 static $update_nonce = false;
613 if ( is_protected_meta( $entry['meta_key'], 'post' ) )
616 if ( !$update_nonce )
617 $update_nonce = wp_create_nonce( 'add-meta' );
622 if ( is_serialized( $entry['meta_value'] ) ) {
623 if ( is_serialized_string( $entry['meta_value'] ) ) {
624 // This is a serialized string, so we should display it.
625 $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
627 // This is a serialized array/object so we should NOT display it.
633 $entry['meta_key'] = esc_attr($entry['meta_key']);
634 $entry['meta_value'] = esc_textarea( $entry['meta_value'] ); // using a <textarea />
635 $entry['meta_id'] = (int) $entry['meta_id'];
637 $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
639 $r .= "\n\t<tr id='meta-{$entry['meta_id']}'>";
640 $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']}' />";
642 $r .= "\n\t\t<div class='submit'>";
643 $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" ) );
645 $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" ) );
647 $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
650 $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>";
655 * Prints the form in the Custom Fields meta box.
659 * @param WP_Post $post Optional. The post being edited.
661 function meta_form( $post = null ) {
663 $post = get_post( $post );
666 * Filter the number of custom fields to retrieve for the drop-down
667 * in the Custom Fields meta box.
671 * @param int $limit Number of custom fields to retrieve. Default 30.
673 $limit = apply_filters( 'postmeta_form_limit', 30 );
674 $sql = "SELECT meta_key
677 HAVING meta_key NOT LIKE %s
680 $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) );
682 natcasesort( $keys );
683 $meta_key_input_id = 'metakeyselect';
685 $meta_key_input_id = 'metakeyinput';
688 <p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p>
692 <th class="left"><label for="<?php echo $meta_key_input_id; ?>"><?php _ex( 'Name', 'meta name' ) ?></label></th>
693 <th><label for="metavalue"><?php _e( 'Value' ) ?></label></th>
699 <td id="newmetaleft" class="left">
700 <?php if ( $keys ) { ?>
701 <select id="metakeyselect" name="metakeyselect">
702 <option value="#NONE#"><?php _e( '— Select —' ); ?></option>
705 foreach ( $keys as $key ) {
706 if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $post->ID, $key ) )
708 echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>";
712 <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" value="" />
713 <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
714 <span id="enternew"><?php _e('Enter new'); ?></span>
715 <span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a>
717 <input type="text" id="metakeyinput" name="metakeyinput" value="" />
720 <td><textarea id="metavalue" name="metavalue" rows="2" cols="25"></textarea></td>
725 <?php submit_button( __( 'Add Custom Field' ), 'secondary', 'addmeta', false, array( 'id' => 'newmeta-submit', 'data-wp-lists' => 'add:the-list:newmeta' ) ); ?>
727 <?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?>
736 * Print out HTML form date elements for editing post or comment publish date.
740 * @param int|bool $edit Accepts 1|true for editing the date, 0|false for adding the date.
741 * @param int|bool $for_post Accepts 1|true for applying the date to a post, 0|false for a comment.
742 * @param int $tab_index The tabindex attribute to add. Default 0.
743 * @param int|bool $multi Optional. Whether the additional fields and buttons should be added.
746 function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
747 global $wp_locale, $comment;
751 $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );
753 $tab_index_attribute = '';
754 if ( (int) $tab_index > 0 )
755 $tab_index_attribute = " tabindex=\"$tab_index\"";
757 // todo: Remove this?
758 // echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />';
760 $time_adj = current_time('timestamp');
761 $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
762 $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
763 $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
764 $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
765 $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
766 $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
767 $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
769 $cur_jj = gmdate( 'd', $time_adj );
770 $cur_mm = gmdate( 'm', $time_adj );
771 $cur_aa = gmdate( 'Y', $time_adj );
772 $cur_hh = gmdate( 'H', $time_adj );
773 $cur_mn = gmdate( 'i', $time_adj );
775 $month = '<label for="mm" class="screen-reader-text">' . __( 'Month' ) . '</label><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n";
776 for ( $i = 1; $i < 13; $i = $i +1 ) {
777 $monthnum = zeroise($i, 2);
778 $month .= "\t\t\t" . '<option value="' . $monthnum . '" ' . selected( $monthnum, $mm, false ) . '>';
779 /* translators: 1: month number (01, 02, etc.), 2: month abbreviation */
780 $month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) ) . "</option>\n";
782 $month .= '</select>';
784 $day = '<label for="jj" class="screen-reader-text">' . __( 'Day' ) . '</label><input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
785 $year = '<label for="aa" class="screen-reader-text">' . __( 'Year' ) . '</label><input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" />';
786 $hour = '<label for="hh" class="screen-reader-text">' . __( 'Hour' ) . '</label><input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
787 $minute = '<label for="mn" class="screen-reader-text">' . __( 'Minute' ) . '</label><input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
789 echo '<div class="timestamp-wrap">';
790 /* translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */
791 printf( __( '%1$s %2$s, %3$s @ %4$s : %5$s' ), $month, $day, $year, $hour, $minute );
793 echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
795 if ( $multi ) return;
799 'mm' => array( $mm, $cur_mm ),
800 'jj' => array( $jj, $cur_jj ),
801 'aa' => array( $aa, $cur_aa ),
802 'hh' => array( $hh, $cur_hh ),
803 'mn' => array( $mn, $cur_mn ),
805 foreach ( $map as $timeunit => $value ) {
806 list( $unit, $curr ) = $value;
808 echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $unit . '" />' . "\n";
809 $cur_timeunit = 'cur_' . $timeunit;
810 echo '<input type="hidden" id="' . $cur_timeunit . '" name="' . $cur_timeunit . '" value="' . $curr . '" />' . "\n";
815 <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a>
816 <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js button-cancel"><?php _e('Cancel'); ?></a>
822 * Print out option HTML elements for the page templates drop-down.
826 * @param string $default Optional. The template file name. Default empty.
828 function page_template_dropdown( $default = '' ) {
829 $templates = get_page_templates( get_post() );
831 foreach ( array_keys( $templates ) as $template ) {
832 $selected = selected( $default, $templates[ $template ], false );
833 echo "\n\t<option value='" . $templates[ $template ] . "' $selected>$template</option>";
838 * Print out option HTML elements for the page parents drop-down.
842 * @param int $default Optional. The default page ID to be pre-selected. Default 0.
843 * @param int $parent Optional. The parent page ID. Default 0.
844 * @param int $level Optional. Page depth level. Default 0.
846 * @return null|false Boolean False if page has no children, otherwise print out html elements
848 function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
851 $items = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent) );
854 foreach ( $items as $item ) {
855 // A page cannot be its own parent.
856 if ( $post && $post->ID && $item->ID == $post->ID )
859 $pad = str_repeat( ' ', $level * 3 );
860 $selected = selected( $default, $item->ID, false );
862 echo "\n\t<option class='level-$level' value='$item->ID' $selected>$pad " . esc_html($item->post_title) . "</option>";
863 parent_dropdown( $default, $item->ID, $level +1 );
871 * Print out option html elements for role selectors.
875 * @param string $selected Slug for the role that should be already selected.
877 function wp_dropdown_roles( $selected = '' ) {
881 $editable_roles = array_reverse( get_editable_roles() );
883 foreach ( $editable_roles as $role => $details ) {
884 $name = translate_user_role($details['name'] );
885 if ( $selected == $role ) // preselect specified role
886 $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
888 $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
894 * Outputs the form used by the importers to accept the data to be imported
898 * @param string $action The action attribute for the form.
900 function wp_import_upload_form( $action ) {
903 * Filter the maximum allowed upload size for import files.
907 * @see wp_max_upload_size()
909 * @param int $max_upload_size Allowed upload size. Default 1 MB.
911 $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
912 $size = size_format( $bytes );
913 $upload_dir = wp_upload_dir();
914 if ( ! empty( $upload_dir['error'] ) ) :
915 ?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
916 <p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
919 <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' ) ); ?>">
921 <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
922 <input type="file" id="upload" name="import" size="25" />
923 <input type="hidden" name="action" value="save" />
924 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
926 <?php submit_button( __('Upload file and import'), 'button' ); ?>
933 * Add a meta box to an edit form.
937 * @param string $id String for use in the 'id' attribute of tags.
938 * @param string $title Title of the meta box.
939 * @param callback $callback Function that fills the box with the desired content.
940 * The function should echo its output.
941 * @param string|WP_Screen $screen Optional. The screen on which to show the box (like a post
942 * type, 'link', or 'comment'). Default is the current screen.
943 * @param string $context Optional. The context within the screen where the boxes
944 * should display. Available contexts vary from screen to
945 * screen. Post edit screen contexts include 'normal', 'side',
946 * and 'advanced'. Comments screen contexts include 'normal'
947 * and 'side'. Menus meta boxes (accordion sections) all use
948 * the 'side' context. Global default is 'advanced'.
949 * @param string $priority Optional. The priority within the context where the boxes
950 * should show ('high', 'low'). Default 'default'.
951 * @param array $callback_args Optional. Data that should be set as the $args property
952 * of the box array (which is the second parameter passed
953 * to your callback). Default null.
955 function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {
956 global $wp_meta_boxes;
958 if ( empty( $screen ) )
959 $screen = get_current_screen();
960 elseif ( is_string( $screen ) )
961 $screen = convert_to_screen( $screen );
965 if ( !isset($wp_meta_boxes) )
966 $wp_meta_boxes = array();
967 if ( !isset($wp_meta_boxes[$page]) )
968 $wp_meta_boxes[$page] = array();
969 if ( !isset($wp_meta_boxes[$page][$context]) )
970 $wp_meta_boxes[$page][$context] = array();
972 foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
973 foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
974 if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
977 // If a core box was previously added or removed by a plugin, don't add.
978 if ( 'core' == $priority ) {
979 // If core box previously deleted, don't add
980 if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
984 * If box was added with default priority, give it core priority to
985 * maintain sort order.
987 if ( 'default' == $a_priority ) {
988 $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
989 unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
993 // If no priority given and id already present, use existing priority.
994 if ( empty($priority) ) {
995 $priority = $a_priority;
997 * Else, if we're adding to the sorted priority, we don't know the title
998 * or callback. Grab them from the previously added context/priority.
1000 } elseif ( 'sorted' == $priority ) {
1001 $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
1002 $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
1003 $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
1005 // An id can be in only one priority and one context.
1006 if ( $priority != $a_priority || $context != $a_context )
1007 unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
1011 if ( empty($priority) )
1014 if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
1015 $wp_meta_boxes[$page][$context][$priority] = array();
1017 $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
1021 * Meta-Box template function
1025 * @staticvar bool $already_sorted
1026 * @param string|WP_Screen $screen Screen identifier
1027 * @param string $context box context
1028 * @param mixed $object gets passed to the box callback function as first parameter
1029 * @return int number of meta_boxes
1031 function do_meta_boxes( $screen, $context, $object ) {
1032 global $wp_meta_boxes;
1033 static $already_sorted = false;
1035 if ( empty( $screen ) )
1036 $screen = get_current_screen();
1037 elseif ( is_string( $screen ) )
1038 $screen = convert_to_screen( $screen );
1040 $page = $screen->id;
1042 $hidden = get_hidden_meta_boxes( $screen );
1044 printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context));
1046 // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
1047 if ( ! $already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) {
1048 foreach ( $sorted as $box_context => $ids ) {
1049 foreach ( explode( ',', $ids ) as $id ) {
1050 if ( $id && 'dashboard_browser_nag' !== $id ) {
1051 add_meta_box( $id, null, null, $screen, $box_context, 'sorted' );
1057 $already_sorted = true;
1061 if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
1062 foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
1063 if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ]) ) {
1064 foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
1065 if ( false == $box || ! $box['title'] )
1068 $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : '';
1069 echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n";
1070 if ( 'dashboard_browser_nag' != $box['id'] )
1071 echo '<div class="handlediv" title="' . esc_attr__('Click to toggle') . '"><br /></div>';
1072 echo "<h3 class='hndle'><span>{$box['title']}</span></h3>\n";
1073 echo '<div class="inside">' . "\n";
1074 call_user_func($box['callback'], $object, $box);
1089 * Remove a meta box from an edit form.
1093 * @param string $id String for use in the 'id' attribute of tags.
1094 * @param string|object $screen The screen on which to show the box (post, page, link).
1095 * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
1097 function remove_meta_box($id, $screen, $context) {
1098 global $wp_meta_boxes;
1100 if ( empty( $screen ) )
1101 $screen = get_current_screen();
1102 elseif ( is_string( $screen ) )
1103 $screen = convert_to_screen( $screen );
1105 $page = $screen->id;
1107 if ( !isset($wp_meta_boxes) )
1108 $wp_meta_boxes = array();
1109 if ( !isset($wp_meta_boxes[$page]) )
1110 $wp_meta_boxes[$page] = array();
1111 if ( !isset($wp_meta_boxes[$page][$context]) )
1112 $wp_meta_boxes[$page][$context] = array();
1114 foreach ( array('high', 'core', 'default', 'low') as $priority )
1115 $wp_meta_boxes[$page][$context][$priority][$id] = false;
1119 * Meta Box Accordion Template Function
1121 * Largely made up of abstracted code from {@link do_meta_boxes()}, this
1122 * function serves to build meta boxes as list items for display as
1123 * a collapsible accordion.
1127 * @uses global $wp_meta_boxes Used to retrieve registered meta boxes.
1129 * @param string|object $screen The screen identifier.
1130 * @param string $context The meta box context.
1131 * @param mixed $object gets passed to the section callback function as first parameter.
1132 * @return int number of meta boxes as accordion sections.
1134 function do_accordion_sections( $screen, $context, $object ) {
1135 global $wp_meta_boxes;
1137 wp_enqueue_script( 'accordion' );
1139 if ( empty( $screen ) )
1140 $screen = get_current_screen();
1141 elseif ( is_string( $screen ) )
1142 $screen = convert_to_screen( $screen );
1144 $page = $screen->id;
1146 $hidden = get_hidden_meta_boxes( $screen );
1148 <div id="side-sortables" class="accordion-container">
1149 <ul class="outer-border">
1152 $first_open = false;
1154 if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
1155 foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
1156 if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
1157 foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
1158 if ( false == $box || ! $box['title'] )
1161 $hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
1164 if ( ! $first_open && empty( $hidden_class ) ) {
1166 $open_class = 'open';
1169 <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'] ); ?>">
1170 <h3 class="accordion-section-title hndle" tabindex="0">
1171 <?php echo esc_html( $box['title'] ); ?>
1172 <span class="screen-reader-text"><?php _e( 'Press return or enter to expand' ); ?></span>
1174 <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
1175 <div class="inside">
1176 <?php call_user_func( $box['callback'], $object, $box ); ?>
1177 </div><!-- .inside -->
1178 </div><!-- .accordion-section-content -->
1179 </li><!-- .accordion-section -->
1186 </ul><!-- .outer-border -->
1187 </div><!-- .accordion-container -->
1193 * Add a new section to a settings page.
1195 * Part of the Settings API. Use this to define new settings sections for an admin page.
1196 * Show settings sections in your admin page callback function with do_settings_sections().
1197 * Add settings fields to your section with add_settings_field()
1199 * The $callback argument should be the name of a function that echoes out any
1200 * content you want to show at the top of the settings section before the actual
1201 * fields. It can output nothing if you want.
1205 * @global $wp_settings_sections Storage array of all settings sections added to admin pages
1207 * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags.
1208 * @param string $title Formatted title of the section. Shown as the heading for the section.
1209 * @param string $callback Function that echos out any content at the top of the section (between heading and fields).
1210 * @param string $page The slug-name of the settings page on which to show the section. Built-in pages include 'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using add_options_page();
1212 function add_settings_section($id, $title, $callback, $page) {
1213 global $wp_settings_sections;
1215 if ( 'misc' == $page ) {
1216 _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) );
1220 if ( 'privacy' == $page ) {
1221 _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) );
1225 $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
1229 * Add a new field to a section of a settings page
1231 * Part of the Settings API. Use this to define a settings field that will show
1232 * as part of a settings section inside a settings page. The fields are shown using
1233 * do_settings_fields() in do_settings-sections()
1235 * The $callback argument should be the name of a function that echoes out the
1236 * html input tags for this setting field. Use get_option() to retrieve existing
1240 * @since 4.2.0 The `$class` argument was added.
1242 * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
1244 * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags.
1245 * @param string $title Formatted title of the field. Shown as the label for the field
1247 * @param string $callback Function that fills the field with the desired form inputs. The
1248 * function should echo its output.
1249 * @param string $page The slug-name of the settings page on which to show the section
1250 * (general, reading, writing, ...).
1251 * @param string $section Optional. The slug-name of the section of the settings page
1252 * in which to show the box. Default 'default'.
1253 * @param array $args {
1254 * Optional. Extra arguments used when outputting the field.
1256 * @type string $label_for When supplied, the setting title will be wrapped
1257 * in a `<label>` element, its `for` attribute populated
1259 * @type string $class CSS Class to be added to the `<tr>` element when the
1263 function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
1264 global $wp_settings_fields;
1266 if ( 'misc' == $page ) {
1267 _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
1271 if ( 'privacy' == $page ) {
1272 _deprecated_argument( __FUNCTION__, '3.5', __( 'The privacy options group has been removed. Use another settings group.' ) );
1276 $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
1280 * Prints out all settings sections added to a particular settings page
1282 * Part of the Settings API. Use this in a settings page callback function
1283 * to output all the sections and fields that were added to that $page with
1284 * add_settings_section() and add_settings_field()
1286 * @global $wp_settings_sections Storage array of all settings sections added to admin pages
1287 * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
1290 * @param string $page The slug name of the page whos settings sections you want to output
1292 function do_settings_sections( $page ) {
1293 global $wp_settings_sections, $wp_settings_fields;
1295 if ( ! isset( $wp_settings_sections[$page] ) )
1298 foreach ( (array) $wp_settings_sections[$page] as $section ) {
1299 if ( $section['title'] )
1300 echo "<h3>{$section['title']}</h3>\n";
1302 if ( $section['callback'] )
1303 call_user_func( $section['callback'], $section );
1305 if ( ! isset( $wp_settings_fields ) || !isset( $wp_settings_fields[$page] ) || !isset( $wp_settings_fields[$page][$section['id']] ) )
1307 echo '<table class="form-table">';
1308 do_settings_fields( $page, $section['id'] );
1314 * Print out the settings fields for a particular settings section
1316 * Part of the Settings API. Use this in a settings page to output
1317 * a specific section. Should normally be called by do_settings_sections()
1318 * rather than directly.
1320 * @global $wp_settings_fields Storage array of settings fields and their pages/sections
1324 * @param string $page Slug title of the admin page who's settings fields you want to show.
1325 * @param string $section Slug title of the settings section who's fields you want to show.
1327 function do_settings_fields($page, $section) {
1328 global $wp_settings_fields;
1330 if ( ! isset( $wp_settings_fields[$page][$section] ) )
1333 foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
1336 if ( ! empty( $field['args']['class'] ) ) {
1337 $class = ' class="' . esc_attr( $field['args']['class'] ) . '"';
1340 echo "<tr{$class}>";
1342 if ( ! empty( $field['args']['label_for'] ) ) {
1343 echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>';
1345 echo '<th scope="row">' . $field['title'] . '</th>';
1349 call_user_func($field['callback'], $field['args']);
1356 * Register a settings error to be displayed to the user
1358 * Part of the Settings API. Use this to show messages to users about settings validation
1359 * problems, missing settings or anything else.
1361 * Settings errors should be added inside the $sanitize_callback function defined in
1362 * register_setting() for a given setting to give feedback about the submission.
1364 * By default messages will show immediately after the submission that generated the error.
1365 * Additional calls to settings_errors() can be used to show errors even when the settings
1366 * page is first accessed.
1370 * @global array $wp_settings_errors Storage array of errors registered during this pageload
1372 * @param string $setting Slug title of the setting to which this error applies
1373 * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
1374 * @param string $message The formatted message text to display to the user (will be shown inside styled
1375 * `<div>` and `<p>` tags).
1376 * @param string $type Optional. Message type, controls HTML class. Accepts 'error' or 'updated'.
1379 function add_settings_error( $setting, $code, $message, $type = 'error' ) {
1380 global $wp_settings_errors;
1382 $wp_settings_errors[] = array(
1383 'setting' => $setting,
1385 'message' => $message,
1391 * Fetch settings errors registered by add_settings_error()
1393 * Checks the $wp_settings_errors array for any errors declared during the current
1394 * pageload and returns them.
1396 * If changes were just submitted ($_GET['settings-updated']) and settings errors were saved
1397 * to the 'settings_errors' transient then those errors will be returned instead. This
1398 * is used to pass errors back across pageloads.
1400 * Use the $sanitize argument to manually re-sanitize the option before returning errors.
1401 * This is useful if you have errors or notices you want to show even when the user
1402 * hasn't submitted data (i.e. when they first load an options page, or in admin_notices action hook)
1406 * @global array $wp_settings_errors Storage array of errors registered during this pageload
1408 * @param string $setting Optional slug title of a specific setting who's errors you want.
1409 * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
1410 * @return array Array of settings errors
1412 function get_settings_errors( $setting = '', $sanitize = false ) {
1413 global $wp_settings_errors;
1416 * If $sanitize is true, manually re-run the sanitization for this option
1417 * This allows the $sanitize_callback from register_setting() to run, adding
1418 * any settings errors you want to show by default.
1421 sanitize_option( $setting, get_option( $setting ) );
1423 // If settings were passed back from options.php then use them.
1424 if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && get_transient( 'settings_errors' ) ) {
1425 $wp_settings_errors = array_merge( (array) $wp_settings_errors, get_transient( 'settings_errors' ) );
1426 delete_transient( 'settings_errors' );
1429 // Check global in case errors have been added on this pageload.
1430 if ( ! count( $wp_settings_errors ) )
1433 // Filter the results to those of a specific setting if one was set.
1435 $setting_errors = array();
1436 foreach ( (array) $wp_settings_errors as $key => $details ) {
1437 if ( $setting == $details['setting'] )
1438 $setting_errors[] = $wp_settings_errors[$key];
1440 return $setting_errors;
1443 return $wp_settings_errors;
1447 * Display settings errors registered by {@see add_settings_error()}.
1449 * Part of the Settings API. Outputs a div for each error retrieved by
1450 * {@see get_settings_errors()}.
1452 * This is called automatically after a settings page based on the
1453 * Settings API is submitted. Errors should be added during the validation
1454 * callback function for a setting defined in {@see register_setting()}
1456 * The $sanitize option is passed into {@see get_settings_errors()} and will
1457 * re-run the setting sanitization
1458 * on its current value.
1460 * The $hide_on_update option will cause errors to only show when the settings
1461 * page is first loaded. if the user has already saved new values it will be
1462 * hidden to avoid repeating messages already shown in the default error
1463 * reporting after submission. This is useful to show general errors like
1464 * missing settings when the user arrives at the settings page.
1468 * @param string $setting Optional slug title of a specific setting who's errors you want.
1469 * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
1470 * @param boolean $hide_on_update If set to true errors will not be shown if the settings page has already been submitted.
1472 function settings_errors( $setting = '', $sanitize = false, $hide_on_update = false ) {
1474 if ( $hide_on_update && ! empty( $_GET['settings-updated'] ) )
1477 $settings_errors = get_settings_errors( $setting, $sanitize );
1479 if ( empty( $settings_errors ) )
1483 foreach ( $settings_errors as $key => $details ) {
1484 $css_id = 'setting-error-' . $details['code'];
1485 $css_class = $details['type'] . ' settings-error notice is-dismissible';
1486 $output .= "<div id='$css_id' class='$css_class'> \n";
1487 $output .= "<p><strong>{$details['message']}</strong></p>";
1488 $output .= "</div> \n";
1494 * {@internal Missing Short Description}}
1498 * @param string $found_action
1500 function find_posts_div($found_action = '') {
1502 <div id="find-posts" class="find-box" style="display: none;">
1503 <div id="find-posts-head" class="find-box-head">
1504 <?php _e( 'Find Posts or Pages' ); ?>
1505 <div id="find-posts-close"></div>
1507 <div class="find-box-inside">
1508 <div class="find-box-search">
1509 <?php if ( $found_action ) { ?>
1510 <input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" />
1512 <input type="hidden" name="affected" id="affected" value="" />
1513 <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
1514 <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
1515 <input type="text" id="find-posts-input" name="ps" value="" />
1516 <span class="spinner"></span>
1517 <input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" />
1518 <div class="clear"></div>
1520 <div id="find-posts-response"></div>
1522 <div class="find-box-buttons">
1523 <?php submit_button( __( 'Select' ), 'button-primary alignright', 'find-posts-submit', false ); ?>
1524 <div class="clear"></div>
1531 * Display the post password.
1533 * The password is passed through {@link esc_attr()} to ensure that it
1534 * is safe for placing in an html attribute.
1538 function the_post_password() {
1540 if ( isset( $post->post_password ) )
1541 echo esc_attr( $post->post_password );
1545 * Get the post title.
1547 * The post title is fetched and if it is blank then a default string is
1552 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
1553 * @return string The post title if set.
1555 function _draft_or_post_title( $post = 0 ) {
1556 $title = get_the_title( $post );
1557 if ( empty( $title ) )
1558 $title = __( '(no title)' );
1559 return esc_html( $title );
1563 * Display the search query.
1565 * A simple wrapper to display the "s" parameter in a GET URI. This function
1566 * should only be used when {@link the_search_query()} cannot.
1570 function _admin_search_query() {
1571 echo isset($_REQUEST['s']) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : '';
1575 * Generic Iframe header for use with Thickbox
1579 * @param string $title Optional. Title of the Iframe page. Default empty.
1580 * @param bool $deprecated Not used.
1582 function iframe_header( $title = '', $deprecated = false ) {
1583 show_admin_bar( false );
1584 global $hook_suffix, $admin_body_class, $wp_locale;
1585 $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
1587 $current_screen = get_current_screen();
1589 @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
1590 _wp_admin_html_begin();
1592 <title><?php bloginfo('name') ?> › <?php echo $title ?> — <?php _e('WordPress'); ?></title>
1594 wp_enqueue_style( 'colors' );
1596 <script type="text/javascript">
1597 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();}}};
1598 function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
1599 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>',
1600 pagenow = '<?php echo $current_screen->id; ?>',
1601 typenow = '<?php echo $current_screen->post_type; ?>',
1602 adminpage = '<?php echo $admin_body_class; ?>',
1603 thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
1604 decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
1605 isRtl = <?php echo (int) is_rtl(); ?>;
1608 /** This action is documented in wp-admin/admin-header.php */
1609 do_action( 'admin_enqueue_scripts', $hook_suffix );
1611 /** This action is documented in wp-admin/admin-header.php */
1612 do_action( "admin_print_styles-$hook_suffix" );
1614 /** This action is documented in wp-admin/admin-header.php */
1615 do_action( 'admin_print_styles' );
1617 /** This action is documented in wp-admin/admin-header.php */
1618 do_action( "admin_print_scripts-$hook_suffix" );
1620 /** This action is documented in wp-admin/admin-header.php */
1621 do_action( 'admin_print_scripts' );
1623 /** This action is documented in wp-admin/admin-header.php */
1624 do_action( "admin_head-$hook_suffix" );
1626 /** This action is documented in wp-admin/admin-header.php */
1627 do_action( 'admin_head' );
1629 $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
1632 $admin_body_class .= ' rtl';
1637 /** This filter is documented in wp-admin/admin-header.php */
1638 $admin_body_classes = apply_filters( 'admin_body_class', '' );
1640 <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; ?>">
1641 <script type="text/javascript">
1643 var c = document.body.className;
1644 c = c.replace(/no-js/, 'js');
1645 document.body.className = c;
1652 * Generic Iframe footer for use with Thickbox
1656 function iframe_footer() {
1658 * We're going to hide any footer output on iFrame pages,
1659 * but run the hooks anyway since they output JavaScript
1660 * or other needed content.
1663 <div class="hidden">
1665 /** This action is documented in wp-admin/admin-footer.php */
1666 do_action( 'admin_footer', '' );
1668 /** This action is documented in wp-admin/admin-footer.php */
1669 do_action( 'admin_print_footer_scripts' );
1672 <script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script>
1678 function _post_states($post) {
1679 $post_states = array();
1680 if ( isset( $_REQUEST['post_status'] ) )
1681 $post_status = $_REQUEST['post_status'];
1685 if ( !empty($post->post_password) )
1686 $post_states['protected'] = __('Password protected');
1687 if ( 'private' == $post->post_status && 'private' != $post_status )
1688 $post_states['private'] = __('Private');
1689 if ( 'draft' == $post->post_status && 'draft' != $post_status )
1690 $post_states['draft'] = __('Draft');
1691 if ( 'pending' == $post->post_status && 'pending' != $post_status )
1692 /* translators: post state */
1693 $post_states['pending'] = _x('Pending', 'post state');
1694 if ( is_sticky($post->ID) )
1695 $post_states['sticky'] = __('Sticky');
1697 if ( get_option( 'page_on_front' ) == $post->ID ) {
1698 $post_states['page_on_front'] = __( 'Front Page' );
1701 if ( get_option( 'page_for_posts' ) == $post->ID ) {
1702 $post_states['page_for_posts'] = __( 'Posts Page' );
1706 * Filter the default post display states used in the posts list table.
1710 * @param array $post_states An array of post display states.
1711 * @param int $post The post ID.
1713 $post_states = apply_filters( 'display_post_states', $post_states, $post );
1715 if ( ! empty($post_states) ) {
1716 $state_count = count($post_states);
1719 foreach ( $post_states as $state ) {
1721 ( $i == $state_count ) ? $sep = '' : $sep = ', ';
1722 echo "<span class='post-state'>$state$sep</span>";
1728 function _media_states( $post ) {
1729 $media_states = array();
1730 $stylesheet = get_option('stylesheet');
1732 if ( current_theme_supports( 'custom-header') ) {
1733 $meta_header = get_post_meta($post->ID, '_wp_attachment_is_custom_header', true );
1734 if ( ! empty( $meta_header ) && $meta_header == $stylesheet )
1735 $media_states[] = __( 'Header Image' );
1738 if ( current_theme_supports( 'custom-background') ) {
1739 $meta_background = get_post_meta($post->ID, '_wp_attachment_is_custom_background', true );
1740 if ( ! empty( $meta_background ) && $meta_background == $stylesheet )
1741 $media_states[] = __( 'Background Image' );
1745 * Filter the default media display states for items in the Media list table.
1749 * @param array $media_states An array of media states. Default 'Header Image',
1750 * 'Background Image'.
1752 $media_states = apply_filters( 'display_media_states', $media_states );
1754 if ( ! empty( $media_states ) ) {
1755 $state_count = count( $media_states );
1758 foreach ( $media_states as $state ) {
1760 ( $i == $state_count ) ? $sep = '' : $sep = ', ';
1761 echo "<span class='post-state'>$state$sep</span>";
1767 * Test support for compressing JavaScript from PHP
1769 * Outputs JavaScript that tests if compression from PHP works as expected
1770 * and sets an option with the result. Has no effect when the current user
1771 * is not an administrator. To run the test again the option 'can_compress_scripts'
1772 * has to be deleted.
1776 function compression_test() {
1778 <script type="text/javascript">
1779 var testCompression = {
1780 get : function(test) {
1782 if ( window.XMLHttpRequest ) {
1783 x = new XMLHttpRequest();
1785 try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
1789 x.onreadystatechange = function() {
1791 if ( x.readyState == 4 ) {
1792 r = x.responseText.substr(0, 18);
1793 h = x.getResponseHeader('Content-Encoding');
1794 testCompression.check(r, h, test);
1798 x.open('GET', ajaxurl + '?action=wp-compression-test&test='+test+'&'+(new Date()).getTime(), true);
1803 check : function(r, h, test) {
1804 if ( ! r && ! test )
1808 if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) )
1817 if ( '"wpCompressionTest' == r )
1824 testCompression.check();
1830 * Echoes a submit button, with provided text and appropriate class(es).
1834 * @see get_submit_button()
1836 * @param string $text The text of the button (defaults to 'Save Changes')
1837 * @param string $type Optional. The type and CSS class(es) of the button. Core values
1838 * include 'primary', 'secondary', 'delete'. Default 'primary'
1839 * @param string $name The HTML name of the submit button. Defaults to "submit". If no
1840 * id attribute is given in $other_attributes below, $name will be
1841 * used as the button's id.
1842 * @param bool $wrap True if the output button should be wrapped in a paragraph tag,
1843 * false otherwise. Defaults to true
1844 * @param array|string $other_attributes Other attributes that should be output with the button, mapping
1845 * attributes to their values, such as setting tabindex to 1, etc.
1846 * These key/value attribute pairs will be output as attribute="value",
1847 * where attribute is the key. Other attributes can also be provided
1848 * as a string such as 'tabindex="1"', though the array format is
1849 * preferred. Default null.
1851 function submit_button( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null ) {
1852 echo get_submit_button( $text, $type, $name, $wrap, $other_attributes );
1856 * Returns a submit button, with provided text and appropriate class
1860 * @param string $text Optional. The text of the button. Default 'Save Changes'.
1861 * @param string $type Optional. The type of button. Accepts 'primary', 'secondary',
1862 * or 'delete'. Default 'primary large'.
1863 * @param string $name Optional. The HTML name of the submit button. Defaults to "submit".
1864 * If no id attribute is given in $other_attributes below, `$name` will
1865 * be used as the button's id. Default 'submit'.
1866 * @param bool $wrap Optional. True if the output button should be wrapped in a paragraph
1867 * tag, false otherwise. Default true.
1868 * @param array|string $other_attributes Optional. Other attributes that should be output with the button,
1869 * mapping attributes to their values, such as `array( 'tabindex' => '1' )`.
1870 * These attributes will be output as `attribute="value"`, such as
1871 * `tabindex="1"`. Other attributes can also be provided as a string such
1872 * as `tabindex="1"`, though the array format is typically cleaner.
1874 * @return string Submit button HTML.
1876 function get_submit_button( $text = '', $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = '' ) {
1877 if ( ! is_array( $type ) )
1878 $type = explode( ' ', $type );
1880 $button_shorthand = array( 'primary', 'small', 'large' );
1881 $classes = array( 'button' );
1882 foreach ( $type as $t ) {
1883 if ( 'secondary' === $t || 'button-secondary' === $t )
1885 $classes[] = in_array( $t, $button_shorthand ) ? 'button-' . $t : $t;
1887 $class = implode( ' ', array_unique( $classes ) );
1889 if ( 'delete' === $type )
1890 $class = 'button-secondary delete';
1892 $text = $text ? $text : __( 'Save Changes' );
1894 // Default the id attribute to $name unless an id was specifically provided in $other_attributes
1896 if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) {
1897 $id = $other_attributes['id'];
1898 unset( $other_attributes['id'] );
1902 if ( is_array( $other_attributes ) ) {
1903 foreach ( $other_attributes as $attribute => $value ) {
1904 $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
1906 } elseif ( ! empty( $other_attributes ) ) { // Attributes provided as a string
1907 $attributes = $other_attributes;
1910 // Don't output empty name and id attributes.
1911 $name_attr = $name ? ' name="' . esc_attr( $name ) . '"' : '';
1912 $id_attr = $id ? ' id="' . esc_attr( $id ) . '"' : '';
1914 $button = '<input type="submit"' . $name_attr . $id_attr . ' class="' . esc_attr( $class );
1915 $button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />';
1918 $button = '<p class="submit">' . $button . '</p>';
1924 function _wp_admin_html_begin() {
1927 $admin_html_class = ( is_admin_bar_showing() ) ? 'wp-toolbar' : '';
1930 @header('X-UA-Compatible: IE=edge');
1935 <html xmlns="http://www.w3.org/1999/xhtml" class="ie8 <?php echo $admin_html_class; ?>" <?php
1937 * Fires inside the HTML tag in the admin header.
1941 do_action( 'admin_xml_ns' );
1942 ?> <?php language_attributes(); ?>>
1944 <!--[if !(IE 8) ]><!-->
1945 <html xmlns="http://www.w3.org/1999/xhtml" class="<?php echo $admin_html_class; ?>" <?php
1946 /** This action is documented in wp-admin/includes/template.php */
1947 do_action( 'admin_xml_ns' );
1948 ?> <?php language_attributes(); ?>>
1951 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
1955 final class WP_Internal_Pointers {
1957 * Initializes the new feature pointers.
1961 * All pointers can be disabled using the following:
1962 * remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
1964 * Individual pointers (e.g. wp390_widgets) can be disabled using the following:
1965 * remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp390_widgets' ) );
1967 * @param string $hook_suffix The current admin page.
1969 public static function enqueue_scripts( $hook_suffix ) {
1971 * Register feature pointers
1972 * Format: array( hook_suffix => pointer_id )
1975 $registered_pointers = array(
1976 'post-new.php' => 'wp410_dfw',
1977 'post.php' => 'wp410_dfw',
1978 'edit.php' => 'wp360_locks',
1979 'widgets.php' => 'wp390_widgets',
1980 'themes.php' => 'wp390_widgets',
1983 // Check if screen related pointer is registered
1984 if ( empty( $registered_pointers[ $hook_suffix ] ) )
1987 $pointers = (array) $registered_pointers[ $hook_suffix ];
1989 $caps_required = array(
1990 'wp390_widgets' => array( 'edit_theme_options' ),
1993 // Get dismissed pointers
1994 $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
1996 $got_pointers = false;
1997 foreach ( array_diff( $pointers, $dismissed ) as $pointer ) {
1998 if ( isset( $caps_required[ $pointer ] ) ) {
1999 foreach ( $caps_required[ $pointer ] as $cap ) {
2000 if ( ! current_user_can( $cap ) )
2005 // Bind pointer print function
2006 add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) );
2007 $got_pointers = true;
2010 if ( ! $got_pointers )
2013 // Add pointers script and style to queue
2014 wp_enqueue_style( 'wp-pointer' );
2015 wp_enqueue_script( 'wp-pointer' );
2019 * Print the pointer JavaScript data.
2023 * @param string $pointer_id The pointer ID.
2024 * @param string $selector The HTML elements, on which the pointer should be attached.
2025 * @param array $args Arguments to be passed to the pointer JS (see wp-pointer.js).
2027 private static function print_js( $pointer_id, $selector, $args ) {
2028 if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) )
2032 <script type="text/javascript">
2034 var options = <?php echo wp_json_encode( $args ); ?>, setup;
2039 options = $.extend( options, {
2042 pointer: '<?php echo $pointer_id; ?>',
2043 action: 'dismiss-wp-pointer'
2048 setup = function() {
2049 $('<?php echo $selector; ?>').first().pointer( options ).pointer('open');
2052 if ( options.position && options.position.defer_loading )
2053 $(window).bind( 'load.wp-pointers', setup );
2055 $(document).ready( setup );
2062 public static function pointer_wp330_toolbar() {}
2063 public static function pointer_wp330_media_uploader() {}
2064 public static function pointer_wp330_saving_widgets() {}
2065 public static function pointer_wp340_customize_current_theme_link() {}
2066 public static function pointer_wp340_choose_image_from_library() {}
2067 public static function pointer_wp350_media() {}
2068 public static function pointer_wp360_revisions() {}
2070 public static function pointer_wp360_locks() {
2071 if ( ! is_multi_author() ) {
2075 $content = '<h3>' . __( 'Edit Lock' ) . '</h3>';
2076 $content .= '<p>' . __( 'Someone else is editing this. No need to refresh; the lock will disappear when they’re done.' ) . '</p>';
2078 self::print_js( 'wp360_locks', 'tr.wp-locked .locked-indicator', array(
2079 'content' => $content,
2080 'position' => array( 'edge' => 'left', 'align' => 'left' ),
2084 public static function pointer_wp390_widgets() {
2085 if ( ! current_theme_supports( 'widgets' ) ) {
2089 $content = '<h3>' . __( 'New Feature: Live Widget Previews' ) . '</h3>';
2090 $content .= '<p>' . __( 'Add, edit, and play around with your widgets from the Customizer.' ) . ' ' . __( 'Preview your changes in real-time and only save them when you’re ready.' ) . '</p>';
2092 if ( 'themes' === get_current_screen()->id ) {
2093 $selector = '.theme.active .customize';
2094 $position = array( 'edge' => is_rtl() ? 'right' : 'left', 'align' => 'center' );
2096 $selector = 'a[href^="customize.php"]';
2098 $position = array( 'edge' => 'right', 'align' => 'center', 'my' => 'right-5px' );
2100 $position = array( 'edge' => 'left', 'align' => 'center', 'my' => 'left-5px' );
2104 self::print_js( 'wp390_widgets', $selector, array(
2105 'content' => $content,
2106 'position' => $position,
2110 public static function pointer_wp410_dfw() {
2111 // Don't show when editor-scrolling is not used.
2112 if ( empty( $GLOBALS['_wp_editor_expand'] ) ) {
2116 $content = '<h3>' . __( 'Distraction-Free Writing' ) . '</h3>';
2117 $content .= '<p>' . __( 'Enable distraction-free writing mode, and everything surrounding the editor will fade away when you start typing. Move your mouse out of the editor to reveal everything again.' ) . '</p>';
2120 $position = array( 'edge' => 'left', 'align' => 'center', 'my' => 'left+40 top-11', 'at' => 'left top' );
2122 $position = array( 'edge' => 'right', 'align' => 'center', 'my' => 'right-40 top-11', 'at' => 'right top' );
2125 self::print_js( 'wp410_dfw', '#wp-content-wrap', array(
2126 'content' => $content,
2127 'position' => $position,
2132 * Prevents new users from seeing existing 'new feature' pointers.
2136 * @param int $user_id User ID.
2138 public static function dismiss_pointers_for_new_users( $user_id ) {
2139 add_user_meta( $user_id, 'dismissed_wp_pointers', 'wp360_locks,wp390_widgets' );
2143 add_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
2144 add_action( 'user_register', array( 'WP_Internal_Pointers', 'dismiss_pointers_for_new_users' ) );
2147 * Convert a screen string to a screen object
2151 * @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen.
2152 * @return WP_Screen Screen object.
2154 function convert_to_screen( $hook_name ) {
2155 if ( ! class_exists( 'WP_Screen' ) ) {
2156 _doing_it_wrong( 'convert_to_screen(), add_meta_box()', __( "Likely direct inclusion of wp-admin/includes/template.php in order to use add_meta_box(). This is very wrong. Hook the add_meta_box() call into the add_meta_boxes action instead." ), '3.3' );
2157 return (object) array( 'id' => '_invalid', 'base' => '_are_belong_to_us' );
2160 return WP_Screen::get( $hook_name );
2164 * Output the HTML for restoring the post data from DOM storage
2169 function _local_storage_notice() {
2171 <div id="local-storage-notice" class="hidden notice">
2172 <p class="local-restore">
2173 <?php _e('The backup of this post in your browser is different from the version below.'); ?>
2174 <a class="restore-backup" href="#"><?php _e('Restore the backup.'); ?></a>
2176 <p class="undo-restore hidden">
2177 <?php _e('Post restored successfully.'); ?>
2178 <a class="undo-restore-backup" href="#"><?php _e('Undo.'); ?></a>
2185 * Output a HTML element with a star rating for a given rating.
2187 * Outputs a HTML element with the star rating exposed on a 0..5 scale in
2188 * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the
2189 * number of ratings may also be displayed by passing the $number parameter.
2192 * @param array $args {
2193 * Optional. Array of star ratings arguments.
2195 * @type int $rating The rating to display, expressed in either a 0.5 rating increment,
2196 * or percentage. Default 0.
2197 * @type string $type Format that the $rating is in. Valid values are 'rating' (default),
2198 * or, 'percent'. Default 'rating'.
2199 * @type int $number The number of ratings that makes up this rating. Default 0.
2202 function wp_star_rating( $args = array() ) {
2208 $r = wp_parse_args( $args, $defaults );
2210 // Non-english decimal places when the $rating is coming from a string
2211 $rating = str_replace( ',', '.', $r['rating'] );
2213 // Convert Percentage to star rating, 0..5 in .5 increments
2214 if ( 'percent' == $r['type'] ) {
2215 $rating = round( $rating / 10, 0 ) / 2;
2218 // Calculate the number of each type of star needed
2219 $full_stars = floor( $rating );
2220 $half_stars = ceil( $rating - $full_stars );
2221 $empty_stars = 5 - $full_stars - $half_stars;
2223 if ( $r['number'] ) {
2224 /* translators: 1: The rating, 2: The number of ratings */
2225 $format = _n( '%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $r['number'] );
2226 $title = sprintf( $format, number_format_i18n( $rating, 1 ), number_format_i18n( $r['number'] ) );
2228 /* translators: 1: The rating */
2229 $title = sprintf( __( '%s rating' ), number_format_i18n( $rating, 1 ) );
2232 echo '<div class="star-rating" title="' . esc_attr( $title ) . '">';
2233 echo '<span class="screen-reader-text">' . $title . '</span>';
2234 echo str_repeat( '<div class="star star-full"></div>', $full_stars );
2235 echo str_repeat( '<div class="star star-half"></div>', $half_stars );
2236 echo str_repeat( '<div class="star star-empty"></div>', $empty_stars);
2241 * Output a notice when editing the page for posts (internal use only).
2246 function _wp_posts_page_notice() {
2247 echo '<div class="notice notice-warning inline"><p>' . __( 'You are currently editing the page that shows your latest posts.' ) . '</p></div>';