angelovcom.net

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

template.php (94073B)


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