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


Generated: Fri May 20 01:00:02 2022 Cross-referenced by PHPXref 0.7.1