home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress / wp-admin / includes / template.php < prev    next >
Encoding:
PHP Script  |  2017-11-10  |  78.1 KB  |  2,185 lines

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