[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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


Generated : Sat Jul 18 08:20:16 2026 Cross-referenced by PHPXref