[ Index ]

PHP Cross Reference of WordPress

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              printf(
1113                  /* translators: %s: A link to install the Classic Editor plugin. */
1114                  __( 'Please install the <a href="%s">Classic Editor plugin</a> to use this meta box.' ),
1115                  esc_url( wp_nonce_url( self_admin_url( 'plugin-install.php?tab=favorites&user=wordpressdotorg&save=0' ), 'save_wporg_username_' . get_current_user_id() ) )
1116              );
1117              echo '</p>';
1118          }
1119      } elseif ( is_plugin_inactive( 'classic-editor/classic-editor.php' ) ) {
1120          if ( current_user_can( 'activate_plugins' ) ) {
1121              $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' );
1122              echo '<p>';
1123              /* translators: %s: A link to activate the Classic Editor plugin. */
1124              printf( __( 'Please activate the <a href="%s">Classic Editor plugin</a> to use this meta box.' ), esc_url( $activate_url ) );
1125              echo '</p>';
1126          }
1127      } elseif ( $object instanceof WP_Post ) {
1128          $edit_url = add_query_arg(
1129              array(
1130                  'classic-editor'         => '',
1131                  'classic-editor__forget' => '',
1132              ),
1133              get_edit_post_link( $object )
1134          );
1135          echo '<p>';
1136          /* translators: %s: A link to use the Classic Editor plugin. */
1137          printf( __( 'Please open the <a href="%s">classic editor</a> to use this meta box.' ), esc_url( $edit_url ) );
1138          echo '</p>';
1139      }
1140  }
1141  
1142  /**
1143   * Internal helper function to find the plugin from a meta box callback.
1144   *
1145   * @since 5.0.0
1146   *
1147   * @access private
1148   *
1149   * @param callable $callback The callback function to check.
1150   * @return array|null The plugin that the callback belongs to, or null if it doesn't belong to a plugin.
1151   */
1152  function _get_plugin_from_callback( $callback ) {
1153      try {
1154          if ( is_array( $callback ) ) {
1155              $reflection = new ReflectionMethod( $callback[0], $callback[1] );
1156          } elseif ( is_string( $callback ) && false !== strpos( $callback, '::' ) ) {
1157              $reflection = new ReflectionMethod( $callback );
1158          } else {
1159              $reflection = new ReflectionFunction( $callback );
1160          }
1161      } catch ( ReflectionException $exception ) {
1162          // We could not properly reflect on the callable, so we abort here.
1163          return null;
1164      }
1165  
1166      // Don't show an error if it's an internal PHP function.
1167      if ( ! $reflection->isInternal() ) {
1168  
1169          // Only show errors if the meta box was registered by a plugin.
1170          $filename   = wp_normalize_path( $reflection->getFileName() );
1171          $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
1172          if ( strpos( $filename, $plugin_dir ) === 0 ) {
1173              $filename = str_replace( $plugin_dir, '', $filename );
1174              $filename = preg_replace( '|^/([^/]*/).*$|', '\\1', $filename );
1175  
1176              $plugins = get_plugins();
1177              foreach ( $plugins as $name => $plugin ) {
1178                  if ( strpos( $name, $filename ) === 0 ) {
1179                      return $plugin;
1180                  }
1181              }
1182          }
1183      }
1184  
1185      return null;
1186  }
1187  
1188  /**
1189   * Meta-Box template function.
1190   *
1191   * @since 2.5.0
1192   *
1193   * @global array $wp_meta_boxes
1194   *
1195   * @staticvar bool $already_sorted
1196   *
1197   * @param string|WP_Screen $screen  Screen identifier. If you have used add_menu_page() or
1198   *                                  add_submenu_page() to create a new screen (and hence screen_id)
1199   *                                  make sure your menu slug conforms to the limits of sanitize_key()
1200   *                                  otherwise the 'screen' menu may not correctly render on your page.
1201   * @param string           $context The screen context for which to display meta boxes.
1202   * @param mixed            $object  Gets passed to the first parameter of the meta box callback function.
1203   *                                  Often this is the object that's the focus of the current screen, for
1204   *                                  example a `WP_Post` or `WP_Comment` object.
1205   * @return int number of meta_boxes
1206   */
1207  function do_meta_boxes( $screen, $context, $object ) {
1208      global $wp_meta_boxes;
1209      static $already_sorted = false;
1210  
1211      if ( empty( $screen ) ) {
1212          $screen = get_current_screen();
1213      } elseif ( is_string( $screen ) ) {
1214          $screen = convert_to_screen( $screen );
1215      }
1216  
1217      $page = $screen->id;
1218  
1219      $hidden = get_hidden_meta_boxes( $screen );
1220  
1221      printf( '<div id="%s-sortables" class="meta-box-sortables">', esc_attr( $context ) );
1222  
1223      // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
1224      $sorted = get_user_option( "meta-box-order_$page" );
1225      if ( ! $already_sorted && $sorted ) {
1226          foreach ( $sorted as $box_context => $ids ) {
1227              foreach ( explode( ',', $ids ) as $id ) {
1228                  if ( $id && 'dashboard_browser_nag' !== $id ) {
1229                      add_meta_box( $id, null, null, $screen, $box_context, 'sorted' );
1230                  }
1231              }
1232          }
1233      }
1234  
1235      $already_sorted = true;
1236  
1237      $i = 0;
1238  
1239      if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
1240          foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
1241              if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
1242                  foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
1243                      if ( false == $box || ! $box['title'] ) {
1244                          continue;
1245                      }
1246  
1247                      $block_compatible = true;
1248                      if ( is_array( $box['args'] ) ) {
1249                          // If a meta box is just here for back compat, don't show it in the block editor.
1250                          if ( $screen->is_block_editor() && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) {
1251                              continue;
1252                          }
1253  
1254                          if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) {
1255                              $block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box'];
1256                              unset( $box['args']['__block_editor_compatible_meta_box'] );
1257                          }
1258  
1259                          // If the meta box is declared as incompatible with the block editor, override the callback function.
1260                          if ( ! $block_compatible && $screen->is_block_editor() ) {
1261                              $box['old_callback'] = $box['callback'];
1262                              $box['callback']     = 'do_block_editor_incompatible_meta_box';
1263                          }
1264  
1265                          if ( isset( $box['args']['__back_compat_meta_box'] ) ) {
1266                              $block_compatible = $block_compatible || (bool) $box['args']['__back_compat_meta_box'];
1267                              unset( $box['args']['__back_compat_meta_box'] );
1268                          }
1269                      }
1270  
1271                      $i++;
1272                      // get_hidden_meta_boxes() doesn't apply in the block editor.
1273                      $hidden_class = ( ! $screen->is_block_editor() && in_array( $box['id'], $hidden ) ) ? ' hide-if-js' : '';
1274                      echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes( $box['id'], $page ) . $hidden_class . '" ' . '>' . "\n";
1275                      if ( 'dashboard_browser_nag' != $box['id'] ) {
1276                          $widget_title = $box['title'];
1277  
1278                          if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) {
1279                              $widget_title = $box['args']['__widget_basename'];
1280                              // Do not pass this parameter to the user callback function.
1281                              unset( $box['args']['__widget_basename'] );
1282                          }
1283  
1284                          echo '<button type="button" class="handlediv" aria-expanded="true">';
1285                          echo '<span class="screen-reader-text">' . sprintf( __( 'Toggle panel: %s' ), $widget_title ) . '</span>';
1286                          echo '<span class="toggle-indicator" aria-hidden="true"></span>';
1287                          echo '</button>';
1288                      }
1289                      echo '<h2 class="hndle">';
1290                      if ( 'dashboard_php_nag' === $box['id'] ) {
1291                          echo '<span aria-hidden="true" class="dashicons dashicons-warning"></span>';
1292                          echo '<span class="screen-reader-text">' . __( 'Warning:' ) . ' </span>';
1293                      }
1294                      echo "<span>{$box['title']}</span>";
1295                      echo "</h2>\n";
1296                      echo '<div class="inside">' . "\n";
1297  
1298                      if ( WP_DEBUG && ! $block_compatible && 'edit' === $screen->parent_base && ! $screen->is_block_editor() && ! isset( $_GET['meta-box-loader'] ) ) {
1299                          $plugin = _get_plugin_from_callback( $box['callback'] );
1300                          if ( $plugin ) {
1301                              ?>
1302                              <div class="error inline">
1303                                  <p>
1304                                      <?php
1305                                          /* translators: %s: the name of the plugin that generated this meta box. */
1306                                          printf( __( "This meta box, from the %s plugin, isn't compatible with the block editor." ), "<strong>{$plugin['Name']}</strong>" );
1307                                      ?>
1308                                  </p>
1309                              </div>
1310                              <?php
1311                          }
1312                      }
1313  
1314                      call_user_func( $box['callback'], $object, $box );
1315                      echo "</div>\n";
1316                      echo "</div>\n";
1317                  }
1318              }
1319          }
1320      }
1321  
1322      echo '</div>';
1323  
1324      return $i;
1325  
1326  }
1327  
1328  /**
1329   * Removes a meta box from one or more screens.
1330   *
1331   * @since 2.6.0
1332   * @since 4.4.0 The `$screen` parameter now accepts an array of screen IDs.
1333   *
1334   * @global array $wp_meta_boxes
1335   *
1336   * @param string                 $id      Meta box ID (used in the 'id' attribute for the meta box).
1337   * @param string|array|WP_Screen $screen  The screen or screens on which the meta box is shown (such as a
1338   *                                        post type, 'link', or 'comment'). Accepts a single screen ID,
1339   *                                        WP_Screen object, or array of screen IDs.
1340   * @param string                 $context The context within the screen where the box is set to display.
1341   *                                        Contexts vary from screen to screen. Post edit screen contexts
1342   *                                        include 'normal', 'side', and 'advanced'. Comments screen contexts
1343   *                                        include 'normal' and 'side'. Menus meta boxes (accordion sections)
1344   *                                        all use the 'side' context.
1345   */
1346  function remove_meta_box( $id, $screen, $context ) {
1347      global $wp_meta_boxes;
1348  
1349      if ( empty( $screen ) ) {
1350          $screen = get_current_screen();
1351      } elseif ( is_string( $screen ) ) {
1352          $screen = convert_to_screen( $screen );
1353      } elseif ( is_array( $screen ) ) {
1354          foreach ( $screen as $single_screen ) {
1355              remove_meta_box( $id, $single_screen, $context );
1356          }
1357      }
1358  
1359      if ( ! isset( $screen->id ) ) {
1360          return;
1361      }
1362  
1363      $page = $screen->id;
1364  
1365      if ( ! isset( $wp_meta_boxes ) ) {
1366          $wp_meta_boxes = array();
1367      }
1368      if ( ! isset( $wp_meta_boxes[ $page ] ) ) {
1369          $wp_meta_boxes[ $page ] = array();
1370      }
1371      if ( ! isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
1372          $wp_meta_boxes[ $page ][ $context ] = array();
1373      }
1374  
1375      foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
1376          $wp_meta_boxes[ $page ][ $context ][ $priority ][ $id ] = false;
1377      }
1378  }
1379  
1380  /**
1381   * Meta Box Accordion Template Function.
1382   *
1383   * Largely made up of abstracted code from do_meta_boxes(), this
1384   * function serves to build meta boxes as list items for display as
1385   * a collapsible accordion.
1386   *
1387   * @since 3.6.0
1388   *
1389   * @uses global $wp_meta_boxes Used to retrieve registered meta boxes.
1390   *
1391   * @param string|object $screen  The screen identifier.
1392   * @param string        $context The meta box context.
1393   * @param mixed         $object  gets passed to the section callback function as first parameter.
1394   * @return int number of meta boxes as accordion sections.
1395   */
1396  function do_accordion_sections( $screen, $context, $object ) {
1397      global $wp_meta_boxes;
1398  
1399      wp_enqueue_script( 'accordion' );
1400  
1401      if ( empty( $screen ) ) {
1402          $screen = get_current_screen();
1403      } elseif ( is_string( $screen ) ) {
1404          $screen = convert_to_screen( $screen );
1405      }
1406  
1407      $page = $screen->id;
1408  
1409      $hidden = get_hidden_meta_boxes( $screen );
1410      ?>
1411      <div id="side-sortables" class="accordion-container">
1412          <ul class="outer-border">
1413      <?php
1414      $i          = 0;
1415      $first_open = false;
1416  
1417      if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
1418          foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
1419              if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
1420                  foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
1421                      if ( false == $box || ! $box['title'] ) {
1422                          continue;
1423                      }
1424                      $i++;
1425                      $hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
1426  
1427                      $open_class = '';
1428                      if ( ! $first_open && empty( $hidden_class ) ) {
1429                          $first_open = true;
1430                          $open_class = 'open';
1431                      }
1432                      ?>
1433                      <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'] ); ?>">
1434                          <h3 class="accordion-section-title hndle" tabindex="0">
1435                              <?php echo esc_html( $box['title'] ); ?>
1436                              <span class="screen-reader-text"><?php _e( 'Press return or enter to open this section' ); ?></span>
1437                          </h3>
1438                          <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
1439                              <div class="inside">
1440                                  <?php call_user_func( $box['callback'], $object, $box ); ?>
1441                              </div><!-- .inside -->
1442                          </div><!-- .accordion-section-content -->
1443                      </li><!-- .accordion-section -->
1444                      <?php
1445                  }
1446              }
1447          }
1448      }
1449      ?>
1450          </ul><!-- .outer-border -->
1451      </div><!-- .accordion-container -->
1452      <?php
1453      return $i;
1454  }
1455  
1456  /**
1457   * Add a new section to a settings page.
1458   *
1459   * Part of the Settings API. Use this to define new settings sections for an admin page.
1460   * Show settings sections in your admin page callback function with do_settings_sections().
1461   * Add settings fields to your section with add_settings_field().
1462   *
1463   * The $callback argument should be the name of a function that echoes out any
1464   * content you want to show at the top of the settings section before the actual
1465   * fields. It can output nothing if you want.
1466   *
1467   * @since 2.7.0
1468   *
1469   * @global $wp_settings_sections Storage array of all settings sections added to admin pages.
1470   *
1471   * @param string   $id       Slug-name to identify the section. Used in the 'id' attribute of tags.
1472   * @param string   $title    Formatted title of the section. Shown as the heading for the section.
1473   * @param callable $callback Function that echos out any content at the top of the section (between heading and fields).
1474   * @param string   $page     The slug-name of the settings page on which to show the section. Built-in pages include
1475   *                           'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using
1476   *                           add_options_page();
1477   */
1478  function add_settings_section( $id, $title, $callback, $page ) {
1479      global $wp_settings_sections;
1480  
1481      if ( 'misc' == $page ) {
1482          _deprecated_argument(
1483              __FUNCTION__,
1484              '3.0.0',
1485              /* translators: %s: misc */
1486              sprintf(
1487                  __( 'The "%s" options group has been removed. Use another settings group.' ),
1488                  'misc'
1489              )
1490          );
1491          $page = 'general';
1492      }
1493  
1494      if ( 'privacy' == $page ) {
1495          _deprecated_argument(
1496              __FUNCTION__,
1497              '3.5.0',
1498              /* translators: %s: privacy */
1499              sprintf(
1500                  __( 'The "%s" options group has been removed. Use another settings group.' ),
1501                  'privacy'
1502              )
1503          );
1504          $page = 'reading';
1505      }
1506  
1507      $wp_settings_sections[ $page ][ $id ] = array(
1508          'id'       => $id,
1509          'title'    => $title,
1510          'callback' => $callback,
1511      );
1512  }
1513  
1514  /**
1515   * Add a new field to a section of a settings page.
1516   *
1517   * Part of the Settings API. Use this to define a settings field that will show
1518   * as part of a settings section inside a settings page. The fields are shown using
1519   * do_settings_fields() in do_settings-sections()
1520   *
1521   * The $callback argument should be the name of a function that echoes out the
1522   * html input tags for this setting field. Use get_option() to retrieve existing
1523   * values to show.
1524   *
1525   * @since 2.7.0
1526   * @since 4.2.0 The `$class` argument was added.
1527   *
1528   * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections.
1529   *
1530   * @param string   $id       Slug-name to identify the field. Used in the 'id' attribute of tags.
1531   * @param string   $title    Formatted title of the field. Shown as the label for the field
1532   *                           during output.
1533   * @param callable $callback Function that fills the field with the desired form inputs. The
1534   *                           function should echo its output.
1535   * @param string   $page     The slug-name of the settings page on which to show the section
1536   *                           (general, reading, writing, ...).
1537   * @param string   $section  Optional. The slug-name of the section of the settings page
1538   *                           in which to show the box. Default 'default'.
1539   * @param array    $args {
1540   *     Optional. Extra arguments used when outputting the field.
1541   *
1542   *     @type string $label_for When supplied, the setting title will be wrapped
1543   *                             in a `<label>` element, its `for` attribute populated
1544   *                             with this value.
1545   *     @type string $class     CSS Class to be added to the `<tr>` element when the
1546   *                             field is output.
1547   * }
1548   */
1549  function add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array() ) {
1550      global $wp_settings_fields;
1551  
1552      if ( 'misc' == $page ) {
1553          _deprecated_argument(
1554              __FUNCTION__,
1555              '3.0.0',
1556              /* translators: %s: misc */
1557              sprintf(
1558                  __( 'The "%s" options group has been removed. Use another settings group.' ),
1559                  'misc'
1560              )
1561          );
1562          $page = 'general';
1563      }
1564  
1565      if ( 'privacy' == $page ) {
1566          _deprecated_argument(
1567              __FUNCTION__,
1568              '3.5.0',
1569              /* translators: %s: privacy */
1570              sprintf(
1571                  __( 'The "%s" options group has been removed. Use another settings group.' ),
1572                  'privacy'
1573              )
1574          );
1575          $page = 'reading';
1576      }
1577  
1578      $wp_settings_fields[ $page ][ $section ][ $id ] = array(
1579          'id'       => $id,
1580          'title'    => $title,
1581          'callback' => $callback,
1582          'args'     => $args,
1583      );
1584  }
1585  
1586  /**
1587   * Prints out all settings sections added to a particular settings page
1588   *
1589   * Part of the Settings API. Use this in a settings page callback function
1590   * to output all the sections and fields that were added to that $page with
1591   * add_settings_section() and add_settings_field()
1592   *
1593   * @global $wp_settings_sections Storage array of all settings sections added to admin pages.
1594   * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections.
1595   * @since 2.7.0
1596   *
1597   * @param string $page The slug name of the page whose settings sections you want to output.
1598   */
1599  function do_settings_sections( $page ) {
1600      global $wp_settings_sections, $wp_settings_fields;
1601  
1602      if ( ! isset( $wp_settings_sections[ $page ] ) ) {
1603          return;
1604      }
1605  
1606      foreach ( (array) $wp_settings_sections[ $page ] as $section ) {
1607          if ( $section['title'] ) {
1608              echo "<h2>{$section['title']}</h2>\n";
1609          }
1610  
1611          if ( $section['callback'] ) {
1612              call_user_func( $section['callback'], $section );
1613          }
1614  
1615          if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[ $page ] ) || ! isset( $wp_settings_fields[ $page ][ $section['id'] ] ) ) {
1616              continue;
1617          }
1618          echo '<table class="form-table" role="presentation">';
1619          do_settings_fields( $page, $section['id'] );
1620          echo '</table>';
1621      }
1622  }
1623  
1624  /**
1625   * Print out the settings fields for a particular settings section.
1626   *
1627   * Part of the Settings API. Use this in a settings page to output
1628   * a specific section. Should normally be called by do_settings_sections()
1629   * rather than directly.
1630   *
1631   * @global $wp_settings_fields Storage array of settings fields and their pages/sections.
1632   *
1633   * @since 2.7.0
1634   *
1635   * @param string $page Slug title of the admin page whose settings fields you want to show.
1636   * @param string $section Slug title of the settings section whose fields you want to show.
1637   */
1638  function do_settings_fields( $page, $section ) {
1639      global $wp_settings_fields;
1640  
1641      if ( ! isset( $wp_settings_fields[ $page ][ $section ] ) ) {
1642          return;
1643      }
1644  
1645      foreach ( (array) $wp_settings_fields[ $page ][ $section ] as $field ) {
1646          $class = '';
1647  
1648          if ( ! empty( $field['args']['class'] ) ) {
1649              $class = ' class="' . esc_attr( $field['args']['class'] ) . '"';
1650          }
1651  
1652          echo "<tr{$class}>";
1653  
1654          if ( ! empty( $field['args']['label_for'] ) ) {
1655              echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>';
1656          } else {
1657              echo '<th scope="row">' . $field['title'] . '</th>';
1658          }
1659  
1660          echo '<td>';
1661          call_user_func( $field['callback'], $field['args'] );
1662          echo '</td>';
1663          echo '</tr>';
1664      }
1665  }
1666  
1667  /**
1668   * Register a settings error to be displayed to the user.
1669   *
1670   * Part of the Settings API. Use this to show messages to users about settings validation
1671   * problems, missing settings or anything else.
1672   *
1673   * Settings errors should be added inside the $sanitize_callback function defined in
1674   * register_setting() for a given setting to give feedback about the submission.
1675   *
1676   * By default messages will show immediately after the submission that generated the error.
1677   * Additional calls to settings_errors() can be used to show errors even when the settings
1678   * page is first accessed.
1679   *
1680   * @since 3.0.0
1681   *
1682   * @global array $wp_settings_errors Storage array of errors registered during this pageload
1683   *
1684   * @param string $setting Slug title of the setting to which this error applies.
1685   * @param string $code    Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
1686   * @param string $message The formatted message text to display to the user (will be shown inside styled
1687   *                        `<div>` and `<p>` tags).
1688   * @param string $type    Optional. Message type, controls HTML class. Accepts 'error' or 'updated'.
1689   *                        Default 'error'.
1690   */
1691  function add_settings_error( $setting, $code, $message, $type = 'error' ) {
1692      global $wp_settings_errors;
1693  
1694      $wp_settings_errors[] = array(
1695          'setting' => $setting,
1696          'code'    => $code,
1697          'message' => $message,
1698          'type'    => $type,
1699      );
1700  }
1701  
1702  /**
1703   * Fetch settings errors registered by add_settings_error().
1704   *
1705   * Checks the $wp_settings_errors array for any errors declared during the current
1706   * pageload and returns them.
1707   *
1708   * If changes were just submitted ($_GET['settings-updated']) and settings errors were saved
1709   * to the 'settings_errors' transient then those errors will be returned instead. This
1710   * is used to pass errors back across pageloads.
1711   *
1712   * Use the $sanitize argument to manually re-sanitize the option before returning errors.
1713   * This is useful if you have errors or notices you want to show even when the user
1714   * hasn't submitted data (i.e. when they first load an options page, or in the {@see 'admin_notices'}
1715   * action hook).
1716   *
1717   * @since 3.0.0
1718   *
1719   * @global array $wp_settings_errors Storage array of errors registered during this pageload
1720   *
1721   * @param string $setting Optional slug title of a specific setting whose errors you want.
1722   * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
1723   * @return array Array of settings errors.
1724   */
1725  function get_settings_errors( $setting = '', $sanitize = false ) {
1726      global $wp_settings_errors;
1727  
1728      /*
1729       * If $sanitize is true, manually re-run the sanitization for this option
1730       * This allows the $sanitize_callback from register_setting() to run, adding
1731       * any settings errors you want to show by default.
1732       */
1733      if ( $sanitize ) {
1734          sanitize_option( $setting, get_option( $setting ) );
1735      }
1736  
1737      // If settings were passed back from options.php then use them.
1738      if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && get_transient( 'settings_errors' ) ) {
1739          $wp_settings_errors = array_merge( (array) $wp_settings_errors, get_transient( 'settings_errors' ) );
1740          delete_transient( 'settings_errors' );
1741      }
1742  
1743      // Check global in case errors have been added on this pageload.
1744      if ( empty( $wp_settings_errors ) ) {
1745          return array();
1746      }
1747  
1748      // Filter the results to those of a specific setting if one was set.
1749      if ( $setting ) {
1750          $setting_errors = array();
1751          foreach ( (array) $wp_settings_errors as $key => $details ) {
1752              if ( $setting == $details['setting'] ) {
1753                  $setting_errors[] = $wp_settings_errors[ $key ];
1754              }
1755          }
1756          return $setting_errors;
1757      }
1758  
1759      return $wp_settings_errors;
1760  }
1761  
1762  /**
1763   * Display settings errors registered by add_settings_error().
1764   *
1765   * Part of the Settings API. Outputs a div for each error retrieved by
1766   * get_settings_errors().
1767   *
1768   * This is called automatically after a settings page based on the
1769   * Settings API is submitted. Errors should be added during the validation
1770   * callback function for a setting defined in register_setting().
1771   *
1772   * The $sanitize option is passed into get_settings_errors() and will
1773   * re-run the setting sanitization
1774   * on its current value.
1775   *
1776   * The $hide_on_update option will cause errors to only show when the settings
1777   * page is first loaded. if the user has already saved new values it will be
1778   * hidden to avoid repeating messages already shown in the default error
1779   * reporting after submission. This is useful to show general errors like
1780   * missing settings when the user arrives at the settings page.
1781   *
1782   * @since 3.0.0
1783   *
1784   * @param string $setting        Optional slug title of a specific setting whose errors you want.
1785   * @param bool   $sanitize       Whether to re-sanitize the setting value before returning errors.
1786   * @param bool   $hide_on_update If set to true errors will not be shown if the settings page has
1787   *                               already been submitted.
1788   */
1789  function settings_errors( $setting = '', $sanitize = false, $hide_on_update = false ) {
1790  
1791      if ( $hide_on_update && ! empty( $_GET['settings-updated'] ) ) {
1792          return;
1793      }
1794  
1795      $settings_errors = get_settings_errors( $setting, $sanitize );
1796  
1797      if ( empty( $settings_errors ) ) {
1798          return;
1799      }
1800  
1801      $output = '';
1802      foreach ( $settings_errors as $key => $details ) {
1803          $css_id    = 'setting-error-' . $details['code'];
1804          $css_class = $details['type'] . ' settings-error notice is-dismissible';
1805          $output   .= "<div id='$css_id' class='$css_class'> \n";
1806          $output   .= "<p><strong>{$details['message']}</strong></p>";
1807          $output   .= "</div> \n";
1808      }
1809      echo $output;
1810  }
1811  
1812  /**
1813   * Outputs the modal window used for attaching media to posts or pages in the media-listing screen.
1814   *
1815   * @since 2.7.0
1816   *
1817   * @param string $found_action
1818   */
1819  function find_posts_div( $found_action = '' ) {
1820      ?>
1821      <div id="find-posts" class="find-box" style="display: none;">
1822          <div id="find-posts-head" class="find-box-head">
1823              <?php _e( 'Attach to existing content' ); ?>
1824              <button type="button" id="find-posts-close"><span class="screen-reader-text"><?php _e( 'Close media attachment panel' ); ?></span></button>
1825          </div>
1826          <div class="find-box-inside">
1827              <div class="find-box-search">
1828                  <?php if ( $found_action ) { ?>
1829                      <input type="hidden" name="found_action" value="<?php echo esc_attr( $found_action ); ?>" />
1830                  <?php } ?>
1831                  <input type="hidden" name="affected" id="affected" value="" />
1832                  <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
1833                  <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
1834                  <input type="text" id="find-posts-input" name="ps" value="" />
1835                  <span class="spinner"></span>
1836                  <input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" />
1837                  <div class="clear"></div>
1838              </div>
1839              <div id="find-posts-response"></div>
1840          </div>
1841          <div class="find-box-buttons">
1842              <?php submit_button( __( 'Select' ), 'primary alignright', 'find-posts-submit', false ); ?>
1843              <div class="clear"></div>
1844          </div>
1845      </div>
1846      <?php
1847  }
1848  
1849  /**
1850   * Displays the post password.
1851   *
1852   * The password is passed through esc_attr() to ensure that it is safe for placing in an html attribute.
1853   *
1854   * @since 2.7.0
1855   */
1856  function the_post_password() {
1857      $post = get_post();
1858      if ( isset( $post->post_password ) ) {
1859          echo esc_attr( $post->post_password );
1860      }
1861  }
1862  
1863  /**
1864   * Get the post title.
1865   *
1866   * The post title is fetched and if it is blank then a default string is
1867   * returned.
1868   *
1869   * @since 2.7.0
1870   *
1871   * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
1872   * @return string The post title if set.
1873   */
1874  function _draft_or_post_title( $post = 0 ) {
1875      $title = get_the_title( $post );
1876      if ( empty( $title ) ) {
1877          $title = __( '(no title)' );
1878      }
1879      return esc_html( $title );
1880  }
1881  
1882  /**
1883   * Displays the search query.
1884   *
1885   * A simple wrapper to display the "s" parameter in a `GET` URI. This function
1886   * should only be used when the_search_query() cannot.
1887   *
1888   * @since 2.7.0
1889   */
1890  function _admin_search_query() {
1891      echo isset( $_REQUEST['s'] ) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : '';
1892  }
1893  
1894  /**
1895   * Generic Iframe header for use with Thickbox
1896   *
1897   * @since 2.7.0
1898   *
1899   * @global string    $hook_suffix
1900   * @global string    $admin_body_class
1901   * @global WP_Locale $wp_locale
1902   *
1903   * @param string $title      Optional. Title of the Iframe page. Default empty.
1904   * @param bool   $deprecated Not used.
1905   */
1906  function iframe_header( $title = '', $deprecated = false ) {
1907      show_admin_bar( false );
1908      global $hook_suffix, $admin_body_class, $wp_locale;
1909      $admin_body_class = preg_replace( '/[^a-z0-9_-]+/i', '-', $hook_suffix );
1910  
1911      $current_screen = get_current_screen();
1912  
1913      header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
1914      _wp_admin_html_begin();
1915      ?>
1916  <title><?php bloginfo( 'name' ); ?> &rsaquo; <?php echo $title; ?> &#8212; <?php _e( 'WordPress' ); ?></title>
1917      <?php
1918      wp_enqueue_style( 'colors' );
1919      ?>
1920  <script type="text/javascript">
1921  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();}}};
1922  function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
1923  var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>',
1924      pagenow = '<?php echo $current_screen->id; ?>',
1925      typenow = '<?php echo $current_screen->post_type; ?>',
1926      adminpage = '<?php echo $admin_body_class; ?>',
1927      thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
1928      decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
1929      isRtl = <?php echo (int) is_rtl(); ?>;
1930  </script>
1931      <?php
1932      /** This action is documented in wp-admin/admin-header.php */
1933      do_action( 'admin_enqueue_scripts', $hook_suffix );
1934  
1935      /** This action is documented in wp-admin/admin-header.php */
1936      do_action( "admin_print_styles-$hook_suffix" );  // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1937  
1938      /** This action is documented in wp-admin/admin-header.php */
1939      do_action( 'admin_print_styles' );
1940  
1941      /** This action is documented in wp-admin/admin-header.php */
1942      do_action( "admin_print_scripts-$hook_suffix" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1943  
1944      /** This action is documented in wp-admin/admin-header.php */
1945      do_action( 'admin_print_scripts' );
1946  
1947      /** This action is documented in wp-admin/admin-header.php */
1948      do_action( "admin_head-$hook_suffix" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1949  
1950      /** This action is documented in wp-admin/admin-header.php */
1951      do_action( 'admin_head' );
1952  
1953      $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) );
1954  
1955      if ( is_rtl() ) {
1956          $admin_body_class .= ' rtl';
1957      }
1958  
1959      ?>
1960  </head>
1961      <?php
1962      /**
1963       * @global string $body_id
1964       */
1965      $admin_body_id = isset( $GLOBALS['body_id'] ) ? 'id="' . $GLOBALS['body_id'] . '" ' : '';
1966  
1967      /** This filter is documented in wp-admin/admin-header.php */
1968      $admin_body_classes = apply_filters( 'admin_body_class', '' );
1969      $admin_body_classes = ltrim( $admin_body_classes . ' ' . $admin_body_class );
1970      ?>
1971  <body <?php echo $admin_body_id; ?>class="wp-admin wp-core-ui no-js iframe <?php echo $admin_body_classes; ?>">
1972  <script type="text/javascript">
1973  (function(){
1974  var c = document.body.className;
1975  c = c.replace(/no-js/, 'js');
1976  document.body.className = c;
1977  })();
1978  </script>
1979      <?php
1980  }
1981  
1982  /**
1983   * Generic Iframe footer for use with Thickbox
1984   *
1985   * @since 2.7.0
1986   */
1987  function iframe_footer() {
1988      /*
1989       * We're going to hide any footer output on iFrame pages,
1990       * but run the hooks anyway since they output JavaScript
1991       * or other needed content.
1992       */
1993  
1994      /**
1995       * @global string $hook_suffix
1996       */
1997      global $hook_suffix;
1998      ?>
1999      <div class="hidden">
2000      <?php
2001      /** This action is documented in wp-admin/admin-footer.php */
2002      do_action( 'admin_footer', $hook_suffix );
2003  
2004      /** This action is documented in wp-admin/admin-footer.php */
2005      do_action( "admin_print_footer_scripts-$hook_suffix" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
2006  
2007      /** This action is documented in wp-admin/admin-footer.php */
2008      do_action( 'admin_print_footer_scripts' );
2009      ?>
2010      </div>
2011  <script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script>
2012  </body>
2013  </html>
2014      <?php
2015  }
2016  
2017  /**
2018   * @param WP_Post $post
2019   */
2020  function _post_states( $post ) {
2021      $post_states = array();
2022      if ( isset( $_REQUEST['post_status'] ) ) {
2023          $post_status = $_REQUEST['post_status'];
2024      } else {
2025          $post_status = '';
2026      }
2027  
2028      if ( ! empty( $post->post_password ) ) {
2029          $post_states['protected'] = __( 'Password protected' );
2030      }
2031      if ( 'private' == $post->post_status && 'private' != $post_status ) {
2032          $post_states['private'] = __( 'Private' );
2033      }
2034      if ( 'draft' === $post->post_status ) {
2035          if ( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
2036              $post_states[] = __( 'Customization Draft' );
2037          } elseif ( 'draft' !== $post_status ) {
2038              $post_states['draft'] = __( 'Draft' );
2039          }
2040      } elseif ( 'trash' === $post->post_status && get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
2041          $post_states[] = __( 'Customization Draft' );
2042      }
2043      if ( 'pending' == $post->post_status && 'pending' != $post_status ) {
2044          $post_states['pending'] = _x( 'Pending', 'post status' );
2045      }
2046      if ( is_sticky( $post->ID ) ) {
2047          $post_states['sticky'] = __( 'Sticky' );
2048      }
2049  
2050      if ( 'future' === $post->post_status ) {
2051          $post_states['scheduled'] = __( 'Scheduled' );
2052      }
2053  
2054      if ( 'page' === get_option( 'show_on_front' ) ) {
2055          if ( intval( get_option( 'page_on_front' ) ) === $post->ID ) {
2056              $post_states['page_on_front'] = __( 'Front Page' );
2057          }
2058  
2059          if ( intval( get_option( 'page_for_posts' ) ) === $post->ID ) {
2060              $post_states['page_for_posts'] = __( 'Posts Page' );
2061          }
2062      }
2063  
2064      if ( intval( get_option( 'wp_page_for_privacy_policy' ) ) === $post->ID ) {
2065          $post_states['page_for_privacy_policy'] = __( 'Privacy Policy Page' );
2066      }
2067  
2068      /**
2069       * Filters the default post display states used in the posts list table.
2070       *
2071       * @since 2.8.0
2072       * @since 3.6.0 Added the `$post` parameter.
2073       *
2074       * @param string[] $post_states An array of post display states.
2075       * @param WP_Post  $post        The current post object.
2076       */
2077      $post_states = apply_filters( 'display_post_states', $post_states, $post );
2078  
2079      if ( ! empty( $post_states ) ) {
2080          $state_count = count( $post_states );
2081          $i           = 0;
2082          echo ' &mdash; ';
2083          foreach ( $post_states as $state ) {
2084              ++$i;
2085              ( $i == $state_count ) ? $sep = '' : $sep = ', ';
2086              echo "<span class='post-state'>$state$sep</span>";
2087          }
2088      }
2089  
2090  }
2091  
2092  /**
2093   * @param WP_Post $post
2094   */
2095  function _media_states( $post ) {
2096      $media_states = array();
2097      $stylesheet   = get_option( 'stylesheet' );
2098  
2099      if ( current_theme_supports( 'custom-header' ) ) {
2100          $meta_header = get_post_meta( $post->ID, '_wp_attachment_is_custom_header', true );
2101  
2102          if ( is_random_header_image() ) {
2103              $header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' );
2104  
2105              if ( $meta_header == $stylesheet && in_array( $post->ID, $header_images ) ) {
2106                  $media_states[] = __( 'Header Image' );
2107              }
2108          } else {
2109              $header_image = get_header_image();
2110  
2111              // Display "Header Image" if the image was ever used as a header image
2112              if ( ! empty( $meta_header ) && $meta_header == $stylesheet && $header_image !== wp_get_attachment_url( $post->ID ) ) {
2113                  $media_states[] = __( 'Header Image' );
2114              }
2115  
2116              // Display "Current Header Image" if the image is currently the header image
2117              if ( $header_image && $header_image == wp_get_attachment_url( $post->ID ) ) {
2118                  $media_states[] = __( 'Current Header Image' );
2119              }
2120          }
2121      }
2122  
2123      if ( current_theme_supports( 'custom-background' ) ) {
2124          $meta_background = get_post_meta( $post->ID, '_wp_attachment_is_custom_background', true );
2125  
2126          if ( ! empty( $meta_background ) && $meta_background == $stylesheet ) {
2127              $media_states[] = __( 'Background Image' );
2128  
2129              $background_image = get_background_image();
2130              if ( $background_image && $background_image == wp_get_attachment_url( $post->ID ) ) {
2131                  $media_states[] = __( 'Current Background Image' );
2132              }
2133          }
2134      }
2135  
2136      if ( $post->ID == get_option( 'site_icon' ) ) {
2137          $media_states[] = __( 'Site Icon' );
2138      }
2139  
2140      if ( $post->ID == get_theme_mod( 'custom_logo' ) ) {
2141          $media_states[] = __( 'Logo' );
2142      }
2143  
2144      /**
2145       * Filters the default media display states for items in the Media list table.
2146       *
2147       * @since 3.2.0
2148       * @since 4.8.0 Added the `$post` parameter.
2149       *
2150       * @param string[] $media_states An array of media states. Default 'Header Image',
2151       *                               'Background Image', 'Site Icon', 'Logo'.
2152       * @param WP_Post  $post         The current attachment object.
2153       */
2154      $media_states = apply_filters( 'display_media_states', $media_states, $post );
2155  
2156      if ( ! empty( $media_states ) ) {
2157          $state_count = count( $media_states );
2158          $i           = 0;
2159          echo ' &mdash; ';
2160          foreach ( $media_states as $state ) {
2161              ++$i;
2162              ( $i == $state_count ) ? $sep = '' : $sep = ', ';
2163              echo "<span class='post-state'>$state$sep</span>";
2164          }
2165      }
2166  }
2167  
2168  /**
2169   * Test support for compressing JavaScript from PHP
2170   *
2171   * Outputs JavaScript that tests if compression from PHP works as expected
2172   * and sets an option with the result. Has no effect when the current user
2173   * is not an administrator. To run the test again the option 'can_compress_scripts'
2174   * has to be deleted.
2175   *
2176   * @since 2.8.0
2177   */
2178  function compression_test() {
2179      ?>
2180      <script type="text/javascript">
2181      var compressionNonce = <?php echo wp_json_encode( wp_create_nonce( 'update_can_compress_scripts' ) ); ?>;
2182      var testCompression = {
2183          get : function(test) {
2184              var x;
2185              if ( window.XMLHttpRequest ) {
2186                  x = new XMLHttpRequest();
2187              } else {
2188                  try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
2189              }
2190  
2191              if (x) {
2192                  x.onreadystatechange = function() {
2193                      var r, h;
2194                      if ( x.readyState == 4 ) {
2195                          r = x.responseText.substr(0, 18);
2196                          h = x.getResponseHeader('Content-Encoding');
2197                          testCompression.check(r, h, test);
2198                      }
2199                  };
2200  
2201                  x.open('GET', ajaxurl + '?action=wp-compression-test&test='+test+'&_ajax_nonce='+compressionNonce+'&'+(new Date()).getTime(), true);
2202                  x.send('');
2203              }
2204          },
2205  
2206          check : function(r, h, test) {
2207              if ( ! r && ! test )
2208                  this.get(1);
2209  
2210              if ( 1 == test ) {
2211                  if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) )
2212                      this.get('no');
2213                  else
2214                      this.get(2);
2215  
2216                  return;
2217              }
2218  
2219              if ( 2 == test ) {
2220                  if ( '"wpCompressionTest' == r )
2221                      this.get('yes');
2222                  else
2223                      this.get('no');
2224              }
2225          }
2226      };
2227      testCompression.check();
2228      </script>
2229      <?php
2230  }
2231  
2232  /**
2233   * Echoes a submit button, with provided text and appropriate class(es).
2234   *
2235   * @since 3.1.0
2236   *
2237   * @see get_submit_button()
2238   *
2239   * @param string       $text             The text of the button (defaults to 'Save Changes')
2240   * @param string       $type             Optional. The type and CSS class(es) of the button. Core values
2241   *                                       include 'primary', 'small', and 'large'. Default 'primary'.
2242   * @param string       $name             The HTML name of the submit button. Defaults to "submit". If no
2243   *                                       id attribute is given in $other_attributes below, $name will be
2244   *                                       used as the button's id.
2245   * @param bool         $wrap             True if the output button should be wrapped in a paragraph tag,
2246   *                                       false otherwise. Defaults to true.
2247   * @param array|string $other_attributes Other attributes that should be output with the button, mapping
2248   *                                       attributes to their values, such as setting tabindex to 1, etc.
2249   *                                       These key/value attribute pairs will be output as attribute="value",
2250   *                                       where attribute is the key. Other attributes can also be provided
2251   *                                       as a string such as 'tabindex="1"', though the array format is
2252   *                                       preferred. Default null.
2253   */
2254  function submit_button( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null ) {
2255      echo get_submit_button( $text, $type, $name, $wrap, $other_attributes );
2256  }
2257  
2258  /**
2259   * Returns a submit button, with provided text and appropriate class
2260   *
2261   * @since 3.1.0
2262   *
2263   * @param string       $text             Optional. The text of the button. Default 'Save Changes'.
2264   * @param string       $type             Optional. The type and CSS class(es) of the button. Core values
2265   *                                       include 'primary', 'small', and 'large'. Default 'primary large'.
2266   * @param string       $name             Optional. The HTML name of the submit button. Defaults to "submit".
2267   *                                       If no id attribute is given in $other_attributes below, `$name` will
2268   *                                       be used as the button's id. Default 'submit'.
2269   * @param bool         $wrap             Optional. True if the output button should be wrapped in a paragraph
2270   *                                       tag, false otherwise. Default true.
2271   * @param array|string $other_attributes Optional. Other attributes that should be output with the button,
2272   *                                       mapping attributes to their values, such as `array( 'tabindex' => '1' )`.
2273   *                                       These attributes will be output as `attribute="value"`, such as
2274   *                                       `tabindex="1"`. Other attributes can also be provided as a string such
2275   *                                       as `tabindex="1"`, though the array format is typically cleaner.
2276   *                                       Default empty.
2277   * @return string Submit button HTML.
2278   */
2279  function get_submit_button( $text = '', $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = '' ) {
2280      if ( ! is_array( $type ) ) {
2281          $type = explode( ' ', $type );
2282      }
2283  
2284      $button_shorthand = array( 'primary', 'small', 'large' );
2285      $classes          = array( 'button' );
2286      foreach ( $type as $t ) {
2287          if ( 'secondary' === $t || 'button-secondary' === $t ) {
2288              continue;
2289          }
2290          $classes[] = in_array( $t, $button_shorthand ) ? 'button-' . $t : $t;
2291      }
2292      // Remove empty items, remove duplicate items, and finally build a string.
2293      $class = implode( ' ', array_unique( array_filter( $classes ) ) );
2294  
2295      $text = $text ? $text : __( 'Save Changes' );
2296  
2297      // Default the id attribute to $name unless an id was specifically provided in $other_attributes
2298      $id = $name;
2299      if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) {
2300          $id = $other_attributes['id'];
2301          unset( $other_attributes['id'] );
2302      }
2303  
2304      $attributes = '';
2305      if ( is_array( $other_attributes ) ) {
2306          foreach ( $other_attributes as $attribute => $value ) {
2307              $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
2308          }
2309      } elseif ( ! empty( $other_attributes ) ) { // Attributes provided as a string
2310          $attributes = $other_attributes;
2311      }
2312  
2313      // Don't output empty name and id attributes.
2314      $name_attr = $name ? ' name="' . esc_attr( $name ) . '"' : '';
2315      $id_attr   = $id ? ' id="' . esc_attr( $id ) . '"' : '';
2316  
2317      $button  = '<input type="submit"' . $name_attr . $id_attr . ' class="' . esc_attr( $class );
2318      $button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />';
2319  
2320      if ( $wrap ) {
2321          $button = '<p class="submit">' . $button . '</p>';
2322      }
2323  
2324      return $button;
2325  }
2326  
2327  /**
2328   * @global bool $is_IE
2329   */
2330  function _wp_admin_html_begin() {
2331      global $is_IE;
2332  
2333      $admin_html_class = ( is_admin_bar_showing() ) ? 'wp-toolbar' : '';
2334  
2335      if ( $is_IE ) {
2336          header( 'X-UA-Compatible: IE=edge' );
2337      }
2338  
2339      ?>
2340  <!DOCTYPE html>
2341  <!--[if IE 8]>
2342  <html xmlns="http://www.w3.org/1999/xhtml" class="ie8 <?php echo $admin_html_class; ?>"
2343      <?php
2344      /**
2345       * Fires inside the HTML tag in the admin header.
2346       *
2347       * @since 2.2.0
2348       */
2349      do_action( 'admin_xml_ns' );
2350  
2351      language_attributes();
2352      ?>
2353      >
2354  <![endif]-->
2355  <!--[if !(IE 8) ]><!-->
2356  <html xmlns="http://www.w3.org/1999/xhtml" class="<?php echo $admin_html_class; ?>"
2357      <?php
2358      /** This action is documented in wp-admin/includes/template.php */
2359      do_action( 'admin_xml_ns' );
2360  
2361      language_attributes();
2362      ?>
2363      >
2364  <!--<![endif]-->
2365  <head>
2366  <meta http-equiv="Content-Type" content="<?php bloginfo( 'html_type' ); ?>; charset=<?php echo get_option( 'blog_charset' ); ?>" />
2367      <?php
2368  }
2369  
2370  /**
2371   * Convert a screen string to a screen object
2372   *
2373   * @since 3.0.0
2374   *
2375   * @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen.
2376   * @return WP_Screen Screen object.
2377   */
2378  function convert_to_screen( $hook_name ) {
2379      if ( ! class_exists( 'WP_Screen' ) ) {
2380          _doing_it_wrong(
2381              'convert_to_screen(), add_meta_box()',
2382              sprintf(
2383                  /* translators: 1: wp-admin/includes/template.php, 2: add_meta_box(), 3: add_meta_boxes */
2384                  __( '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.' ),
2385                  '<code>wp-admin/includes/template.php</code>',
2386                  '<code>add_meta_box()</code>',
2387                  '<code>add_meta_boxes</code>'
2388              ),
2389              '3.3.0'
2390          );
2391          return (object) array(
2392              'id'   => '_invalid',
2393              'base' => '_are_belong_to_us',
2394          );
2395      }
2396  
2397      return WP_Screen::get( $hook_name );
2398  }
2399  
2400  /**
2401   * Output the HTML for restoring the post data from DOM storage
2402   *
2403   * @since 3.6.0
2404   * @access private
2405   */
2406  function _local_storage_notice() {
2407      ?>
2408      <div id="local-storage-notice" class="hidden notice is-dismissible">
2409      <p class="local-restore">
2410          <?php _e( 'The backup of this post in your browser is different from the version below.' ); ?>
2411          <button type="button" class="button restore-backup"><?php _e( 'Restore the backup' ); ?></button>
2412      </p>
2413      <p class="help">
2414          <?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.' ); ?>
2415      </p>
2416      </div>
2417      <?php
2418  }
2419  
2420  /**
2421   * Output a HTML element with a star rating for a given rating.
2422   *
2423   * Outputs a HTML element with the star rating exposed on a 0..5 scale in
2424   * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the
2425   * number of ratings may also be displayed by passing the $number parameter.
2426   *
2427   * @since 3.8.0
2428   * @since 4.4.0 Introduced the `echo` parameter.
2429   *
2430   * @param array $args {
2431   *     Optional. Array of star ratings arguments.
2432   *
2433   *     @type int|float $rating The rating to display, expressed in either a 0.5 rating increment,
2434   *                             or percentage. Default 0.
2435   *     @type string    $type   Format that the $rating is in. Valid values are 'rating' (default),
2436   *                             or, 'percent'. Default 'rating'.
2437   *     @type int       $number The number of ratings that makes up this rating. Default 0.
2438   *     @type bool      $echo   Whether to echo the generated markup. False to return the markup instead
2439   *                             of echoing it. Default true.
2440   * }
2441   * @return string Star rating HTML.
2442   */
2443  function wp_star_rating( $args = array() ) {
2444      $defaults = array(
2445          'rating' => 0,
2446          'type'   => 'rating',
2447          'number' => 0,
2448          'echo'   => true,
2449      );
2450      $r        = wp_parse_args( $args, $defaults );
2451  
2452      // Non-English decimal places when the $rating is coming from a string
2453      $rating = (float) str_replace( ',', '.', $r['rating'] );
2454  
2455      // Convert Percentage to star rating, 0..5 in .5 increments
2456      if ( 'percent' === $r['type'] ) {
2457          $rating = round( $rating / 10, 0 ) / 2;
2458      }
2459  
2460      // Calculate the number of each type of star needed
2461      $full_stars  = floor( $rating );
2462      $half_stars  = ceil( $rating - $full_stars );
2463      $empty_stars = 5 - $full_stars - $half_stars;
2464  
2465      if ( $r['number'] ) {
2466          /* translators: 1: the rating, 2: the number of ratings */
2467          $format = _n( '%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $r['number'] );
2468          $title  = sprintf( $format, number_format_i18n( $rating, 1 ), number_format_i18n( $r['number'] ) );
2469      } else {
2470          /* translators: %s: the rating */
2471          $title = sprintf( __( '%s rating' ), number_format_i18n( $rating, 1 ) );
2472      }
2473  
2474      $output  = '<div class="star-rating">';
2475      $output .= '<span class="screen-reader-text">' . $title . '</span>';
2476      $output .= str_repeat( '<div class="star star-full" aria-hidden="true"></div>', $full_stars );
2477      $output .= str_repeat( '<div class="star star-half" aria-hidden="true"></div>', $half_stars );
2478      $output .= str_repeat( '<div class="star star-empty" aria-hidden="true"></div>', $empty_stars );
2479      $output .= '</div>';
2480  
2481      if ( $r['echo'] ) {
2482          echo $output;
2483      }
2484  
2485      return $output;
2486  }
2487  
2488  /**
2489   * Output a notice when editing the page for posts (internal use only).
2490   *
2491   * @ignore
2492   * @since 4.2.0
2493   */
2494  function _wp_posts_page_notice() {
2495      echo '<div class="notice notice-warning inline"><p>' . __( 'You are currently editing the page that shows your latest posts.' ) . '</p></div>';
2496  }


Generated: Fri Jul 19 01:00:04 2019 Cross-referenced by PHPXref 0.7.1