[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

/wp-admin/includes/ -> template.php (source)

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


Generated: Mon Jun 17 08:20:02 2019 Cross-referenced by PHPXref 0.7