WordPress.org

Make WordPress Core

Changeset 34241


Ignore:
Timestamp:
09/16/2015 03:34:17 PM (4 years ago)
Author:
wonderboymusic
Message:

wp-admin/includes/template.php is now a loader for 3 files made via svn cp:

  • Walker_Category_Checklist class
  • WP_Internal_Pointers class
  • template-functions.php

This is BC for plugins that are loading wp-admin/includes/template.php for fun.

See #33413.

Location:
trunk/src/wp-admin/includes
Files:
1 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-walker-category-checklist.php

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

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

    r34238 r34241  
    77 * @package WordPress
    88 * @subpackage Administration
     9 * @since 4.4.0
    910 */
    1011
     
    1213// Category Checklists
    1314//
    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 
    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"' : '';
    88 
    89         $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
    90 
    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';
    95 
    96             if ( in_array( $category->term_id, $args['selected_cats'] ) ) {
    97                 $inner_class .= ' selected';
    98                 $aria_cheched = 'true';
    99             }
    100 
    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>';
    105         } else {
    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>';
    111         }
    112     }
    113 
    114     /**
    115      * Ends the element output, if needed.
    116      *
    117      * @see Walker::end_el()
    118      *
    119      * @since 2.5.1
    120      *
    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()
    125      */
    126     public function end_el( &$output, $category, $depth = 0, $args = array() ) {
    127         $output .= "</li>\n";
    128     }
    129 }
    13015
    13116/**
     
    20161901}
    20171902
    2018 final class WP_Internal_Pointers {
    2019     /**
    2020      * Initializes the new feature pointers.
    2021      *
    2022      * @since 3.3.0
    2023      *
    2024      * All pointers can be disabled using the following:
    2025      *     remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
    2026      *
    2027      * Individual pointers (e.g. wp390_widgets) can be disabled using the following:
    2028      *     remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp390_widgets' ) );
    2029      *
    2030      * @static
    2031      *
    2032      * @param string $hook_suffix The current admin page.
    2033      */
    2034     public static function enqueue_scripts( $hook_suffix ) {
    2035         /*
    2036          * Register feature pointers
    2037          *
    2038          * Format:
    2039          *     array(
    2040          *         hook_suffix => pointer callback
    2041          *     )
    2042          *
    2043          * Example:
    2044          *     array(
    2045          *         'themes.php' => 'wp390_widgets'
    2046          *     )
    2047          */
    2048         $registered_pointers = array(
    2049             // None currently
    2050         );
    2051 
    2052         // Check if screen related pointer is registered
    2053         if ( empty( $registered_pointers[ $hook_suffix ] ) )
    2054             return;
    2055 
    2056         $pointers = (array) $registered_pointers[ $hook_suffix ];
    2057 
    2058         /*
    2059          * Specify required capabilities for feature pointers
    2060          *
    2061          * Format:
    2062          *     array(
    2063          *         pointer callback => Array of required capabilities
    2064          *     )
    2065          *
    2066          * Example:
    2067          *     array(
    2068          *         'wp390_widgets' => array( 'edit_theme_options' )
    2069          *     )
    2070          */
    2071         $caps_required = array(
    2072             // None currently
    2073         );
    2074 
    2075         // Get dismissed pointers
    2076         $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
    2077 
    2078         $got_pointers = false;
    2079         foreach ( array_diff( $pointers, $dismissed ) as $pointer ) {
    2080             if ( isset( $caps_required[ $pointer ] ) ) {
    2081                 foreach ( $caps_required[ $pointer ] as $cap ) {
    2082                     if ( ! current_user_can( $cap ) )
    2083                         continue 2;
    2084                 }
    2085             }
    2086 
    2087             // Bind pointer print function
    2088             add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) );
    2089             $got_pointers = true;
    2090         }
    2091 
    2092         if ( ! $got_pointers )
    2093             return;
    2094 
    2095         // Add pointers script and style to queue
    2096         wp_enqueue_style( 'wp-pointer' );
    2097         wp_enqueue_script( 'wp-pointer' );
    2098     }
    2099 
    2100     /**
    2101      * Print the pointer JavaScript data.
    2102      *
    2103      * @since 3.3.0
    2104      *
    2105      * @static
    2106      *
    2107      * @param string $pointer_id The pointer ID.
    2108      * @param string $selector The HTML elements, on which the pointer should be attached.
    2109      * @param array  $args Arguments to be passed to the pointer JS (see wp-pointer.js).
    2110      */
    2111     private static function print_js( $pointer_id, $selector, $args ) {
    2112         if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) )
    2113             return;
    2114 
    2115         ?>
    2116         <script type="text/javascript">
    2117         (function($){
    2118             var options = <?php echo wp_json_encode( $args ); ?>, setup;
    2119 
    2120             if ( ! options )
    2121                 return;
    2122 
    2123             options = $.extend( options, {
    2124                 close: function() {
    2125                     $.post( ajaxurl, {
    2126                         pointer: '<?php echo $pointer_id; ?>',
    2127                         action: 'dismiss-wp-pointer'
    2128                     });
    2129                 }
    2130             });
    2131 
    2132             setup = function() {
    2133                 $('<?php echo $selector; ?>').first().pointer( options ).pointer('open');
    2134             };
    2135 
    2136             if ( options.position && options.position.defer_loading )
    2137                 $(window).bind( 'load.wp-pointers', setup );
    2138             else
    2139                 $(document).ready( setup );
    2140 
    2141         })( jQuery );
    2142         </script>
    2143         <?php
    2144     }
    2145 
    2146     public static function pointer_wp330_toolbar() {}
    2147     public static function pointer_wp330_media_uploader() {}
    2148     public static function pointer_wp330_saving_widgets() {}
    2149     public static function pointer_wp340_customize_current_theme_link() {}
    2150     public static function pointer_wp340_choose_image_from_library() {}
    2151     public static function pointer_wp350_media() {}
    2152     public static function pointer_wp360_revisions() {}
    2153     public static function pointer_wp360_locks() {}
    2154     public static function pointer_wp390_widgets() {}
    2155     public static function pointer_wp410_dfw() {}
    2156 
    2157     /**
    2158      * Prevents new users from seeing existing 'new feature' pointers.
    2159      *
    2160      * @since 3.3.0
    2161      *
    2162      * @static
    2163      *
    2164      * @param int $user_id User ID.
    2165      */
    2166     public static function dismiss_pointers_for_new_users( $user_id ) {
    2167         add_user_meta( $user_id, 'dismissed_wp_pointers', '' );
    2168     }
    2169 }
    2170 
    21711903/**
    21721904 * Convert a screen string to a screen object
  • trunk/src/wp-admin/includes/template.php

    r34111 r34241  
    99 */
    1010
    11 //
    12 // Category Checklists
    13 //
     11/** Walker_Category_Checklist class */
     12require_once( ABSPATH . 'wp-admin/includes/class-walker-category-checklist.php' );
    1413
    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
     14/** WP_Internal_Pointers class */
     15require_once( ABSPATH . 'wp-admin/includes/class-wp-internal-pointers.php' );
    2716
    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 
    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"' : '';
    88 
    89         $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
    90 
    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';
    95 
    96             if ( in_array( $category->term_id, $args['selected_cats'] ) ) {
    97                 $inner_class .= ' selected';
    98                 $aria_cheched = 'true';
    99             }
    100 
    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>';
    105         } else {
    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>';
    111         }
    112     }
    113 
    114     /**
    115      * Ends the element output, if needed.
    116      *
    117      * @see Walker::end_el()
    118      *
    119      * @since 2.5.1
    120      *
    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()
    125      */
    126     public function end_el( &$output, $category, $depth = 0, $args = array() ) {
    127         $output .= "</li>\n";
    128     }
    129 }
    130 
    131 /**
    132  * Output an unordered list of checkbox input elements labeled with category names.
    133  *
    134  * @since 2.5.1
    135  *
    136  * @see wp_terms_checklist()
    137  *
    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.
    141  *                                     Default 0.
    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.
    144  *                                     Default false.
    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.
    149  */
    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,
    156         'walker' => $walker,
    157         'checked_ontop' => $checked_ontop
    158     ) );
    159 }
    160 
    161 /**
    162  * Output an unordered list of checkbox input elements labelled with term names.
    163  *
    164  * Taxonomy-independent version of wp_category_checklist().
    165  *
    166  * @since 3.0.0
    167  * @since 4.4.0 Introduced the `$echo` argument.
    168  *
    169  * @param int          $post_id Optional. Post ID. Default 0.
    170  * @param array|string $args {
    171  *     Optional. Array or string of arguments for generating a terms checklist. Default empty array.
    172  *
    173  *     @type int    $descendants_and_self ID of the category to output along with its descendants.
    174  *                                        Default 0.
    175  *     @type array  $selected_cats        List of categories to mark as checked. Default false.
    176  *     @type array  $popular_cats         List of categories to receive the "popular-category" class.
    177  *                                        Default false.
    178  *     @type object $walker               Walker object to use to build the output.
    179  *                                        Default is a Walker_Category_Checklist instance.
    180  *     @type string $taxonomy             Taxonomy to generate the checklist for. Default 'category'.
    181  *     @type bool   $checked_ontop        Whether to move checked items out of the hierarchy and to
    182  *                                        the top of the list. Default true.
    183  *     @type bool   $echo                 Whether to echo the generated markup. False to return the markup instead
    184  *                                        of echoing it. Default true.
    185  * }
    186  */
    187 function wp_terms_checklist( $post_id = 0, $args = array() ) {
    188     $defaults = array(
    189         'descendants_and_self' => 0,
    190         'selected_cats' => false,
    191         'popular_cats' => false,
    192         'walker' => null,
    193         'taxonomy' => 'category',
    194         'checked_ontop' => true,
    195         'echo' => true,
    196     );
    197 
    198     /**
    199      * Filter the taxonomy terms checklist arguments.
    200      *
    201      * @since 3.4.0
    202      *
    203      * @see wp_terms_checklist()
    204      *
    205      * @param array $args    An array of arguments.
    206      * @param int   $post_id The post ID.
    207      */
    208     $params = apply_filters( 'wp_terms_checklist_args', $args, $post_id );
    209 
    210     $r = wp_parse_args( $params, $defaults );
    211 
    212     if ( empty( $r['walker'] ) || ! ( $r['walker'] instanceof Walker ) ) {
    213         $walker = new Walker_Category_Checklist;
    214     } else {
    215         $walker = $r['walker'];
    216     }
    217 
    218     $taxonomy = $r['taxonomy'];
    219     $descendants_and_self = (int) $r['descendants_and_self'];
    220 
    221     $args = array( 'taxonomy' => $taxonomy );
    222 
    223     $tax = get_taxonomy( $taxonomy );
    224     $args['disabled'] = ! current_user_can( $tax->cap->assign_terms );
    225 
    226     $args['list_only'] = ! empty( $r['list_only'] );
    227 
    228     if ( is_array( $r['selected_cats'] ) ) {
    229         $args['selected_cats'] = $r['selected_cats'];
    230     } elseif ( $post_id ) {
    231         $args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) );
    232     } else {
    233         $args['selected_cats'] = array();
    234     }
    235     if ( is_array( $r['popular_cats'] ) ) {
    236         $args['popular_cats'] = $r['popular_cats'];
    237     } else {
    238         $args['popular_cats'] = get_terms( $taxonomy, array(
    239             'fields' => 'ids',
    240             'orderby' => 'count',
    241             'order' => 'DESC',
    242             'number' => 10,
    243             'hierarchical' => false
    244         ) );
    245     }
    246     if ( $descendants_and_self ) {
    247         $categories = (array) get_terms( $taxonomy, array(
    248             'child_of' => $descendants_and_self,
    249             'hierarchical' => 0,
    250             'hide_empty' => 0
    251         ) );
    252         $self = get_term( $descendants_and_self, $taxonomy );
    253         array_unshift( $categories, $self );
    254     } else {
    255         $categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) );
    256     }
    257 
    258     $output = '';
    259 
    260     if ( $r['checked_ontop'] ) {
    261         // 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)
    262         $checked_categories = array();
    263         $keys = array_keys( $categories );
    264 
    265         foreach ( $keys as $k ) {
    266             if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) {
    267                 $checked_categories[] = $categories[$k];
    268                 unset( $categories[$k] );
    269             }
    270         }
    271 
    272         // Put checked cats on top
    273         $output .= call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) );
    274     }
    275     // Then the rest of them
    276     $output .= call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) );
    277 
    278     if ( $r['echo'] ) {
    279         echo $output;
    280     }
    281 
    282     return $output;
    283 }
    284 
    285 /**
    286  * Retrieve a list of the most popular terms from the specified taxonomy.
    287  *
    288  * If the $echo argument is true then the elements for a list of checkbox
    289  * `<input>` elements labelled with the names of the selected terms is output.
    290  * If the $post_ID global isn't empty then the terms associated with that
    291  * post will be marked as checked.
    292  *
    293  * @since 2.5.0
    294  *
    295  * @param string $taxonomy Taxonomy to retrieve terms from.
    296  * @param int $default Not used.
    297  * @param int $number Number of terms to retrieve. Defaults to 10.
    298  * @param bool $echo Optionally output the list as well. Defaults to true.
    299  * @return array List of popular term IDs.
    300  */
    301 function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
    302     $post = get_post();
    303 
    304     if ( $post && $post->ID )
    305         $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields'=>'ids'));
    306     else
    307         $checked_terms = array();
    308 
    309     $terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
    310 
    311     $tax = get_taxonomy($taxonomy);
    312 
    313     $popular_ids = array();
    314     foreach ( (array) $terms as $term ) {
    315         $popular_ids[] = $term->term_id;
    316         if ( !$echo ) // hack for AJAX use
    317             continue;
    318         $id = "popular-$taxonomy-$term->term_id";
    319         $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : '';
    320         ?>
    321 
    322         <li id="<?php echo $id; ?>" class="popular-category">
    323             <label class="selectit">
    324                 <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 ) ); ?> />
    325                 <?php
    326                 /** This filter is documented in wp-includes/category-template.php */
    327                 echo esc_html( apply_filters( 'the_category', $term->name ) );
    328                 ?>
    329             </label>
    330         </li>
    331 
    332         <?php
    333     }
    334     return $popular_ids;
    335 }
    336 
    337 /**
    338  * {@internal Missing Short Description}}
    339  *
    340  * @since 2.5.1
    341  *
    342  * @param int $link_id
    343  */
    344 function wp_link_category_checklist( $link_id = 0 ) {
    345     $default = 1;
    346 
    347     $checked_categories = array();
    348 
    349     if ( $link_id ) {
    350         $checked_categories = wp_get_link_cats( $link_id );
    351         // No selected categories, strange
    352         if ( ! count( $checked_categories ) ) {
    353             $checked_categories[] = $default;
    354         }
    355     } else {
    356         $checked_categories[] = $default;
    357     }
    358 
    359     $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) );
    360 
    361     if ( empty( $categories ) )
    362         return;
    363 
    364     foreach ( $categories as $category ) {
    365         $cat_id = $category->term_id;
    366 
    367         /** This filter is documented in wp-includes/category-template.php */
    368         $name = esc_html( apply_filters( 'the_category', $category->name ) );
    369         $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : '';
    370         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>";
    371     }
    372 }
    373 
    374 /**
    375  * Adds hidden fields with the data for use in the inline editor for posts and pages.
    376  *
    377  * @since 2.7.0
    378  *
    379  * @param WP_Post $post Post object.
    380  */
    381 function get_inline_data($post) {
    382     $post_type_object = get_post_type_object($post->post_type);
    383     if ( ! current_user_can( 'edit_post', $post->ID ) )
    384         return;
    385 
    386     $title = esc_textarea( trim( $post->post_title ) );
    387 
    388     /** This filter is documented in wp-admin/edit-tag-form.php */
    389     echo '
    390 <div class="hidden" id="inline_' . $post->ID . '">
    391     <div class="post_title">' . $title . '</div>
    392     <div class="post_name">' . apply_filters( 'editable_slug', $post->post_name ) . '</div>
    393     <div class="post_author">' . $post->post_author . '</div>
    394     <div class="comment_status">' . esc_html( $post->comment_status ) . '</div>
    395     <div class="ping_status">' . esc_html( $post->ping_status ) . '</div>
    396     <div class="_status">' . esc_html( $post->post_status ) . '</div>
    397     <div class="jj">' . mysql2date( 'd', $post->post_date, false ) . '</div>
    398     <div class="mm">' . mysql2date( 'm', $post->post_date, false ) . '</div>
    399     <div class="aa">' . mysql2date( 'Y', $post->post_date, false ) . '</div>
    400     <div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div>
    401     <div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div>
    402     <div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div>
    403     <div class="post_password">' . esc_html( $post->post_password ) . '</div>';
    404 
    405     if ( $post_type_object->hierarchical )
    406         echo '<div class="post_parent">' . $post->post_parent . '</div>';
    407 
    408     if ( $post->post_type == 'page' )
    409         echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>';
    410 
    411     if ( post_type_supports( $post->post_type, 'page-attributes' ) )
    412         echo '<div class="menu_order">' . $post->menu_order . '</div>';
    413 
    414     $taxonomy_names = get_object_taxonomies( $post->post_type );
    415     foreach ( $taxonomy_names as $taxonomy_name) {
    416         $taxonomy = get_taxonomy( $taxonomy_name );
    417 
    418         if ( $taxonomy->hierarchical && $taxonomy->show_ui ) {
    419 
    420             $terms = get_object_term_cache( $post->ID, $taxonomy_name );
    421             if ( false === $terms ) {
    422                 $terms = wp_get_object_terms( $post->ID, $taxonomy_name );
    423                 wp_cache_add( $post->ID, $terms, $taxonomy_name . '_relationships' );
    424             }
    425             $term_ids = empty( $terms ) ? array() : wp_list_pluck( $terms, 'term_id' );
    426 
    427             echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode( ',', $term_ids ) . '</div>';
    428 
    429         } elseif ( $taxonomy->show_ui ) {
    430 
    431             echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">'
    432                 . esc_html( str_replace( ',', ', ', get_terms_to_edit( $post->ID, $taxonomy_name ) ) ) . '</div>';
    433 
    434         }
    435     }
    436 
    437     if ( !$post_type_object->hierarchical )
    438         echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
    439 
    440     if ( post_type_supports( $post->post_type, 'post-formats' ) )
    441         echo '<div class="post_format">' . esc_html( get_post_format( $post->ID ) ) . '</div>';
    442 
    443     echo '</div>';
    444 }
    445 
    446 /**
    447  * {@internal Missing Short Description}}
    448  *
    449  * @since 2.7.0
    450  *
    451  * @global WP_List_Table $wp_list_table
    452  *
    453  * @param int    $position
    454  * @param bool   $checkbox
    455  * @param string $mode
    456  * @param bool   $table_row
    457  */
    458 function wp_comment_reply( $position = 1, $checkbox = false, $mode = 'single', $table_row = true ) {
    459     global $wp_list_table;
    460     /**
    461      * Filter the in-line comment reply-to form output in the Comments
    462      * list table.
    463      *
    464      * Returning a non-empty value here will short-circuit display
    465      * of the in-line comment-reply form in the Comments list table,
    466      * echoing the returned value instead.
    467      *
    468      * @since 2.7.0
    469      *
    470      * @see wp_comment_reply()
    471      *
    472      * @param string $content The reply-to form content.
    473      * @param array  $args    An array of default args.
    474      */
    475     $content = apply_filters( 'wp_comment_reply', '', array( 'position' => $position, 'checkbox' => $checkbox, 'mode' => $mode ) );
    476 
    477     if ( ! empty($content) ) {
    478         echo $content;
    479         return;
    480     }
    481 
    482     if ( ! $wp_list_table ) {
    483         if ( $mode == 'single' ) {
    484             $wp_list_table = _get_list_table('WP_Post_Comments_List_Table');
    485         } else {
    486             $wp_list_table = _get_list_table('WP_Comments_List_Table');
    487         }
    488     }
    489 
    490 ?>
    491 <form method="get">
    492 <?php if ( $table_row ) : ?>
    493 <table style="display:none;"><tbody id="com-reply"><tr id="replyrow" class="inline-edit-row" style="display:none;"><td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="colspanchange">
    494 <?php else : ?>
    495 <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;">
    496 <?php endif; ?>
    497     <div id="replyhead" style="display:none;"><h5><?php _e( 'Reply to Comment' ); ?></h5></div>
    498     <div id="addhead" style="display:none;"><h5><?php _e('Add new Comment'); ?></h5></div>
    499     <div id="edithead" style="display:none;">
    500         <div class="inside">
    501         <label for="author-name"><?php _e( 'Name' ) ?></label>
    502         <input type="text" name="newcomment_author" size="50" value="" id="author-name" />
    503         </div>
    504 
    505         <div class="inside">
    506         <label for="author-email"><?php _e('Email') ?></label>
    507         <input type="text" name="newcomment_author_email" size="50" value="" id="author-email" />
    508         </div>
    509 
    510         <div class="inside">
    511         <label for="author-url"><?php _e('URL') ?></label>
    512         <input type="text" id="author-url" name="newcomment_author_url" class="code" size="103" value="" />
    513         </div>
    514         <div style="clear:both;"></div>
    515     </div>
    516 
    517     <div id="replycontainer">
    518     <?php
    519     $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' );
    520     wp_editor( '', 'replycontent', array( 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings ) );
    521     ?>
    522     </div>
    523 
    524     <p id="replysubmit" class="submit">
    525     <a href="#comments-form" class="save button-primary alignright">
    526     <span id="addbtn" style="display:none;"><?php _e('Add Comment'); ?></span>
    527     <span id="savebtn" style="display:none;"><?php _e('Update Comment'); ?></span>
    528     <span id="replybtn" style="display:none;"><?php _e('Submit Reply'); ?></span></a>
    529     <a href="#comments-form" class="cancel button-secondary alignleft"><?php _e('Cancel'); ?></a>
    530     <span class="waiting spinner"></span>
    531     <span class="error" style="display:none;"></span>
    532     <br class="clear" />
    533     </p>
    534 
    535     <input type="hidden" name="action" id="action" value="" />
    536     <input type="hidden" name="comment_ID" id="comment_ID" value="" />
    537     <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" />
    538     <input type="hidden" name="status" id="status" value="" />
    539     <input type="hidden" name="position" id="position" value="<?php echo $position; ?>" />
    540     <input type="hidden" name="checkbox" id="checkbox" value="<?php echo $checkbox ? 1 : 0; ?>" />
    541     <input type="hidden" name="mode" id="mode" value="<?php echo esc_attr($mode); ?>" />
    542     <?php
    543         wp_nonce_field( 'replyto-comment', '_ajax_nonce-replyto-comment', false );
    544         if ( current_user_can( 'unfiltered_html' ) )
    545             wp_nonce_field( 'unfiltered-html-comment', '_wp_unfiltered_html_comment', false );
    546     ?>
    547 <?php if ( $table_row ) : ?>
    548 </td></tr></tbody></table>
    549 <?php else : ?>
    550 </div></div>
    551 <?php endif; ?>
    552 </form>
    553 <?php
    554 }
    555 
    556 /**
    557  * Output 'undo move to trash' text for comments
    558  *
    559  * @since 2.9.0
    560  */
    561 function wp_comment_trashnotice() {
    562 ?>
    563 <div class="hidden" id="trash-undo-holder">
    564     <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>
    565 </div>
    566 <div class="hidden" id="spam-undo-holder">
    567     <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>
    568 </div>
    569 <?php
    570 }
    571 
    572 /**
    573  * {@internal Missing Short Description}}
    574  *
    575  * @since 1.2.0
    576  *
    577  * @param array $meta
    578  */
    579 function list_meta( $meta ) {
    580     // Exit if no meta
    581     if ( ! $meta ) {
    582         echo '
    583 <table id="list-table" style="display: none;">
    584     <thead>
    585     <tr>
    586         <th class="left">' . _x( 'Name', 'meta name' ) . '</th>
    587         <th>' . __( 'Value' ) . '</th>
    588     </tr>
    589     </thead>
    590     <tbody id="the-list" data-wp-lists="list:meta">
    591     <tr><td></td></tr>
    592     </tbody>
    593 </table>'; //TBODY needed for list-manipulation JS
    594         return;
    595     }
    596     $count = 0;
    597 ?>
    598 <table id="list-table">
    599     <thead>
    600     <tr>
    601         <th class="left"><?php _ex( 'Name', 'meta name' ) ?></th>
    602         <th><?php _e( 'Value' ) ?></th>
    603     </tr>
    604     </thead>
    605     <tbody id='the-list' data-wp-lists='list:meta'>
    606 <?php
    607     foreach ( $meta as $entry )
    608         echo _list_meta_row( $entry, $count );
    609 ?>
    610     </tbody>
    611 </table>
    612 <?php
    613 }
    614 
    615 /**
    616  * {@internal Missing Short Description}}
    617  *
    618  * @since 2.5.0
    619  *
    620  * @staticvar string $update_nonce
    621  *
    622  * @param array $entry
    623  * @param int   $count
    624  * @return string
    625  */
    626 function _list_meta_row( $entry, &$count ) {
    627     static $update_nonce = '';
    628 
    629     if ( is_protected_meta( $entry['meta_key'], 'post' ) )
    630         return '';
    631 
    632     if ( ! $update_nonce )
    633         $update_nonce = wp_create_nonce( 'add-meta' );
    634 
    635     $r = '';
    636     ++ $count;
    637 
    638     if ( is_serialized( $entry['meta_value'] ) ) {
    639         if ( is_serialized_string( $entry['meta_value'] ) ) {
    640             // This is a serialized string, so we should display it.
    641             $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
    642         } else {
    643             // This is a serialized array/object so we should NOT display it.
    644             --$count;
    645             return '';
    646         }
    647     }
    648 
    649     $entry['meta_key'] = esc_attr($entry['meta_key']);
    650     $entry['meta_value'] = esc_textarea( $entry['meta_value'] ); // using a <textarea />
    651     $entry['meta_id'] = (int) $entry['meta_id'];
    652 
    653     $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
    654 
    655     $r .= "\n\t<tr id='meta-{$entry['meta_id']}'>";
    656     $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']}' />";
    657 
    658     $r .= "\n\t\t<div class='submit'>";
    659     $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" ) );
    660     $r .= "\n\t\t";
    661     $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" ) );
    662     $r .= "</div>";
    663     $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
    664     $r .= "</td>";
    665 
    666     $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>";
    667     return $r;
    668 }
    669 
    670 /**
    671  * Prints the form in the Custom Fields meta box.
    672  *
    673  * @since 1.2.0
    674  *
    675  * @global wpdb $wpdb
    676  *
    677  * @param WP_Post $post Optional. The post being edited.
    678  */
    679 function meta_form( $post = null ) {
    680     global $wpdb;
    681     $post = get_post( $post );
    682 
    683     /**
    684      * Filter the number of custom fields to retrieve for the drop-down
    685      * in the Custom Fields meta box.
    686      *
    687      * @since 2.1.0
    688      *
    689      * @param int $limit Number of custom fields to retrieve. Default 30.
    690      */
    691     $limit = apply_filters( 'postmeta_form_limit', 30 );
    692     $sql = "SELECT DISTINCT meta_key
    693         FROM $wpdb->postmeta
    694         WHERE meta_key NOT BETWEEN '_' AND '_z'
    695         HAVING meta_key NOT LIKE %s
    696         ORDER BY meta_key
    697         LIMIT %d";
    698     $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) );
    699     if ( $keys ) {
    700         natcasesort( $keys );
    701         $meta_key_input_id = 'metakeyselect';
    702     } else {
    703         $meta_key_input_id = 'metakeyinput';
    704     }
    705 ?>
    706 <p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p>
    707 <table id="newmeta">
    708 <thead>
    709 <tr>
    710 <th class="left"><label for="<?php echo $meta_key_input_id; ?>"><?php _ex( 'Name', 'meta name' ) ?></label></th>
    711 <th><label for="metavalue"><?php _e( 'Value' ) ?></label></th>
    712 </tr>
    713 </thead>
    714 
    715 <tbody>
    716 <tr>
    717 <td id="newmetaleft" class="left">
    718 <?php if ( $keys ) { ?>
    719 <select id="metakeyselect" name="metakeyselect">
    720 <option value="#NONE#"><?php _e( '&mdash; Select &mdash;' ); ?></option>
    721 <?php
    722 
    723     foreach ( $keys as $key ) {
    724         if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $post->ID, $key ) )
    725             continue;
    726         echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>";
    727     }
    728 ?>
    729 </select>
    730 <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" value="" />
    731 <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
    732 <span id="enternew"><?php _e('Enter new'); ?></span>
    733 <span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a>
    734 <?php } else { ?>
    735 <input type="text" id="metakeyinput" name="metakeyinput" value="" />
    736 <?php } ?>
    737 </td>
    738 <td><textarea id="metavalue" name="metavalue" rows="2" cols="25"></textarea></td>
    739 </tr>
    740 
    741 <tr><td colspan="2">
    742 <div class="submit">
    743 <?php submit_button( __( 'Add Custom Field' ), 'secondary', 'addmeta', false, array( 'id' => 'newmeta-submit', 'data-wp-lists' => 'add:the-list:newmeta' ) ); ?>
    744 </div>
    745 <?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?>
    746 </td></tr>
    747 </tbody>
    748 </table>
    749 <?php
    750 
    751 }
    752 
    753 /**
    754  * Print out HTML form date elements for editing post or comment publish date.
    755  *
    756  * @since 0.71
    757  * @since 4.4.0 Converted to use get_comment() instead of the global `$comment`.
    758  *
    759  * @global WP_Locale  $wp_locale
    760  *
    761  * @param int|bool $edit      Accepts 1|true for editing the date, 0|false for adding the date.
    762  * @param int|bool $for_post  Accepts 1|true for applying the date to a post, 0|false for a comment.
    763  * @param int      $tab_index The tabindex attribute to add. Default 0.
    764  * @param int|bool $multi     Optional. Whether the additional fields and buttons should be added.
    765  *                            Default 0|false.
    766  */
    767 function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
    768     global $wp_locale;
    769     $post = get_post();
    770 
    771     if ( $for_post )
    772         $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );
    773 
    774     $tab_index_attribute = '';
    775     if ( (int) $tab_index > 0 )
    776         $tab_index_attribute = " tabindex=\"$tab_index\"";
    777 
    778     // todo: Remove this?
    779     // 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 />';
    780 
    781     $time_adj = current_time('timestamp');
    782     $post_date = ($for_post) ? $post->post_date : get_comment()->comment_date;
    783     $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
    784     $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
    785     $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
    786     $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
    787     $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
    788     $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
    789 
    790     $cur_jj = gmdate( 'd', $time_adj );
    791     $cur_mm = gmdate( 'm', $time_adj );
    792     $cur_aa = gmdate( 'Y', $time_adj );
    793     $cur_hh = gmdate( 'H', $time_adj );
    794     $cur_mn = gmdate( 'i', $time_adj );
    795 
    796     $month = '<label><span class="screen-reader-text">' . __( 'Month' ) . '</span><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n";
    797     for ( $i = 1; $i < 13; $i = $i +1 ) {
    798         $monthnum = zeroise($i, 2);
    799         $monthtext = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) );
    800         $month .= "\t\t\t" . '<option value="' . $monthnum . '" data-text="' . $monthtext . '" ' . selected( $monthnum, $mm, false ) . '>';
    801         /* translators: 1: month number (01, 02, etc.), 2: month abbreviation */
    802         $month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $monthtext ) . "</option>\n";
    803     }
    804     $month .= '</select></label>';
    805 
    806     $day = '<label><span class="screen-reader-text">' . __( 'Day' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>';
    807     $year = '<label><span class="screen-reader-text">' . __( 'Year' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" /></label>';
    808     $hour = '<label><span class="screen-reader-text">' . __( 'Hour' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>';
    809     $minute = '<label><span class="screen-reader-text">' . __( 'Minute' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>';
    810 
    811     echo '<div class="timestamp-wrap">';
    812     /* translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */
    813     printf( __( '%1$s %2$s, %3$s @ %4$s:%5$s' ), $month, $day, $year, $hour, $minute );
    814 
    815     echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
    816 
    817     if ( $multi ) return;
    818 
    819     echo "\n\n";
    820     $map = array(
    821         'mm' => array( $mm, $cur_mm ),
    822         'jj' => array( $jj, $cur_jj ),
    823         'aa' => array( $aa, $cur_aa ),
    824         'hh' => array( $hh, $cur_hh ),
    825         'mn' => array( $mn, $cur_mn ),
    826     );
    827     foreach ( $map as $timeunit => $value ) {
    828         list( $unit, $curr ) = $value;
    829 
    830         echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $unit . '" />' . "\n";
    831         $cur_timeunit = 'cur_' . $timeunit;
    832         echo '<input type="hidden" id="' . $cur_timeunit . '" name="' . $cur_timeunit . '" value="' . $curr . '" />' . "\n";
    833     }
    834 ?>
    835 
    836 <p>
    837 <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a>
    838 <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js button-cancel"><?php _e('Cancel'); ?></a>
    839 </p>
    840 <?php
    841 }
    842 
    843 /**
    844  * Print out option HTML elements for the page templates drop-down.
    845  *
    846  * @since 1.5.0
    847  *
    848  * @param string $default Optional. The template file name. Default empty.
    849  */
    850 function page_template_dropdown( $default = '' ) {
    851     $templates = get_page_templates( get_post() );
    852     ksort( $templates );
    853     foreach ( array_keys( $templates ) as $template ) {
    854         $selected = selected( $default, $templates[ $template ], false );
    855         echo "\n\t<option value='" . $templates[ $template ] . "' $selected>$template</option>";
    856     }
    857 }
    858 
    859 /**
    860  * Print out option HTML elements for the page parents drop-down.
    861  *
    862  * @since 1.5.0
    863  * @since 4.4.0 `$post` argument was added.
    864  *
    865  * @global wpdb $wpdb
    866  *
    867  * @param int         $default Optional. The default page ID to be pre-selected. Default 0.
    868  * @param int         $parent  Optional. The parent page ID. Default 0.
    869  * @param int         $level   Optional. Page depth level. Default 0.
    870  * @param int|WP_Post $post    Post ID or WP_Post object.
    871  *
    872  * @return null|false Boolean False if page has no children, otherwise print out html elements
    873  */
    874 function parent_dropdown( $default = 0, $parent = 0, $level = 0, $post = null ) {
    875     global $wpdb;
    876     $post = get_post( $post );
    877     $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) );
    878 
    879     if ( $items ) {
    880         foreach ( $items as $item ) {
    881             // A page cannot be its own parent.
    882             if ( $post && $post->ID && $item->ID == $post->ID )
    883                 continue;
    884 
    885             $pad = str_repeat( '&nbsp;', $level * 3 );
    886             $selected = selected( $default, $item->ID, false );
    887 
    888             echo "\n\t<option class='level-$level' value='$item->ID' $selected>$pad " . esc_html($item->post_title) . "</option>";
    889             parent_dropdown( $default, $item->ID, $level +1 );
    890         }
    891     } else {
    892         return false;
    893     }
    894 }
    895 
    896 /**
    897  * Print out option html elements for role selectors.
    898  *
    899  * @since 2.1.0
    900  *
    901  * @param string $selected Slug for the role that should be already selected.
    902  */
    903 function wp_dropdown_roles( $selected = '' ) {
    904     $p = '';
    905     $r = '';
    906 
    907     $editable_roles = array_reverse( get_editable_roles() );
    908 
    909     foreach ( $editable_roles as $role => $details ) {
    910         $name = translate_user_role($details['name'] );
    911         if ( $selected == $role ) // preselect specified role
    912             $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
    913         else
    914             $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
    915     }
    916     echo $p . $r;
    917 }
    918 
    919 /**
    920  * Outputs the form used by the importers to accept the data to be imported
    921  *
    922  * @since 2.0.0
    923  *
    924  * @param string $action The action attribute for the form.
    925  */
    926 function wp_import_upload_form( $action ) {
    927 
    928     /**
    929      * Filter the maximum allowed upload size for import files.
    930      *
    931      * @since 2.3.0
    932      *
    933      * @see wp_max_upload_size()
    934      *
    935      * @param int $max_upload_size Allowed upload size. Default 1 MB.
    936      */
    937     $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
    938     $size = size_format( $bytes );
    939     $upload_dir = wp_upload_dir();
    940     if ( ! empty( $upload_dir['error'] ) ) :
    941         ?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
    942         <p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
    943     else :
    944 ?>
    945 <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' ) ); ?>">
    946 <p>
    947 <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
    948 <input type="file" id="upload" name="import" size="25" />
    949 <input type="hidden" name="action" value="save" />
    950 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
    951 </p>
    952 <?php submit_button( __('Upload file and import'), 'button' ); ?>
    953 </form>
    954 <?php
    955     endif;
    956 }
    957 
    958 /**
    959  * Add a meta box to an edit form.
    960  *
    961  * @since 2.5.0
    962  *
    963  * @global array $wp_meta_boxes
    964  *
    965  * @param string           $id            String for use in the 'id' attribute of tags.
    966  * @param string           $title         Title of the meta box.
    967  * @param callback         $callback      Function that fills the box with the desired content.
    968  *                                        The function should echo its output.
    969  * @param string|WP_Screen $screen        Optional. The screen on which to show the box (like a post
    970  *                                        type, 'link', or 'comment'). Default is the current screen.
    971  * @param string           $context       Optional. The context within the screen where the boxes
    972  *                                        should display. Available contexts vary from screen to
    973  *                                        screen. Post edit screen contexts include 'normal', 'side',
    974  *                                        and 'advanced'. Comments screen contexts include 'normal'
    975  *                                        and 'side'. Menus meta boxes (accordion sections) all use
    976  *                                        the 'side' context. Global default is 'advanced'.
    977  * @param string           $priority      Optional. The priority within the context where the boxes
    978  *                                        should show ('high', 'low'). Default 'default'.
    979  * @param array            $callback_args Optional. Data that should be set as the $args property
    980  *                                        of the box array (which is the second parameter passed
    981  *                                        to your callback). Default null.
    982  */
    983 function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {
    984     global $wp_meta_boxes;
    985 
    986     if ( empty( $screen ) )
    987         $screen = get_current_screen();
    988     elseif ( is_string( $screen ) )
    989         $screen = convert_to_screen( $screen );
    990 
    991     $page = $screen->id;
    992 
    993     if ( !isset($wp_meta_boxes) )
    994         $wp_meta_boxes = array();
    995     if ( !isset($wp_meta_boxes[$page]) )
    996         $wp_meta_boxes[$page] = array();
    997     if ( !isset($wp_meta_boxes[$page][$context]) )
    998         $wp_meta_boxes[$page][$context] = array();
    999 
    1000     foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
    1001         foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
    1002             if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
    1003                 continue;
    1004 
    1005             // If a core box was previously added or removed by a plugin, don't add.
    1006             if ( 'core' == $priority ) {
    1007                 // If core box previously deleted, don't add
    1008                 if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
    1009                     return;
    1010 
    1011                 /*
    1012                  * If box was added with default priority, give it core priority to
    1013                  * maintain sort order.
    1014                  */
    1015                 if ( 'default' == $a_priority ) {
    1016                     $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
    1017                     unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
    1018                 }
    1019                 return;
    1020             }
    1021             // If no priority given and id already present, use existing priority.
    1022             if ( empty($priority) ) {
    1023                 $priority = $a_priority;
    1024             /*
    1025              * Else, if we're adding to the sorted priority, we don't know the title
    1026              * or callback. Grab them from the previously added context/priority.
    1027              */
    1028             } elseif ( 'sorted' == $priority ) {
    1029                 $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
    1030                 $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
    1031                 $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
    1032             }
    1033             // An id can be in only one priority and one context.
    1034             if ( $priority != $a_priority || $context != $a_context )
    1035                 unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
    1036         }
    1037     }
    1038 
    1039     if ( empty($priority) )
    1040         $priority = 'low';
    1041 
    1042     if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
    1043         $wp_meta_boxes[$page][$context][$priority] = array();
    1044 
    1045     $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
    1046 }
    1047 
    1048 /**
    1049  * Meta-Box template function
    1050  *
    1051  * @since 2.5.0
    1052  *
    1053  * @global array $wp_meta_boxes
    1054  *
    1055  * @staticvar bool $already_sorted
    1056  * @param string|WP_Screen $screen  Screen identifier
    1057  * @param string           $context box context
    1058  * @param mixed            $object  gets passed to the box callback function as first parameter
    1059  * @return int number of meta_boxes
    1060  */
    1061 function do_meta_boxes( $screen, $context, $object ) {
    1062     global $wp_meta_boxes;
    1063     static $already_sorted = false;
    1064 
    1065     if ( empty( $screen ) )
    1066         $screen = get_current_screen();
    1067     elseif ( is_string( $screen ) )
    1068         $screen = convert_to_screen( $screen );
    1069 
    1070     $page = $screen->id;
    1071 
    1072     $hidden = get_hidden_meta_boxes( $screen );
    1073 
    1074     printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context));
    1075 
    1076     // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
    1077     if ( ! $already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) {
    1078         foreach ( $sorted as $box_context => $ids ) {
    1079             foreach ( explode( ',', $ids ) as $id ) {
    1080                 if ( $id && 'dashboard_browser_nag' !== $id ) {
    1081                     add_meta_box( $id, null, null, $screen, $box_context, 'sorted' );
    1082                 }
    1083             }
    1084         }
    1085     }
    1086 
    1087     $already_sorted = true;
    1088 
    1089     $i = 0;
    1090 
    1091     if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
    1092         foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
    1093             if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ]) ) {
    1094                 foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
    1095                     if ( false == $box || ! $box['title'] )
    1096                         continue;
    1097                     $i++;
    1098                     $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : '';
    1099                     echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n";
    1100                     if ( 'dashboard_browser_nag' != $box['id'] ) {
    1101                         echo '<button class="handlediv button-link" title="' . esc_attr__( 'Click to toggle' ) . '" aria-expanded="true">';
    1102                         echo '<span class="screen-reader-text">' . sprintf( __( 'Click to toggle %s panel' ), $box['title'] ) . '</span><br />';
    1103                         echo '</button>';
    1104                     }
    1105                     echo "<h3 class='hndle'><span>{$box['title']}</span></h3>\n";
    1106                     echo '<div class="inside">' . "\n";
    1107                     call_user_func($box['callback'], $object, $box);
    1108                     echo "</div>\n";
    1109                     echo "</div>\n";
    1110                 }
    1111             }
    1112         }
    1113     }
    1114 
    1115     echo "</div>";
    1116 
    1117     return $i;
    1118 
    1119 }
    1120 
    1121 /**
    1122  * Remove a meta box from an edit form.
    1123  *
    1124  * @since 2.6.0
    1125  *
    1126  * @global array $wp_meta_boxes
    1127  *
    1128  * @param string        $id      String for use in the 'id' attribute of tags.
    1129  * @param string|object $screen  The screen on which to show the box (post, page, link).
    1130  * @param string        $context The context within the page where the boxes should show ('normal', 'advanced').
    1131  */
    1132 function remove_meta_box($id, $screen, $context) {
    1133     global $wp_meta_boxes;
    1134 
    1135     if ( empty( $screen ) )
    1136         $screen = get_current_screen();
    1137     elseif ( is_string( $screen ) )
    1138         $screen = convert_to_screen( $screen );
    1139 
    1140     $page = $screen->id;
    1141 
    1142     if ( !isset($wp_meta_boxes) )
    1143         $wp_meta_boxes = array();
    1144     if ( !isset($wp_meta_boxes[$page]) )
    1145         $wp_meta_boxes[$page] = array();
    1146     if ( !isset($wp_meta_boxes[$page][$context]) )
    1147         $wp_meta_boxes[$page][$context] = array();
    1148 
    1149     foreach ( array('high', 'core', 'default', 'low') as $priority )
    1150         $wp_meta_boxes[$page][$context][$priority][$id] = false;
    1151 }
    1152 
    1153 /**
    1154  * Meta Box Accordion Template Function
    1155  *
    1156  * Largely made up of abstracted code from {@link do_meta_boxes()}, this
    1157  * function serves to build meta boxes as list items for display as
    1158  * a collapsible accordion.
    1159  *
    1160  * @since 3.6.0
    1161  *
    1162  * @uses global $wp_meta_boxes Used to retrieve registered meta boxes.
    1163  *
    1164  * @param string|object $screen  The screen identifier.
    1165  * @param string        $context The meta box context.
    1166  * @param mixed         $object  gets passed to the section callback function as first parameter.
    1167  * @return int number of meta boxes as accordion sections.
    1168  */
    1169 function do_accordion_sections( $screen, $context, $object ) {
    1170     global $wp_meta_boxes;
    1171 
    1172     wp_enqueue_script( 'accordion' );
    1173 
    1174     if ( empty( $screen ) )
    1175         $screen = get_current_screen();
    1176     elseif ( is_string( $screen ) )
    1177         $screen = convert_to_screen( $screen );
    1178 
    1179     $page = $screen->id;
    1180 
    1181     $hidden = get_hidden_meta_boxes( $screen );
    1182     ?>
    1183     <div id="side-sortables" class="accordion-container">
    1184         <ul class="outer-border">
    1185     <?php
    1186     $i = 0;
    1187     $first_open = false;
    1188 
    1189     if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
    1190         foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
    1191             if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
    1192                 foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
    1193                     if ( false == $box || ! $box['title'] )
    1194                         continue;
    1195                     $i++;
    1196                     $hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
    1197 
    1198                     $open_class = '';
    1199                     if ( ! $first_open && empty( $hidden_class ) ) {
    1200                         $first_open = true;
    1201                         $open_class = 'open';
    1202                     }
    1203                     ?>
    1204                     <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'] ); ?>">
    1205                         <h3 class="accordion-section-title hndle" tabindex="0">
    1206                             <?php echo esc_html( $box['title'] ); ?>
    1207                             <span class="screen-reader-text"><?php _e( 'Press return or enter to expand' ); ?></span>
    1208                         </h3>
    1209                         <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
    1210                             <div class="inside">
    1211                                 <?php call_user_func( $box['callback'], $object, $box ); ?>
    1212                             </div><!-- .inside -->
    1213                         </div><!-- .accordion-section-content -->
    1214                     </li><!-- .accordion-section -->
    1215                     <?php
    1216                 }
    1217             }
    1218         }
    1219     }
    1220     ?>
    1221         </ul><!-- .outer-border -->
    1222     </div><!-- .accordion-container -->
    1223     <?php
    1224     return $i;
    1225 }
    1226 
    1227 /**
    1228  * Add a new section to a settings page.
    1229  *
    1230  * Part of the Settings API. Use this to define new settings sections for an admin page.
    1231  * Show settings sections in your admin page callback function with do_settings_sections().
    1232  * Add settings fields to your section with add_settings_field()
    1233  *
    1234  * The $callback argument should be the name of a function that echoes out any
    1235  * content you want to show at the top of the settings section before the actual
    1236  * fields. It can output nothing if you want.
    1237  *
    1238  * @since 2.7.0
    1239  *
    1240  * @global $wp_settings_sections Storage array of all settings sections added to admin pages
    1241  *
    1242  * @param string $id       Slug-name to identify the section. Used in the 'id' attribute of tags.
    1243  * @param string $title    Formatted title of the section. Shown as the heading for the section.
    1244  * @param string $callback Function that echos out any content at the top of the section (between heading and fields).
    1245  * @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();
    1246  */
    1247 function add_settings_section($id, $title, $callback, $page) {
    1248     global $wp_settings_sections;
    1249 
    1250     if ( 'misc' == $page ) {
    1251         _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) );
    1252         $page = 'general';
    1253     }
    1254 
    1255     if ( 'privacy' == $page ) {
    1256         _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) );
    1257         $page = 'reading';
    1258     }
    1259 
    1260     $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
    1261 }
    1262 
    1263 /**
    1264  * Add a new field to a section of a settings page
    1265  *
    1266  * Part of the Settings API. Use this to define a settings field that will show
    1267  * as part of a settings section inside a settings page. The fields are shown using
    1268  * do_settings_fields() in do_settings-sections()
    1269  *
    1270  * The $callback argument should be the name of a function that echoes out the
    1271  * html input tags for this setting field. Use get_option() to retrieve existing
    1272  * values to show.
    1273  *
    1274  * @since 2.7.0
    1275  * @since 4.2.0 The `$class` argument was added.
    1276  *
    1277  * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
    1278  *
    1279  * @param string $id       Slug-name to identify the field. Used in the 'id' attribute of tags.
    1280  * @param string $title    Formatted title of the field. Shown as the label for the field
    1281  *                         during output.
    1282  * @param string $callback Function that fills the field with the desired form inputs. The
    1283  *                         function should echo its output.
    1284  * @param string $page     The slug-name of the settings page on which to show the section
    1285  *                         (general, reading, writing, ...).
    1286  * @param string $section  Optional. The slug-name of the section of the settings page
    1287  *                         in which to show the box. Default 'default'.
    1288  * @param array  $args {
    1289  *     Optional. Extra arguments used when outputting the field.
    1290  *
    1291  *     @type string $label_for When supplied, the setting title will be wrapped
    1292  *                             in a `<label>` element, its `for` attribute populated
    1293  *                             with this value.
    1294  *     @type string $class     CSS Class to be added to the `<tr>` element when the
    1295  *                             field is output.
    1296  * }
    1297  */
    1298 function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
    1299     global $wp_settings_fields;
    1300 
    1301     if ( 'misc' == $page ) {
    1302         _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
    1303         $page = 'general';
    1304     }
    1305 
    1306     if ( 'privacy' == $page ) {
    1307         _deprecated_argument( __FUNCTION__, '3.5', __( 'The privacy options group has been removed. Use another settings group.' ) );
    1308         $page = 'reading';
    1309     }
    1310 
    1311     $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
    1312 }
    1313 
    1314 /**
    1315  * Prints out all settings sections added to a particular settings page
    1316  *
    1317  * Part of the Settings API. Use this in a settings page callback function
    1318  * to output all the sections and fields that were added to that $page with
    1319  * add_settings_section() and add_settings_field()
    1320  *
    1321  * @global $wp_settings_sections Storage array of all settings sections added to admin pages
    1322  * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
    1323  * @since 2.7.0
    1324  *
    1325  * @param string $page The slug name of the page whos settings sections you want to output
    1326  */
    1327 function do_settings_sections( $page ) {
    1328     global $wp_settings_sections, $wp_settings_fields;
    1329 
    1330     if ( ! isset( $wp_settings_sections[$page] ) )
    1331         return;
    1332 
    1333     foreach ( (array) $wp_settings_sections[$page] as $section ) {
    1334         if ( $section['title'] )
    1335             echo "<h3>{$section['title']}</h3>\n";
    1336 
    1337         if ( $section['callback'] )
    1338             call_user_func( $section['callback'], $section );
    1339 
    1340         if ( ! isset( $wp_settings_fields ) || !isset( $wp_settings_fields[$page] ) || !isset( $wp_settings_fields[$page][$section['id']] ) )
    1341             continue;
    1342         echo '<table class="form-table">';
    1343         do_settings_fields( $page, $section['id'] );
    1344         echo '</table>';
    1345     }
    1346 }
    1347 
    1348 /**
    1349  * Print out the settings fields for a particular settings section
    1350  *
    1351  * Part of the Settings API. Use this in a settings page to output
    1352  * a specific section. Should normally be called by do_settings_sections()
    1353  * rather than directly.
    1354  *
    1355  * @global $wp_settings_fields Storage array of settings fields and their pages/sections
    1356  *
    1357  * @since 2.7.0
    1358  *
    1359  * @param string $page Slug title of the admin page who's settings fields you want to show.
    1360  * @param string $section Slug title of the settings section who's fields you want to show.
    1361  */
    1362 function do_settings_fields($page, $section) {
    1363     global $wp_settings_fields;
    1364 
    1365     if ( ! isset( $wp_settings_fields[$page][$section] ) )
    1366         return;
    1367 
    1368     foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
    1369         $class = '';
    1370 
    1371         if ( ! empty( $field['args']['class'] ) ) {
    1372             $class = ' class="' . esc_attr( $field['args']['class'] ) . '"';
    1373         }
    1374 
    1375         echo "<tr{$class}>";
    1376 
    1377         if ( ! empty( $field['args']['label_for'] ) ) {
    1378             echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>';
    1379         } else {
    1380             echo '<th scope="row">' . $field['title'] . '</th>';
    1381         }
    1382 
    1383         echo '<td>';
    1384         call_user_func($field['callback'], $field['args']);
    1385         echo '</td>';
    1386         echo '</tr>';
    1387     }
    1388 }
    1389 
    1390 /**
    1391  * Register a settings error to be displayed to the user
    1392  *
    1393  * Part of the Settings API. Use this to show messages to users about settings validation
    1394  * problems, missing settings or anything else.
    1395  *
    1396  * Settings errors should be added inside the $sanitize_callback function defined in
    1397  * register_setting() for a given setting to give feedback about the submission.
    1398  *
    1399  * By default messages will show immediately after the submission that generated the error.
    1400  * Additional calls to settings_errors() can be used to show errors even when the settings
    1401  * page is first accessed.
    1402  *
    1403  * @since 3.0.0
    1404  *
    1405  * @global array $wp_settings_errors Storage array of errors registered during this pageload
    1406  *
    1407  * @param string $setting Slug title of the setting to which this error applies
    1408  * @param string $code    Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
    1409  * @param string $message The formatted message text to display to the user (will be shown inside styled
    1410  *                        `<div>` and `<p>` tags).
    1411  * @param string $type    Optional. Message type, controls HTML class. Accepts 'error' or 'updated'.
    1412  *                        Default 'error'.
    1413  */
    1414 function add_settings_error( $setting, $code, $message, $type = 'error' ) {
    1415     global $wp_settings_errors;
    1416 
    1417     $wp_settings_errors[] = array(
    1418         'setting' => $setting,
    1419         'code'    => $code,
    1420         'message' => $message,
    1421         'type'    => $type
    1422     );
    1423 }
    1424 
    1425 /**
    1426  * Fetch settings errors registered by add_settings_error()
    1427  *
    1428  * Checks the $wp_settings_errors array for any errors declared during the current
    1429  * pageload and returns them.
    1430  *
    1431  * If changes were just submitted ($_GET['settings-updated']) and settings errors were saved
    1432  * to the 'settings_errors' transient then those errors will be returned instead. This
    1433  * is used to pass errors back across pageloads.
    1434  *
    1435  * Use the $sanitize argument to manually re-sanitize the option before returning errors.
    1436  * This is useful if you have errors or notices you want to show even when the user
    1437  * hasn't submitted data (i.e. when they first load an options page, or in admin_notices action hook)
    1438  *
    1439  * @since 3.0.0
    1440  *
    1441  * @global array $wp_settings_errors Storage array of errors registered during this pageload
    1442  *
    1443  * @param string $setting Optional slug title of a specific setting who's errors you want.
    1444  * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
    1445  * @return array Array of settings errors
    1446  */
    1447 function get_settings_errors( $setting = '', $sanitize = false ) {
    1448     global $wp_settings_errors;
    1449 
    1450     /*
    1451      * If $sanitize is true, manually re-run the sanitization for this option
    1452      * This allows the $sanitize_callback from register_setting() to run, adding
    1453      * any settings errors you want to show by default.
    1454      */
    1455     if ( $sanitize )
    1456         sanitize_option( $setting, get_option( $setting ) );
    1457 
    1458     // If settings were passed back from options.php then use them.
    1459     if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && get_transient( 'settings_errors' ) ) {
    1460         $wp_settings_errors = array_merge( (array) $wp_settings_errors, get_transient( 'settings_errors' ) );
    1461         delete_transient( 'settings_errors' );
    1462     }
    1463 
    1464     // Check global in case errors have been added on this pageload.
    1465     if ( ! count( $wp_settings_errors ) )
    1466         return array();
    1467 
    1468     // Filter the results to those of a specific setting if one was set.
    1469     if ( $setting ) {
    1470         $setting_errors = array();
    1471         foreach ( (array) $wp_settings_errors as $key => $details ) {
    1472             if ( $setting == $details['setting'] )
    1473                 $setting_errors[] = $wp_settings_errors[$key];
    1474         }
    1475         return $setting_errors;
    1476     }
    1477 
    1478     return $wp_settings_errors;
    1479 }
    1480 
    1481 /**
    1482  * Display settings errors registered by {@see add_settings_error()}.
    1483  *
    1484  * Part of the Settings API. Outputs a div for each error retrieved by
    1485  * {@see get_settings_errors()}.
    1486  *
    1487  * This is called automatically after a settings page based on the
    1488  * Settings API is submitted. Errors should be added during the validation
    1489  * callback function for a setting defined in {@see register_setting()}
    1490  *
    1491  * The $sanitize option is passed into {@see get_settings_errors()} and will
    1492  * re-run the setting sanitization
    1493  * on its current value.
    1494  *
    1495  * The $hide_on_update option will cause errors to only show when the settings
    1496  * page is first loaded. if the user has already saved new values it will be
    1497  * hidden to avoid repeating messages already shown in the default error
    1498  * reporting after submission. This is useful to show general errors like
    1499  * missing settings when the user arrives at the settings page.
    1500  *
    1501  * @since 3.0.0
    1502  *
    1503  * @param string $setting        Optional slug title of a specific setting who's errors you want.
    1504  * @param bool   $sanitize       Whether to re-sanitize the setting value before returning errors.
    1505  * @param bool   $hide_on_update If set to true errors will not be shown if the settings page has already been submitted.
    1506  */
    1507 function settings_errors( $setting = '', $sanitize = false, $hide_on_update = false ) {
    1508 
    1509     if ( $hide_on_update && ! empty( $_GET['settings-updated'] ) )
    1510         return;
    1511 
    1512     $settings_errors = get_settings_errors( $setting, $sanitize );
    1513 
    1514     if ( empty( $settings_errors ) )
    1515         return;
    1516 
    1517     $output = '';
    1518     foreach ( $settings_errors as $key => $details ) {
    1519         $css_id = 'setting-error-' . $details['code'];
    1520         $css_class = $details['type'] . ' settings-error notice is-dismissible';
    1521         $output .= "<div id='$css_id' class='$css_class'> \n";
    1522         $output .= "<p><strong>{$details['message']}</strong></p>";
    1523         $output .= "</div> \n";
    1524     }
    1525     echo $output;
    1526 }
    1527 
    1528 /**
    1529  * {@internal Missing Short Description}}
    1530  *
    1531  * @since 2.7.0
    1532  *
    1533  * @param string $found_action
    1534  */
    1535 function find_posts_div($found_action = '') {
    1536 ?>
    1537     <div id="find-posts" class="find-box" style="display: none;">
    1538         <div id="find-posts-head" class="find-box-head">
    1539             <?php _e( 'Find Posts or Pages' ); ?>
    1540             <div id="find-posts-close"></div>
    1541         </div>
    1542         <div class="find-box-inside">
    1543             <div class="find-box-search">
    1544                 <?php if ( $found_action ) { ?>
    1545                     <input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" />
    1546                 <?php } ?>
    1547                 <input type="hidden" name="affected" id="affected" value="" />
    1548                 <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
    1549                 <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
    1550                 <input type="text" id="find-posts-input" name="ps" value="" />
    1551                 <span class="spinner"></span>
    1552                 <input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" />
    1553                 <div class="clear"></div>
    1554             </div>
    1555             <div id="find-posts-response"></div>
    1556         </div>
    1557         <div class="find-box-buttons">
    1558             <?php submit_button( __( 'Select' ), 'button-primary alignright', 'find-posts-submit', false ); ?>
    1559             <div class="clear"></div>
    1560         </div>
    1561     </div>
    1562 <?php
    1563 }
    1564 
    1565 /**
    1566  * Display the post password.
    1567  *
    1568  * The password is passed through {@link esc_attr()} to ensure that it
    1569  * is safe for placing in an html attribute.
    1570  *
    1571  * @since 2.7.0
    1572  */
    1573 function the_post_password() {
    1574     $post = get_post();
    1575     if ( isset( $post->post_password ) )
    1576         echo esc_attr( $post->post_password );
    1577 }
    1578 
    1579 /**
    1580  * Get the post title.
    1581  *
    1582  * The post title is fetched and if it is blank then a default string is
    1583  * returned.
    1584  *
    1585  * @since 2.7.0
    1586  *
    1587  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
    1588  * @return string The post title if set.
    1589  */
    1590 function _draft_or_post_title( $post = 0 ) {
    1591     $title = get_the_title( $post );
    1592     if ( empty( $title ) )
    1593         $title = __( '(no title)' );
    1594     return esc_html( $title );
    1595 }
    1596 
    1597 /**
    1598  * Display the search query.
    1599  *
    1600  * A simple wrapper to display the "s" parameter in a GET URI. This function
    1601  * should only be used when {@link the_search_query()} cannot.
    1602  *
    1603  * @since 2.7.0
    1604  */
    1605 function _admin_search_query() {
    1606     echo isset($_REQUEST['s']) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : '';
    1607 }
    1608 
    1609 /**
    1610  * Generic Iframe header for use with Thickbox
    1611  *
    1612  * @since 2.7.0
    1613  *
    1614  * @global string    $hook_suffix
    1615  * @global string    $admin_body_class
    1616  * @global WP_Locale $wp_locale
    1617  *
    1618  * @param string $title      Optional. Title of the Iframe page. Default empty.
    1619  * @param bool   $deprecated Not used.
    1620  */
    1621 function iframe_header( $title = '', $deprecated = false ) {
    1622     show_admin_bar( false );
    1623     global $hook_suffix, $admin_body_class, $wp_locale;
    1624     $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
    1625 
    1626     $current_screen = get_current_screen();
    1627 
    1628     @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
    1629     _wp_admin_html_begin();
    1630 ?>
    1631 <title><?php bloginfo('name') ?> &rsaquo; <?php echo $title ?> &#8212; <?php _e('WordPress'); ?></title>
    1632 <?php
    1633 wp_enqueue_style( 'colors' );
    1634 ?>
    1635 <script type="text/javascript">
    1636 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();}}};
    1637 function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
    1638 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>',
    1639     pagenow = '<?php echo $current_screen->id; ?>',
    1640     typenow = '<?php echo $current_screen->post_type; ?>',
    1641     adminpage = '<?php echo $admin_body_class; ?>',
    1642     thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
    1643     decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
    1644     isRtl = <?php echo (int) is_rtl(); ?>;
    1645 </script>
    1646 <?php
    1647 /** This action is documented in wp-admin/admin-header.php */
    1648 do_action( 'admin_enqueue_scripts', $hook_suffix );
    1649 
    1650 /** This action is documented in wp-admin/admin-header.php */
    1651 do_action( "admin_print_styles-$hook_suffix" );
    1652 
    1653 /** This action is documented in wp-admin/admin-header.php */
    1654 do_action( 'admin_print_styles' );
    1655 
    1656 /** This action is documented in wp-admin/admin-header.php */
    1657 do_action( "admin_print_scripts-$hook_suffix" );
    1658 
    1659 /** This action is documented in wp-admin/admin-header.php */
    1660 do_action( 'admin_print_scripts' );
    1661 
    1662 /** This action is documented in wp-admin/admin-header.php */
    1663 do_action( "admin_head-$hook_suffix" );
    1664 
    1665 /** This action is documented in wp-admin/admin-header.php */
    1666 do_action( 'admin_head' );
    1667 
    1668 $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
    1669 
    1670 if ( is_rtl() )
    1671     $admin_body_class .= ' rtl';
    1672 
    1673 ?>
    1674 </head>
    1675 <?php
    1676 /** This filter is documented in wp-admin/admin-header.php */
    1677 $admin_body_classes = apply_filters( 'admin_body_class', '' );
    1678 ?>
    1679 <body<?php
    1680 /**
    1681  * @global string $body_id
    1682  */