balmet.com

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

post-template.php (64766B)


      1 <?php
      2 /**
      3  * WordPress Post Template Functions.
      4  *
      5  * Gets content for the current post in the loop.
      6  *
      7  * @package WordPress
      8  * @subpackage Template
      9  */
     10 
     11 /**
     12  * Display the ID of the current item in the WordPress Loop.
     13  *
     14  * @since 0.71
     15  */
     16 function the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
     17 	echo get_the_ID();
     18 }
     19 
     20 /**
     21  * Retrieve the ID of the current item in the WordPress Loop.
     22  *
     23  * @since 2.1.0
     24  *
     25  * @return int|false The ID of the current item in the WordPress Loop. False if $post is not set.
     26  */
     27 function get_the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
     28 	$post = get_post();
     29 	return ! empty( $post ) ? $post->ID : false;
     30 }
     31 
     32 /**
     33  * Display or retrieve the current post title with optional markup.
     34  *
     35  * @since 0.71
     36  *
     37  * @param string $before Optional. Markup to prepend to the title. Default empty.
     38  * @param string $after  Optional. Markup to append to the title. Default empty.
     39  * @param bool   $echo   Optional. Whether to echo or return the title. Default true for echo.
     40  * @return void|string Void if `$echo` argument is true, current post title if `$echo` is false.
     41  */
     42 function the_title( $before = '', $after = '', $echo = true ) {
     43 	$title = get_the_title();
     44 
     45 	if ( strlen( $title ) == 0 ) {
     46 		return;
     47 	}
     48 
     49 	$title = $before . $title . $after;
     50 
     51 	if ( $echo ) {
     52 		echo $title;
     53 	} else {
     54 		return $title;
     55 	}
     56 }
     57 
     58 /**
     59  * Sanitize the current title when retrieving or displaying.
     60  *
     61  * Works like the_title(), except the parameters can be in a string or
     62  * an array. See the function for what can be override in the $args parameter.
     63  *
     64  * The title before it is displayed will have the tags stripped and esc_attr()
     65  * before it is passed to the user or displayed. The default as with the_title(),
     66  * is to display the title.
     67  *
     68  * @since 2.3.0
     69  *
     70  * @param string|array $args {
     71  *     Title attribute arguments. Optional.
     72  *
     73  *     @type string  $before Markup to prepend to the title. Default empty.
     74  *     @type string  $after  Markup to append to the title. Default empty.
     75  *     @type bool    $echo   Whether to echo or return the title. Default true for echo.
     76  *     @type WP_Post $post   Current post object to retrieve the title for.
     77  * }
     78  * @return void|string Void if 'echo' argument is true, the title attribute if 'echo' is false.
     79  */
     80 function the_title_attribute( $args = '' ) {
     81 	$defaults    = array(
     82 		'before' => '',
     83 		'after'  => '',
     84 		'echo'   => true,
     85 		'post'   => get_post(),
     86 	);
     87 	$parsed_args = wp_parse_args( $args, $defaults );
     88 
     89 	$title = get_the_title( $parsed_args['post'] );
     90 
     91 	if ( strlen( $title ) == 0 ) {
     92 		return;
     93 	}
     94 
     95 	$title = $parsed_args['before'] . $title . $parsed_args['after'];
     96 	$title = esc_attr( strip_tags( $title ) );
     97 
     98 	if ( $parsed_args['echo'] ) {
     99 		echo $title;
    100 	} else {
    101 		return $title;
    102 	}
    103 }
    104 
    105 /**
    106  * Retrieve post title.
    107  *
    108  * If the post is protected and the visitor is not an admin, then "Protected"
    109  * will be displayed before the post title. If the post is private, then
    110  * "Private" will be located before the post title.
    111  *
    112  * @since 0.71
    113  *
    114  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
    115  * @return string
    116  */
    117 function get_the_title( $post = 0 ) {
    118 	$post = get_post( $post );
    119 
    120 	$title = isset( $post->post_title ) ? $post->post_title : '';
    121 	$id    = isset( $post->ID ) ? $post->ID : 0;
    122 
    123 	if ( ! is_admin() ) {
    124 		if ( ! empty( $post->post_password ) ) {
    125 
    126 			/* translators: %s: Protected post title. */
    127 			$prepend = __( 'Protected: %s' );
    128 
    129 			/**
    130 			 * Filters the text prepended to the post title for protected posts.
    131 			 *
    132 			 * The filter is only applied on the front end.
    133 			 *
    134 			 * @since 2.8.0
    135 			 *
    136 			 * @param string  $prepend Text displayed before the post title.
    137 			 *                         Default 'Protected: %s'.
    138 			 * @param WP_Post $post    Current post object.
    139 			 */
    140 			$protected_title_format = apply_filters( 'protected_title_format', $prepend, $post );
    141 			$title                  = sprintf( $protected_title_format, $title );
    142 		} elseif ( isset( $post->post_status ) && 'private' === $post->post_status ) {
    143 
    144 			/* translators: %s: Private post title. */
    145 			$prepend = __( 'Private: %s' );
    146 
    147 			/**
    148 			 * Filters the text prepended to the post title of private posts.
    149 			 *
    150 			 * The filter is only applied on the front end.
    151 			 *
    152 			 * @since 2.8.0
    153 			 *
    154 			 * @param string  $prepend Text displayed before the post title.
    155 			 *                         Default 'Private: %s'.
    156 			 * @param WP_Post $post    Current post object.
    157 			 */
    158 			$private_title_format = apply_filters( 'private_title_format', $prepend, $post );
    159 			$title                = sprintf( $private_title_format, $title );
    160 		}
    161 	}
    162 
    163 	/**
    164 	 * Filters the post title.
    165 	 *
    166 	 * @since 0.71
    167 	 *
    168 	 * @param string $title The post title.
    169 	 * @param int    $id    The post ID.
    170 	 */
    171 	return apply_filters( 'the_title', $title, $id );
    172 }
    173 
    174 /**
    175  * Display the Post Global Unique Identifier (guid).
    176  *
    177  * The guid will appear to be a link, but should not be used as a link to the
    178  * post. The reason you should not use it as a link, is because of moving the
    179  * blog across domains.
    180  *
    181  * URL is escaped to make it XML-safe.
    182  *
    183  * @since 1.5.0
    184  *
    185  * @param int|WP_Post $post Optional. Post ID or post object. Default is global $post.
    186  */
    187 function the_guid( $post = 0 ) {
    188 	$post = get_post( $post );
    189 
    190 	$guid = isset( $post->guid ) ? get_the_guid( $post ) : '';
    191 	$id   = isset( $post->ID ) ? $post->ID : 0;
    192 
    193 	/**
    194 	 * Filters the escaped Global Unique Identifier (guid) of the post.
    195 	 *
    196 	 * @since 4.2.0
    197 	 *
    198 	 * @see get_the_guid()
    199 	 *
    200 	 * @param string $guid Escaped Global Unique Identifier (guid) of the post.
    201 	 * @param int    $id   The post ID.
    202 	 */
    203 	echo apply_filters( 'the_guid', $guid, $id );
    204 }
    205 
    206 /**
    207  * Retrieve the Post Global Unique Identifier (guid).
    208  *
    209  * The guid will appear to be a link, but should not be used as an link to the
    210  * post. The reason you should not use it as a link, is because of moving the
    211  * blog across domains.
    212  *
    213  * @since 1.5.0
    214  *
    215  * @param int|WP_Post $post Optional. Post ID or post object. Default is global $post.
    216  * @return string
    217  */
    218 function get_the_guid( $post = 0 ) {
    219 	$post = get_post( $post );
    220 
    221 	$guid = isset( $post->guid ) ? $post->guid : '';
    222 	$id   = isset( $post->ID ) ? $post->ID : 0;
    223 
    224 	/**
    225 	 * Filters the Global Unique Identifier (guid) of the post.
    226 	 *
    227 	 * @since 1.5.0
    228 	 *
    229 	 * @param string $guid Global Unique Identifier (guid) of the post.
    230 	 * @param int    $id   The post ID.
    231 	 */
    232 	return apply_filters( 'get_the_guid', $guid, $id );
    233 }
    234 
    235 /**
    236  * Display the post content.
    237  *
    238  * @since 0.71
    239  *
    240  * @param string $more_link_text Optional. Content for when there is more text.
    241  * @param bool   $strip_teaser   Optional. Strip teaser content before the more text. Default false.
    242  */
    243 function the_content( $more_link_text = null, $strip_teaser = false ) {
    244 	$content = get_the_content( $more_link_text, $strip_teaser );
    245 
    246 	/**
    247 	 * Filters the post content.
    248 	 *
    249 	 * @since 0.71
    250 	 *
    251 	 * @param string $content Content of the current post.
    252 	 */
    253 	$content = apply_filters( 'the_content', $content );
    254 	$content = str_replace( ']]>', ']]&gt;', $content );
    255 	echo $content;
    256 }
    257 
    258 /**
    259  * Retrieve the post content.
    260  *
    261  * @since 0.71
    262  * @since 5.2.0 Added the `$post` parameter.
    263  *
    264  * @global int   $page      Page number of a single post/page.
    265  * @global int   $more      Boolean indicator for whether single post/page is being viewed.
    266  * @global bool  $preview   Whether post/page is in preview mode.
    267  * @global array $pages     Array of all pages in post/page. Each array element contains
    268  *                          part of the content separated by the `<!--nextpage-->` tag.
    269  * @global int   $multipage Boolean indicator for whether multiple pages are in play.
    270  *
    271  * @param string             $more_link_text Optional. Content for when there is more text.
    272  * @param bool               $strip_teaser   Optional. Strip teaser content before the more text. Default false.
    273  * @param WP_Post|object|int $post           Optional. WP_Post instance or Post ID/object. Default null.
    274  * @return string
    275  */
    276 function get_the_content( $more_link_text = null, $strip_teaser = false, $post = null ) {
    277 	global $page, $more, $preview, $pages, $multipage;
    278 
    279 	$_post = get_post( $post );
    280 
    281 	if ( ! ( $_post instanceof WP_Post ) ) {
    282 		return '';
    283 	}
    284 
    285 	// Use the globals if the $post parameter was not specified,
    286 	// but only after they have been set up in setup_postdata().
    287 	if ( null === $post && did_action( 'the_post' ) ) {
    288 		$elements = compact( 'page', 'more', 'preview', 'pages', 'multipage' );
    289 	} else {
    290 		$elements = generate_postdata( $_post );
    291 	}
    292 
    293 	if ( null === $more_link_text ) {
    294 		$more_link_text = sprintf(
    295 			'<span aria-label="%1$s">%2$s</span>',
    296 			sprintf(
    297 				/* translators: %s: Post title. */
    298 				__( 'Continue reading %s' ),
    299 				the_title_attribute(
    300 					array(
    301 						'echo' => false,
    302 						'post' => $_post,
    303 					)
    304 				)
    305 			),
    306 			__( '(more&hellip;)' )
    307 		);
    308 	}
    309 
    310 	$output     = '';
    311 	$has_teaser = false;
    312 
    313 	// If post password required and it doesn't match the cookie.
    314 	if ( post_password_required( $_post ) ) {
    315 		return get_the_password_form( $_post );
    316 	}
    317 
    318 	// If the requested page doesn't exist.
    319 	if ( $elements['page'] > count( $elements['pages'] ) ) {
    320 		// Give them the highest numbered page that DOES exist.
    321 		$elements['page'] = count( $elements['pages'] );
    322 	}
    323 
    324 	$page_no = $elements['page'];
    325 	$content = $elements['pages'][ $page_no - 1 ];
    326 	if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
    327 		if ( has_block( 'more', $content ) ) {
    328 			// Remove the core/more block delimiters. They will be left over after $content is split up.
    329 			$content = preg_replace( '/<!-- \/?wp:more(.*?) -->/', '', $content );
    330 		}
    331 
    332 		$content = explode( $matches[0], $content, 2 );
    333 
    334 		if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) {
    335 			$more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
    336 		}
    337 
    338 		$has_teaser = true;
    339 	} else {
    340 		$content = array( $content );
    341 	}
    342 
    343 	if ( false !== strpos( $_post->post_content, '<!--noteaser-->' ) && ( ! $elements['multipage'] || 1 == $elements['page'] ) ) {
    344 		$strip_teaser = true;
    345 	}
    346 
    347 	$teaser = $content[0];
    348 
    349 	if ( $elements['more'] && $strip_teaser && $has_teaser ) {
    350 		$teaser = '';
    351 	}
    352 
    353 	$output .= $teaser;
    354 
    355 	if ( count( $content ) > 1 ) {
    356 		if ( $elements['more'] ) {
    357 			$output .= '<span id="more-' . $_post->ID . '"></span>' . $content[1];
    358 		} else {
    359 			if ( ! empty( $more_link_text ) ) {
    360 
    361 				/**
    362 				 * Filters the Read More link text.
    363 				 *
    364 				 * @since 2.8.0
    365 				 *
    366 				 * @param string $more_link_element Read More link element.
    367 				 * @param string $more_link_text    Read More text.
    368 				 */
    369 				$output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink( $_post ) . "#more-{$_post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
    370 			}
    371 			$output = force_balance_tags( $output );
    372 		}
    373 	}
    374 
    375 	return $output;
    376 }
    377 
    378 /**
    379  * Display the post excerpt.
    380  *
    381  * @since 0.71
    382  */
    383 function the_excerpt() {
    384 
    385 	/**
    386 	 * Filters the displayed post excerpt.
    387 	 *
    388 	 * @since 0.71
    389 	 *
    390 	 * @see get_the_excerpt()
    391 	 *
    392 	 * @param string $post_excerpt The post excerpt.
    393 	 */
    394 	echo apply_filters( 'the_excerpt', get_the_excerpt() );
    395 }
    396 
    397 /**
    398  * Retrieves the post excerpt.
    399  *
    400  * @since 0.71
    401  * @since 4.5.0 Introduced the `$post` parameter.
    402  *
    403  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
    404  * @return string Post excerpt.
    405  */
    406 function get_the_excerpt( $post = null ) {
    407 	if ( is_bool( $post ) ) {
    408 		_deprecated_argument( __FUNCTION__, '2.3.0' );
    409 	}
    410 
    411 	$post = get_post( $post );
    412 	if ( empty( $post ) ) {
    413 		return '';
    414 	}
    415 
    416 	if ( post_password_required( $post ) ) {
    417 		return __( 'There is no excerpt because this is a protected post.' );
    418 	}
    419 
    420 	/**
    421 	 * Filters the retrieved post excerpt.
    422 	 *
    423 	 * @since 1.2.0
    424 	 * @since 4.5.0 Introduced the `$post` parameter.
    425 	 *
    426 	 * @param string  $post_excerpt The post excerpt.
    427 	 * @param WP_Post $post         Post object.
    428 	 */
    429 	return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );
    430 }
    431 
    432 /**
    433  * Determines whether the post has a custom excerpt.
    434  *
    435  * For more information on this and similar theme functions, check out
    436  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
    437  * Conditional Tags} article in the Theme Developer Handbook.
    438  *
    439  * @since 2.3.0
    440  *
    441  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
    442  * @return bool True if the post has a custom excerpt, false otherwise.
    443  */
    444 function has_excerpt( $post = 0 ) {
    445 	$post = get_post( $post );
    446 	return ( ! empty( $post->post_excerpt ) );
    447 }
    448 
    449 /**
    450  * Displays the classes for the post container element.
    451  *
    452  * @since 2.7.0
    453  *
    454  * @param string|string[] $class   One or more classes to add to the class list.
    455  * @param int|WP_Post     $post_id Optional. Post ID or post object. Defaults to the global `$post`.
    456  */
    457 function post_class( $class = '', $post_id = null ) {
    458 	// Separates classes with a single space, collates classes for post DIV.
    459 	echo 'class="' . esc_attr( implode( ' ', get_post_class( $class, $post_id ) ) ) . '"';
    460 }
    461 
    462 /**
    463  * Retrieves an array of the class names for the post container element.
    464  *
    465  * The class names are many. If the post is a sticky, then the 'sticky'
    466  * class name. The class 'hentry' is always added to each post. If the post has a
    467  * post thumbnail, 'has-post-thumbnail' is added as a class. For each taxonomy that
    468  * the post belongs to, a class will be added of the format '{$taxonomy}-{$slug}' -
    469  * eg 'category-foo' or 'my_custom_taxonomy-bar'.
    470  *
    471  * The 'post_tag' taxonomy is a special
    472  * case; the class has the 'tag-' prefix instead of 'post_tag-'. All class names are
    473  * passed through the filter, {@see 'post_class'}, with the list of class names, followed by
    474  * $class parameter value, with the post ID as the last parameter.
    475  *
    476  * @since 2.7.0
    477  * @since 4.2.0 Custom taxonomy class names were added.
    478  *
    479  * @param string|string[] $class   Space-separated string or array of class names to add to the class list.
    480  * @param int|WP_Post     $post_id Optional. Post ID or post object.
    481  * @return string[] Array of class names.
    482  */
    483 function get_post_class( $class = '', $post_id = null ) {
    484 	$post = get_post( $post_id );
    485 
    486 	$classes = array();
    487 
    488 	if ( $class ) {
    489 		if ( ! is_array( $class ) ) {
    490 			$class = preg_split( '#\s+#', $class );
    491 		}
    492 		$classes = array_map( 'esc_attr', $class );
    493 	} else {
    494 		// Ensure that we always coerce class to being an array.
    495 		$class = array();
    496 	}
    497 
    498 	if ( ! $post ) {
    499 		return $classes;
    500 	}
    501 
    502 	$classes[] = 'post-' . $post->ID;
    503 	if ( ! is_admin() ) {
    504 		$classes[] = $post->post_type;
    505 	}
    506 	$classes[] = 'type-' . $post->post_type;
    507 	$classes[] = 'status-' . $post->post_status;
    508 
    509 	// Post Format.
    510 	if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
    511 		$post_format = get_post_format( $post->ID );
    512 
    513 		if ( $post_format && ! is_wp_error( $post_format ) ) {
    514 			$classes[] = 'format-' . sanitize_html_class( $post_format );
    515 		} else {
    516 			$classes[] = 'format-standard';
    517 		}
    518 	}
    519 
    520 	$post_password_required = post_password_required( $post->ID );
    521 
    522 	// Post requires password.
    523 	if ( $post_password_required ) {
    524 		$classes[] = 'post-password-required';
    525 	} elseif ( ! empty( $post->post_password ) ) {
    526 		$classes[] = 'post-password-protected';
    527 	}
    528 
    529 	// Post thumbnails.
    530 	if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) && ! is_attachment( $post ) && ! $post_password_required ) {
    531 		$classes[] = 'has-post-thumbnail';
    532 	}
    533 
    534 	// Sticky for Sticky Posts.
    535 	if ( is_sticky( $post->ID ) ) {
    536 		if ( is_home() && ! is_paged() ) {
    537 			$classes[] = 'sticky';
    538 		} elseif ( is_admin() ) {
    539 			$classes[] = 'status-sticky';
    540 		}
    541 	}
    542 
    543 	// hentry for hAtom compliance.
    544 	$classes[] = 'hentry';
    545 
    546 	// All public taxonomies.
    547 	$taxonomies = get_taxonomies( array( 'public' => true ) );
    548 	foreach ( (array) $taxonomies as $taxonomy ) {
    549 		if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) {
    550 			foreach ( (array) get_the_terms( $post->ID, $taxonomy ) as $term ) {
    551 				if ( empty( $term->slug ) ) {
    552 					continue;
    553 				}
    554 
    555 				$term_class = sanitize_html_class( $term->slug, $term->term_id );
    556 				if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) {
    557 					$term_class = $term->term_id;
    558 				}
    559 
    560 				// 'post_tag' uses the 'tag' prefix for backward compatibility.
    561 				if ( 'post_tag' === $taxonomy ) {
    562 					$classes[] = 'tag-' . $term_class;
    563 				} else {
    564 					$classes[] = sanitize_html_class( $taxonomy . '-' . $term_class, $taxonomy . '-' . $term->term_id );
    565 				}
    566 			}
    567 		}
    568 	}
    569 
    570 	$classes = array_map( 'esc_attr', $classes );
    571 
    572 	/**
    573 	 * Filters the list of CSS class names for the current post.
    574 	 *
    575 	 * @since 2.7.0
    576 	 *
    577 	 * @param string[] $classes An array of post class names.
    578 	 * @param string[] $class   An array of additional class names added to the post.
    579 	 * @param int      $post_id The post ID.
    580 	 */
    581 	$classes = apply_filters( 'post_class', $classes, $class, $post->ID );
    582 
    583 	return array_unique( $classes );
    584 }
    585 
    586 /**
    587  * Displays the class names for the body element.
    588  *
    589  * @since 2.8.0
    590  *
    591  * @param string|string[] $class Space-separated string or array of class names to add to the class list.
    592  */
    593 function body_class( $class = '' ) {
    594 	// Separates class names with a single space, collates class names for body element.
    595 	echo 'class="' . esc_attr( implode( ' ', get_body_class( $class ) ) ) . '"';
    596 }
    597 
    598 /**
    599  * Retrieves an array of the class names for the body element.
    600  *
    601  * @since 2.8.0
    602  *
    603  * @global WP_Query $wp_query WordPress Query object.
    604  *
    605  * @param string|string[] $class Space-separated string or array of class names to add to the class list.
    606  * @return string[] Array of class names.
    607  */
    608 function get_body_class( $class = '' ) {
    609 	global $wp_query;
    610 
    611 	$classes = array();
    612 
    613 	if ( is_rtl() ) {
    614 		$classes[] = 'rtl';
    615 	}
    616 
    617 	if ( is_front_page() ) {
    618 		$classes[] = 'home';
    619 	}
    620 	if ( is_home() ) {
    621 		$classes[] = 'blog';
    622 	}
    623 	if ( is_privacy_policy() ) {
    624 		$classes[] = 'privacy-policy';
    625 	}
    626 	if ( is_archive() ) {
    627 		$classes[] = 'archive';
    628 	}
    629 	if ( is_date() ) {
    630 		$classes[] = 'date';
    631 	}
    632 	if ( is_search() ) {
    633 		$classes[] = 'search';
    634 		$classes[] = $wp_query->posts ? 'search-results' : 'search-no-results';
    635 	}
    636 	if ( is_paged() ) {
    637 		$classes[] = 'paged';
    638 	}
    639 	if ( is_attachment() ) {
    640 		$classes[] = 'attachment';
    641 	}
    642 	if ( is_404() ) {
    643 		$classes[] = 'error404';
    644 	}
    645 
    646 	if ( is_singular() ) {
    647 		$post_id   = $wp_query->get_queried_object_id();
    648 		$post      = $wp_query->get_queried_object();
    649 		$post_type = $post->post_type;
    650 
    651 		if ( is_page_template() ) {
    652 			$classes[] = "{$post_type}-template";
    653 
    654 			$template_slug  = get_page_template_slug( $post_id );
    655 			$template_parts = explode( '/', $template_slug );
    656 
    657 			foreach ( $template_parts as $part ) {
    658 				$classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) );
    659 			}
    660 			$classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( '.', '-', $template_slug ) );
    661 		} else {
    662 			$classes[] = "{$post_type}-template-default";
    663 		}
    664 
    665 		if ( is_single() ) {
    666 			$classes[] = 'single';
    667 			if ( isset( $post->post_type ) ) {
    668 				$classes[] = 'single-' . sanitize_html_class( $post->post_type, $post_id );
    669 				$classes[] = 'postid-' . $post_id;
    670 
    671 				// Post Format.
    672 				if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
    673 					$post_format = get_post_format( $post->ID );
    674 
    675 					if ( $post_format && ! is_wp_error( $post_format ) ) {
    676 						$classes[] = 'single-format-' . sanitize_html_class( $post_format );
    677 					} else {
    678 						$classes[] = 'single-format-standard';
    679 					}
    680 				}
    681 			}
    682 		}
    683 
    684 		if ( is_attachment() ) {
    685 			$mime_type   = get_post_mime_type( $post_id );
    686 			$mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
    687 			$classes[]   = 'attachmentid-' . $post_id;
    688 			$classes[]   = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );
    689 		} elseif ( is_page() ) {
    690 			$classes[] = 'page';
    691 
    692 			$page_id = $wp_query->get_queried_object_id();
    693 
    694 			$post = get_post( $page_id );
    695 
    696 			$classes[] = 'page-id-' . $page_id;
    697 
    698 			if ( get_pages(
    699 				array(
    700 					'parent' => $page_id,
    701 					'number' => 1,
    702 				)
    703 			) ) {
    704 				$classes[] = 'page-parent';
    705 			}
    706 
    707 			if ( $post->post_parent ) {
    708 				$classes[] = 'page-child';
    709 				$classes[] = 'parent-pageid-' . $post->post_parent;
    710 			}
    711 		}
    712 	} elseif ( is_archive() ) {
    713 		if ( is_post_type_archive() ) {
    714 			$classes[] = 'post-type-archive';
    715 			$post_type = get_query_var( 'post_type' );
    716 			if ( is_array( $post_type ) ) {
    717 				$post_type = reset( $post_type );
    718 			}
    719 			$classes[] = 'post-type-archive-' . sanitize_html_class( $post_type );
    720 		} elseif ( is_author() ) {
    721 			$author    = $wp_query->get_queried_object();
    722 			$classes[] = 'author';
    723 			if ( isset( $author->user_nicename ) ) {
    724 				$classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID );
    725 				$classes[] = 'author-' . $author->ID;
    726 			}
    727 		} elseif ( is_category() ) {
    728 			$cat       = $wp_query->get_queried_object();
    729 			$classes[] = 'category';
    730 			if ( isset( $cat->term_id ) ) {
    731 				$cat_class = sanitize_html_class( $cat->slug, $cat->term_id );
    732 				if ( is_numeric( $cat_class ) || ! trim( $cat_class, '-' ) ) {
    733 					$cat_class = $cat->term_id;
    734 				}
    735 
    736 				$classes[] = 'category-' . $cat_class;
    737 				$classes[] = 'category-' . $cat->term_id;
    738 			}
    739 		} elseif ( is_tag() ) {
    740 			$tag       = $wp_query->get_queried_object();
    741 			$classes[] = 'tag';
    742 			if ( isset( $tag->term_id ) ) {
    743 				$tag_class = sanitize_html_class( $tag->slug, $tag->term_id );
    744 				if ( is_numeric( $tag_class ) || ! trim( $tag_class, '-' ) ) {
    745 					$tag_class = $tag->term_id;
    746 				}
    747 
    748 				$classes[] = 'tag-' . $tag_class;
    749 				$classes[] = 'tag-' . $tag->term_id;
    750 			}
    751 		} elseif ( is_tax() ) {
    752 			$term = $wp_query->get_queried_object();
    753 			if ( isset( $term->term_id ) ) {
    754 				$term_class = sanitize_html_class( $term->slug, $term->term_id );
    755 				if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) {
    756 					$term_class = $term->term_id;
    757 				}
    758 
    759 				$classes[] = 'tax-' . sanitize_html_class( $term->taxonomy );
    760 				$classes[] = 'term-' . $term_class;
    761 				$classes[] = 'term-' . $term->term_id;
    762 			}
    763 		}
    764 	}
    765 
    766 	if ( is_user_logged_in() ) {
    767 		$classes[] = 'logged-in';
    768 	}
    769 
    770 	if ( is_admin_bar_showing() ) {
    771 		$classes[] = 'admin-bar';
    772 		$classes[] = 'no-customize-support';
    773 	}
    774 
    775 	if ( current_theme_supports( 'custom-background' )
    776 		&& ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() ) ) {
    777 		$classes[] = 'custom-background';
    778 	}
    779 
    780 	if ( has_custom_logo() ) {
    781 		$classes[] = 'wp-custom-logo';
    782 	}
    783 
    784 	if ( current_theme_supports( 'responsive-embeds' ) ) {
    785 		$classes[] = 'wp-embed-responsive';
    786 	}
    787 
    788 	$page = $wp_query->get( 'page' );
    789 
    790 	if ( ! $page || $page < 2 ) {
    791 		$page = $wp_query->get( 'paged' );
    792 	}
    793 
    794 	if ( $page && $page > 1 && ! is_404() ) {
    795 		$classes[] = 'paged-' . $page;
    796 
    797 		if ( is_single() ) {
    798 			$classes[] = 'single-paged-' . $page;
    799 		} elseif ( is_page() ) {
    800 			$classes[] = 'page-paged-' . $page;
    801 		} elseif ( is_category() ) {
    802 			$classes[] = 'category-paged-' . $page;
    803 		} elseif ( is_tag() ) {
    804 			$classes[] = 'tag-paged-' . $page;
    805 		} elseif ( is_date() ) {
    806 			$classes[] = 'date-paged-' . $page;
    807 		} elseif ( is_author() ) {
    808 			$classes[] = 'author-paged-' . $page;
    809 		} elseif ( is_search() ) {
    810 			$classes[] = 'search-paged-' . $page;
    811 		} elseif ( is_post_type_archive() ) {
    812 			$classes[] = 'post-type-paged-' . $page;
    813 		}
    814 	}
    815 
    816 	if ( ! empty( $class ) ) {
    817 		if ( ! is_array( $class ) ) {
    818 			$class = preg_split( '#\s+#', $class );
    819 		}
    820 		$classes = array_merge( $classes, $class );
    821 	} else {
    822 		// Ensure that we always coerce class to being an array.
    823 		$class = array();
    824 	}
    825 
    826 	$classes = array_map( 'esc_attr', $classes );
    827 
    828 	/**
    829 	 * Filters the list of CSS body class names for the current post or page.
    830 	 *
    831 	 * @since 2.8.0
    832 	 *
    833 	 * @param string[] $classes An array of body class names.
    834 	 * @param string[] $class   An array of additional class names added to the body.
    835 	 */
    836 	$classes = apply_filters( 'body_class', $classes, $class );
    837 
    838 	return array_unique( $classes );
    839 }
    840 
    841 /**
    842  * Whether post requires password and correct password has been provided.
    843  *
    844  * @since 2.7.0
    845  *
    846  * @param int|WP_Post|null $post An optional post. Global $post used if not provided.
    847  * @return bool false if a password is not required or the correct password cookie is present, true otherwise.
    848  */
    849 function post_password_required( $post = null ) {
    850 	$post = get_post( $post );
    851 
    852 	if ( empty( $post->post_password ) ) {
    853 		/** This filter is documented in wp-includes/post-template.php */
    854 		return apply_filters( 'post_password_required', false, $post );
    855 	}
    856 
    857 	if ( ! isset( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ) ) {
    858 		/** This filter is documented in wp-includes/post-template.php */
    859 		return apply_filters( 'post_password_required', true, $post );
    860 	}
    861 
    862 	require_once ABSPATH . WPINC . '/class-phpass.php';
    863 	$hasher = new PasswordHash( 8, true );
    864 
    865 	$hash = wp_unslash( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] );
    866 	if ( 0 !== strpos( $hash, '$P$B' ) ) {
    867 		$required = true;
    868 	} else {
    869 		$required = ! $hasher->CheckPassword( $post->post_password, $hash );
    870 	}
    871 
    872 	/**
    873 	 * Filters whether a post requires the user to supply a password.
    874 	 *
    875 	 * @since 4.7.0
    876 	 *
    877 	 * @param bool    $required Whether the user needs to supply a password. True if password has not been
    878 	 *                          provided or is incorrect, false if password has been supplied or is not required.
    879 	 * @param WP_Post $post     Post object.
    880 	 */
    881 	return apply_filters( 'post_password_required', $required, $post );
    882 }
    883 
    884 //
    885 // Page Template Functions for usage in Themes.
    886 //
    887 
    888 /**
    889  * The formatted output of a list of pages.
    890  *
    891  * Displays page links for paginated posts (i.e. including the `<!--nextpage-->`
    892  * Quicktag one or more times). This tag must be within The Loop.
    893  *
    894  * @since 1.2.0
    895  * @since 5.1.0 Added the `aria_current` argument.
    896  *
    897  * @global int $page
    898  * @global int $numpages
    899  * @global int $multipage
    900  * @global int $more
    901  *
    902  * @param string|array $args {
    903  *     Optional. Array or string of default arguments.
    904  *
    905  *     @type string       $before           HTML or text to prepend to each link. Default is `<p> Pages:`.
    906  *     @type string       $after            HTML or text to append to each link. Default is `</p>`.
    907  *     @type string       $link_before      HTML or text to prepend to each link, inside the `<a>` tag.
    908  *                                          Also prepended to the current item, which is not linked. Default empty.
    909  *     @type string       $link_after       HTML or text to append to each Pages link inside the `<a>` tag.
    910  *                                          Also appended to the current item, which is not linked. Default empty.
    911  *     @type string       $aria_current     The value for the aria-current attribute. Possible values are 'page',
    912  *                                          'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'.
    913  *     @type string       $next_or_number   Indicates whether page numbers should be used. Valid values are number
    914  *                                          and next. Default is 'number'.
    915  *     @type string       $separator        Text between pagination links. Default is ' '.
    916  *     @type string       $nextpagelink     Link text for the next page link, if available. Default is 'Next Page'.
    917  *     @type string       $previouspagelink Link text for the previous page link, if available. Default is 'Previous Page'.
    918  *     @type string       $pagelink         Format string for page numbers. The % in the parameter string will be
    919  *                                          replaced with the page number, so 'Page %' generates "Page 1", "Page 2", etc.
    920  *                                          Defaults to '%', just the page number.
    921  *     @type int|bool     $echo             Whether to echo or not. Accepts 1|true or 0|false. Default 1|true.
    922  * }
    923  * @return string Formatted output in HTML.
    924  */
    925 function wp_link_pages( $args = '' ) {
    926 	global $page, $numpages, $multipage, $more;
    927 
    928 	$defaults = array(
    929 		'before'           => '<p class="post-nav-links">' . __( 'Pages:' ),
    930 		'after'            => '</p>',
    931 		'link_before'      => '',
    932 		'link_after'       => '',
    933 		'aria_current'     => 'page',
    934 		'next_or_number'   => 'number',
    935 		'separator'        => ' ',
    936 		'nextpagelink'     => __( 'Next page' ),
    937 		'previouspagelink' => __( 'Previous page' ),
    938 		'pagelink'         => '%',
    939 		'echo'             => 1,
    940 	);
    941 
    942 	$parsed_args = wp_parse_args( $args, $defaults );
    943 
    944 	/**
    945 	 * Filters the arguments used in retrieving page links for paginated posts.
    946 	 *
    947 	 * @since 3.0.0
    948 	 *
    949 	 * @param array $parsed_args An array of page link arguments. See wp_link_pages()
    950 	 *                           for information on accepted arguments.
    951 	 */
    952 	$parsed_args = apply_filters( 'wp_link_pages_args', $parsed_args );
    953 
    954 	$output = '';
    955 	if ( $multipage ) {
    956 		if ( 'number' === $parsed_args['next_or_number'] ) {
    957 			$output .= $parsed_args['before'];
    958 			for ( $i = 1; $i <= $numpages; $i++ ) {
    959 				$link = $parsed_args['link_before'] . str_replace( '%', $i, $parsed_args['pagelink'] ) . $parsed_args['link_after'];
    960 				if ( $i != $page || ! $more && 1 == $page ) {
    961 					$link = _wp_link_page( $i ) . $link . '</a>';
    962 				} elseif ( $i === $page ) {
    963 					$link = '<span class="post-page-numbers current" aria-current="' . esc_attr( $parsed_args['aria_current'] ) . '">' . $link . '</span>';
    964 				}
    965 				/**
    966 				 * Filters the HTML output of individual page number links.
    967 				 *
    968 				 * @since 3.6.0
    969 				 *
    970 				 * @param string $link The page number HTML output.
    971 				 * @param int    $i    Page number for paginated posts' page links.
    972 				 */
    973 				$link = apply_filters( 'wp_link_pages_link', $link, $i );
    974 
    975 				// Use the custom links separator beginning with the second link.
    976 				$output .= ( 1 === $i ) ? ' ' : $parsed_args['separator'];
    977 				$output .= $link;
    978 			}
    979 			$output .= $parsed_args['after'];
    980 		} elseif ( $more ) {
    981 			$output .= $parsed_args['before'];
    982 			$prev    = $page - 1;
    983 			if ( $prev > 0 ) {
    984 				$link = _wp_link_page( $prev ) . $parsed_args['link_before'] . $parsed_args['previouspagelink'] . $parsed_args['link_after'] . '</a>';
    985 
    986 				/** This filter is documented in wp-includes/post-template.php */
    987 				$output .= apply_filters( 'wp_link_pages_link', $link, $prev );
    988 			}
    989 			$next = $page + 1;
    990 			if ( $next <= $numpages ) {
    991 				if ( $prev ) {
    992 					$output .= $parsed_args['separator'];
    993 				}
    994 				$link = _wp_link_page( $next ) . $parsed_args['link_before'] . $parsed_args['nextpagelink'] . $parsed_args['link_after'] . '</a>';
    995 
    996 				/** This filter is documented in wp-includes/post-template.php */
    997 				$output .= apply_filters( 'wp_link_pages_link', $link, $next );
    998 			}
    999 			$output .= $parsed_args['after'];
   1000 		}
   1001 	}
   1002 
   1003 	/**
   1004 	 * Filters the HTML output of page links for paginated posts.
   1005 	 *
   1006 	 * @since 3.6.0
   1007 	 *
   1008 	 * @param string $output HTML output of paginated posts' page links.
   1009 	 * @param array  $args   An array of arguments. See wp_link_pages()
   1010 	 *                       for information on accepted arguments.
   1011 	 */
   1012 	$html = apply_filters( 'wp_link_pages', $output, $args );
   1013 
   1014 	if ( $parsed_args['echo'] ) {
   1015 		echo $html;
   1016 	}
   1017 	return $html;
   1018 }
   1019 
   1020 /**
   1021  * Helper function for wp_link_pages().
   1022  *
   1023  * @since 3.1.0
   1024  * @access private
   1025  *
   1026  * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
   1027  *
   1028  * @param int $i Page number.
   1029  * @return string Link.
   1030  */
   1031 function _wp_link_page( $i ) {
   1032 	global $wp_rewrite;
   1033 	$post       = get_post();
   1034 	$query_args = array();
   1035 
   1036 	if ( 1 == $i ) {
   1037 		$url = get_permalink();
   1038 	} else {
   1039 		if ( ! get_option( 'permalink_structure' ) || in_array( $post->post_status, array( 'draft', 'pending' ), true ) ) {
   1040 			$url = add_query_arg( 'page', $i, get_permalink() );
   1041 		} elseif ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) {
   1042 			$url = trailingslashit( get_permalink() ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $i, 'single_paged' );
   1043 		} else {
   1044 			$url = trailingslashit( get_permalink() ) . user_trailingslashit( $i, 'single_paged' );
   1045 		}
   1046 	}
   1047 
   1048 	if ( is_preview() ) {
   1049 
   1050 		if ( ( 'draft' !== $post->post_status ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) {
   1051 			$query_args['preview_id']    = wp_unslash( $_GET['preview_id'] );
   1052 			$query_args['preview_nonce'] = wp_unslash( $_GET['preview_nonce'] );
   1053 		}
   1054 
   1055 		$url = get_preview_post_link( $post, $query_args, $url );
   1056 	}
   1057 
   1058 	return '<a href="' . esc_url( $url ) . '" class="post-page-numbers">';
   1059 }
   1060 
   1061 //
   1062 // Post-meta: Custom per-post fields.
   1063 //
   1064 
   1065 /**
   1066  * Retrieve post custom meta data field.
   1067  *
   1068  * @since 1.5.0
   1069  *
   1070  * @param string $key Meta data key name.
   1071  * @return array|string|false Array of values, or single value if only one element exists.
   1072  *                            False if the key does not exist.
   1073  */
   1074 function post_custom( $key = '' ) {
   1075 	$custom = get_post_custom();
   1076 
   1077 	if ( ! isset( $custom[ $key ] ) ) {
   1078 		return false;
   1079 	} elseif ( 1 === count( $custom[ $key ] ) ) {
   1080 		return $custom[ $key ][0];
   1081 	} else {
   1082 		return $custom[ $key ];
   1083 	}
   1084 }
   1085 
   1086 /**
   1087  * Display a list of post custom fields.
   1088  *
   1089  * @since 1.2.0
   1090  *
   1091  * @internal This will probably change at some point...
   1092  */
   1093 function the_meta() {
   1094 	$keys = get_post_custom_keys();
   1095 	if ( $keys ) {
   1096 		$li_html = '';
   1097 		foreach ( (array) $keys as $key ) {
   1098 			$keyt = trim( $key );
   1099 			if ( is_protected_meta( $keyt, 'post' ) ) {
   1100 				continue;
   1101 			}
   1102 
   1103 			$values = array_map( 'trim', get_post_custom_values( $key ) );
   1104 			$value  = implode( ', ', $values );
   1105 
   1106 			$html = sprintf(
   1107 				"<li><span class='post-meta-key'>%s</span> %s</li>\n",
   1108 				/* translators: %s: Post custom field name. */
   1109 				sprintf( _x( '%s:', 'Post custom field name' ), $key ),
   1110 				$value
   1111 			);
   1112 
   1113 			/**
   1114 			 * Filters the HTML output of the li element in the post custom fields list.
   1115 			 *
   1116 			 * @since 2.2.0
   1117 			 *
   1118 			 * @param string $html  The HTML output for the li element.
   1119 			 * @param string $key   Meta key.
   1120 			 * @param string $value Meta value.
   1121 			 */
   1122 			$li_html .= apply_filters( 'the_meta_key', $html, $key, $value );
   1123 		}
   1124 
   1125 		if ( $li_html ) {
   1126 			echo "<ul class='post-meta'>\n{$li_html}</ul>\n";
   1127 		}
   1128 	}
   1129 }
   1130 
   1131 //
   1132 // Pages.
   1133 //
   1134 
   1135 /**
   1136  * Retrieve or display a list of pages as a dropdown (select list).
   1137  *
   1138  * @since 2.1.0
   1139  * @since 4.2.0 The `$value_field` argument was added.
   1140  * @since 4.3.0 The `$class` argument was added.
   1141  *
   1142  * @see get_pages()
   1143  *
   1144  * @param array|string $args {
   1145  *     Optional. Array or string of arguments to generate a page dropdown. See `get_pages()` for additional arguments.
   1146  *
   1147  *     @type int          $depth                 Maximum depth. Default 0.
   1148  *     @type int          $child_of              Page ID to retrieve child pages of. Default 0.
   1149  *     @type int|string   $selected              Value of the option that should be selected. Default 0.
   1150  *     @type bool|int     $echo                  Whether to echo or return the generated markup. Accepts 0, 1,
   1151  *                                               or their bool equivalents. Default 1.
   1152  *     @type string       $name                  Value for the 'name' attribute of the select element.
   1153  *                                               Default 'page_id'.
   1154  *     @type string       $id                    Value for the 'id' attribute of the select element.
   1155  *     @type string       $class                 Value for the 'class' attribute of the select element. Default: none.
   1156  *                                               Defaults to the value of `$name`.
   1157  *     @type string       $show_option_none      Text to display for showing no pages. Default empty (does not display).
   1158  *     @type string       $show_option_no_change Text to display for "no change" option. Default empty (does not display).
   1159  *     @type string       $option_none_value     Value to use when no page is selected. Default empty.
   1160  *     @type string       $value_field           Post field used to populate the 'value' attribute of the option
   1161  *                                               elements. Accepts any valid post field. Default 'ID'.
   1162  * }
   1163  * @return string HTML dropdown list of pages.
   1164  */
   1165 function wp_dropdown_pages( $args = '' ) {
   1166 	$defaults = array(
   1167 		'depth'                 => 0,
   1168 		'child_of'              => 0,
   1169 		'selected'              => 0,
   1170 		'echo'                  => 1,
   1171 		'name'                  => 'page_id',
   1172 		'id'                    => '',
   1173 		'class'                 => '',
   1174 		'show_option_none'      => '',
   1175 		'show_option_no_change' => '',
   1176 		'option_none_value'     => '',
   1177 		'value_field'           => 'ID',
   1178 	);
   1179 
   1180 	$parsed_args = wp_parse_args( $args, $defaults );
   1181 
   1182 	$pages  = get_pages( $parsed_args );
   1183 	$output = '';
   1184 	// Back-compat with old system where both id and name were based on $name argument.
   1185 	if ( empty( $parsed_args['id'] ) ) {
   1186 		$parsed_args['id'] = $parsed_args['name'];
   1187 	}
   1188 
   1189 	if ( ! empty( $pages ) ) {
   1190 		$class = '';
   1191 		if ( ! empty( $parsed_args['class'] ) ) {
   1192 			$class = " class='" . esc_attr( $parsed_args['class'] ) . "'";
   1193 		}
   1194 
   1195 		$output = "<select name='" . esc_attr( $parsed_args['name'] ) . "'" . $class . " id='" . esc_attr( $parsed_args['id'] ) . "'>\n";
   1196 		if ( $parsed_args['show_option_no_change'] ) {
   1197 			$output .= "\t<option value=\"-1\">" . $parsed_args['show_option_no_change'] . "</option>\n";
   1198 		}
   1199 		if ( $parsed_args['show_option_none'] ) {
   1200 			$output .= "\t<option value=\"" . esc_attr( $parsed_args['option_none_value'] ) . '">' . $parsed_args['show_option_none'] . "</option>\n";
   1201 		}
   1202 		$output .= walk_page_dropdown_tree( $pages, $parsed_args['depth'], $parsed_args );
   1203 		$output .= "</select>\n";
   1204 	}
   1205 
   1206 	/**
   1207 	 * Filters the HTML output of a list of pages as a drop down.
   1208 	 *
   1209 	 * @since 2.1.0
   1210 	 * @since 4.4.0 `$parsed_args` and `$pages` added as arguments.
   1211 	 *
   1212 	 * @param string    $output      HTML output for drop down list of pages.
   1213 	 * @param array     $parsed_args The parsed arguments array. See wp_dropdown_pages()
   1214 	 *                               for information on accepted arguments.
   1215 	 * @param WP_Post[] $pages       Array of the page objects.
   1216 	 */
   1217 	$html = apply_filters( 'wp_dropdown_pages', $output, $parsed_args, $pages );
   1218 
   1219 	if ( $parsed_args['echo'] ) {
   1220 		echo $html;
   1221 	}
   1222 
   1223 	return $html;
   1224 }
   1225 
   1226 /**
   1227  * Retrieve or display a list of pages (or hierarchical post type items) in list (li) format.
   1228  *
   1229  * @since 1.5.0
   1230  * @since 4.7.0 Added the `item_spacing` argument.
   1231  *
   1232  * @see get_pages()
   1233  *
   1234  * @global WP_Query $wp_query WordPress Query object.
   1235  *
   1236  * @param array|string $args {
   1237  *     Optional. Array or string of arguments to generate a list of pages. See `get_pages()` for additional arguments.
   1238  *
   1239  *     @type int          $child_of     Display only the sub-pages of a single page by ID. Default 0 (all pages).
   1240  *     @type string       $authors      Comma-separated list of author IDs. Default empty (all authors).
   1241  *     @type string       $date_format  PHP date format to use for the listed pages. Relies on the 'show_date' parameter.
   1242  *                                      Default is the value of 'date_format' option.
   1243  *     @type int          $depth        Number of levels in the hierarchy of pages to include in the generated list.
   1244  *                                      Accepts -1 (any depth), 0 (all pages), 1 (top-level pages only), and n (pages to
   1245  *                                      the given n depth). Default 0.
   1246  *     @type bool         $echo         Whether or not to echo the list of pages. Default true.
   1247  *     @type string       $exclude      Comma-separated list of page IDs to exclude. Default empty.
   1248  *     @type array        $include      Comma-separated list of page IDs to include. Default empty.
   1249  *     @type string       $link_after   Text or HTML to follow the page link label. Default null.
   1250  *     @type string       $link_before  Text or HTML to precede the page link label. Default null.
   1251  *     @type string       $post_type    Post type to query for. Default 'page'.
   1252  *     @type string|array $post_status  Comma-separated list or array of post statuses to include. Default 'publish'.
   1253  *     @type string       $show_date    Whether to display the page publish or modified date for each page. Accepts
   1254  *                                      'modified' or any other value. An empty value hides the date. Default empty.
   1255  *     @type string       $sort_column  Comma-separated list of column names to sort the pages by. Accepts 'post_author',
   1256  *                                      'post_date', 'post_title', 'post_name', 'post_modified', 'post_modified_gmt',
   1257  *                                      'menu_order', 'post_parent', 'ID', 'rand', or 'comment_count'. Default 'post_title'.
   1258  *     @type string       $title_li     List heading. Passing a null or empty value will result in no heading, and the list
   1259  *                                      will not be wrapped with unordered list `<ul>` tags. Default 'Pages'.
   1260  *     @type string       $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve' or 'discard'.
   1261  *                                      Default 'preserve'.
   1262  *     @type Walker       $walker       Walker instance to use for listing pages. Default empty (Walker_Page).
   1263  * }
   1264  * @return void|string Void if 'echo' argument is true, HTML list of pages if 'echo' is false.
   1265  */
   1266 function wp_list_pages( $args = '' ) {
   1267 	$defaults = array(
   1268 		'depth'        => 0,
   1269 		'show_date'    => '',
   1270 		'date_format'  => get_option( 'date_format' ),
   1271 		'child_of'     => 0,
   1272 		'exclude'      => '',
   1273 		'title_li'     => __( 'Pages' ),
   1274 		'echo'         => 1,
   1275 		'authors'      => '',
   1276 		'sort_column'  => 'menu_order, post_title',
   1277 		'link_before'  => '',
   1278 		'link_after'   => '',
   1279 		'item_spacing' => 'preserve',
   1280 		'walker'       => '',
   1281 	);
   1282 
   1283 	$parsed_args = wp_parse_args( $args, $defaults );
   1284 
   1285 	if ( ! in_array( $parsed_args['item_spacing'], array( 'preserve', 'discard' ), true ) ) {
   1286 		// Invalid value, fall back to default.
   1287 		$parsed_args['item_spacing'] = $defaults['item_spacing'];
   1288 	}
   1289 
   1290 	$output       = '';
   1291 	$current_page = 0;
   1292 
   1293 	// Sanitize, mostly to keep spaces out.
   1294 	$parsed_args['exclude'] = preg_replace( '/[^0-9,]/', '', $parsed_args['exclude'] );
   1295 
   1296 	// Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array).
   1297 	$exclude_array = ( $parsed_args['exclude'] ) ? explode( ',', $parsed_args['exclude'] ) : array();
   1298 
   1299 	/**
   1300 	 * Filters the array of pages to exclude from the pages list.
   1301 	 *
   1302 	 * @since 2.1.0
   1303 	 *
   1304 	 * @param string[] $exclude_array An array of page IDs to exclude.
   1305 	 */
   1306 	$parsed_args['exclude'] = implode( ',', apply_filters( 'wp_list_pages_excludes', $exclude_array ) );
   1307 
   1308 	$parsed_args['hierarchical'] = 0;
   1309 
   1310 	// Query pages.
   1311 	$pages = get_pages( $parsed_args );
   1312 
   1313 	if ( ! empty( $pages ) ) {
   1314 		if ( $parsed_args['title_li'] ) {
   1315 			$output .= '<li class="pagenav">' . $parsed_args['title_li'] . '<ul>';
   1316 		}
   1317 		global $wp_query;
   1318 		if ( is_page() || is_attachment() || $wp_query->is_posts_page ) {
   1319 			$current_page = get_queried_object_id();
   1320 		} elseif ( is_singular() ) {
   1321 			$queried_object = get_queried_object();
   1322 			if ( is_post_type_hierarchical( $queried_object->post_type ) ) {
   1323 				$current_page = $queried_object->ID;
   1324 			}
   1325 		}
   1326 
   1327 		$output .= walk_page_tree( $pages, $parsed_args['depth'], $current_page, $parsed_args );
   1328 
   1329 		if ( $parsed_args['title_li'] ) {
   1330 			$output .= '</ul></li>';
   1331 		}
   1332 	}
   1333 
   1334 	/**
   1335 	 * Filters the HTML output of the pages to list.
   1336 	 *
   1337 	 * @since 1.5.1
   1338 	 * @since 4.4.0 `$pages` added as arguments.
   1339 	 *
   1340 	 * @see wp_list_pages()
   1341 	 *
   1342 	 * @param string    $output      HTML output of the pages list.
   1343 	 * @param array     $parsed_args An array of page-listing arguments. See wp_list_pages()
   1344 	 *                               for information on accepted arguments.
   1345 	 * @param WP_Post[] $pages       Array of the page objects.
   1346 	 */
   1347 	$html = apply_filters( 'wp_list_pages', $output, $parsed_args, $pages );
   1348 
   1349 	if ( $parsed_args['echo'] ) {
   1350 		echo $html;
   1351 	} else {
   1352 		return $html;
   1353 	}
   1354 }
   1355 
   1356 /**
   1357  * Displays or retrieves a list of pages with an optional home link.
   1358  *
   1359  * The arguments are listed below and part of the arguments are for wp_list_pages() function.
   1360  * Check that function for more info on those arguments.
   1361  *
   1362  * @since 2.7.0
   1363  * @since 4.4.0 Added `menu_id`, `container`, `before`, `after`, and `walker` arguments.
   1364  * @since 4.7.0 Added the `item_spacing` argument.
   1365  *
   1366  * @param array|string $args {
   1367  *     Optional. Array or string of arguments to generate a page menu. See `wp_list_pages()` for additional arguments.
   1368  *
   1369  *     @type string          $sort_column  How to sort the list of pages. Accepts post column names.
   1370  *                                         Default 'menu_order, post_title'.
   1371  *     @type string          $menu_id      ID for the div containing the page list. Default is empty string.
   1372  *     @type string          $menu_class   Class to use for the element containing the page list. Default 'menu'.
   1373  *     @type string          $container    Element to use for the element containing the page list. Default 'div'.
   1374  *     @type bool            $echo         Whether to echo the list or return it. Accepts true (echo) or false (return).
   1375  *                                         Default true.
   1376  *     @type int|bool|string $show_home    Whether to display the link to the home page. Can just enter the text
   1377  *                                         you'd like shown for the home link. 1|true defaults to 'Home'.
   1378  *     @type string          $link_before  The HTML or text to prepend to $show_home text. Default empty.
   1379  *     @type string          $link_after   The HTML or text to append to $show_home text. Default empty.
   1380  *     @type string          $before       The HTML or text to prepend to the menu. Default is '<ul>'.
   1381  *     @type string          $after        The HTML or text to append to the menu. Default is '</ul>'.
   1382  *     @type string          $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve'
   1383  *                                         or 'discard'. Default 'discard'.
   1384  *     @type Walker          $walker       Walker instance to use for listing pages. Default empty (Walker_Page).
   1385  * }
   1386  * @return void|string Void if 'echo' argument is true, HTML menu if 'echo' is false.
   1387  */
   1388 function wp_page_menu( $args = array() ) {
   1389 	$defaults = array(
   1390 		'sort_column'  => 'menu_order, post_title',
   1391 		'menu_id'      => '',
   1392 		'menu_class'   => 'menu',
   1393 		'container'    => 'div',
   1394 		'echo'         => true,
   1395 		'link_before'  => '',
   1396 		'link_after'   => '',
   1397 		'before'       => '<ul>',
   1398 		'after'        => '</ul>',
   1399 		'item_spacing' => 'discard',
   1400 		'walker'       => '',
   1401 	);
   1402 	$args     = wp_parse_args( $args, $defaults );
   1403 
   1404 	if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ), true ) ) {
   1405 		// Invalid value, fall back to default.
   1406 		$args['item_spacing'] = $defaults['item_spacing'];
   1407 	}
   1408 
   1409 	if ( 'preserve' === $args['item_spacing'] ) {
   1410 		$t = "\t";
   1411 		$n = "\n";
   1412 	} else {
   1413 		$t = '';
   1414 		$n = '';
   1415 	}
   1416 
   1417 	/**
   1418 	 * Filters the arguments used to generate a page-based menu.
   1419 	 *
   1420 	 * @since 2.7.0
   1421 	 *
   1422 	 * @see wp_page_menu()
   1423 	 *
   1424 	 * @param array $args An array of page menu arguments. See wp_page_menu()
   1425 	 *                    for information on accepted arguments.
   1426 	 */
   1427 	$args = apply_filters( 'wp_page_menu_args', $args );
   1428 
   1429 	$menu = '';
   1430 
   1431 	$list_args = $args;
   1432 
   1433 	// Show Home in the menu.
   1434 	if ( ! empty( $args['show_home'] ) ) {
   1435 		if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) {
   1436 			$text = __( 'Home' );
   1437 		} else {
   1438 			$text = $args['show_home'];
   1439 		}
   1440 		$class = '';
   1441 		if ( is_front_page() && ! is_paged() ) {
   1442 			$class = 'class="current_page_item"';
   1443 		}
   1444 		$menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
   1445 		// If the front page is a page, add it to the exclude list.
   1446 		if ( 'page' === get_option( 'show_on_front' ) ) {
   1447 			if ( ! empty( $list_args['exclude'] ) ) {
   1448 				$list_args['exclude'] .= ',';
   1449 			} else {
   1450 				$list_args['exclude'] = '';
   1451 			}
   1452 			$list_args['exclude'] .= get_option( 'page_on_front' );
   1453 		}
   1454 	}
   1455 
   1456 	$list_args['echo']     = false;
   1457 	$list_args['title_li'] = '';
   1458 	$menu                 .= wp_list_pages( $list_args );
   1459 
   1460 	$container = sanitize_text_field( $args['container'] );
   1461 
   1462 	// Fallback in case `wp_nav_menu()` was called without a container.
   1463 	if ( empty( $container ) ) {
   1464 		$container = 'div';
   1465 	}
   1466 
   1467 	if ( $menu ) {
   1468 
   1469 		// wp_nav_menu() doesn't set before and after.
   1470 		if ( isset( $args['fallback_cb'] ) &&
   1471 			'wp_page_menu' === $args['fallback_cb'] &&
   1472 			'ul' !== $container ) {
   1473 			$args['before'] = "<ul>{$n}";
   1474 			$args['after']  = '</ul>';
   1475 		}
   1476 
   1477 		$menu = $args['before'] . $menu . $args['after'];
   1478 	}
   1479 
   1480 	$attrs = '';
   1481 	if ( ! empty( $args['menu_id'] ) ) {
   1482 		$attrs .= ' id="' . esc_attr( $args['menu_id'] ) . '"';
   1483 	}
   1484 
   1485 	if ( ! empty( $args['menu_class'] ) ) {
   1486 		$attrs .= ' class="' . esc_attr( $args['menu_class'] ) . '"';
   1487 	}
   1488 
   1489 	$menu = "<{$container}{$attrs}>" . $menu . "</{$container}>{$n}";
   1490 
   1491 	/**
   1492 	 * Filters the HTML output of a page-based menu.
   1493 	 *
   1494 	 * @since 2.7.0
   1495 	 *
   1496 	 * @see wp_page_menu()
   1497 	 *
   1498 	 * @param string $menu The HTML output.
   1499 	 * @param array  $args An array of arguments. See wp_page_menu()
   1500 	 *                     for information on accepted arguments.
   1501 	 */
   1502 	$menu = apply_filters( 'wp_page_menu', $menu, $args );
   1503 
   1504 	if ( $args['echo'] ) {
   1505 		echo $menu;
   1506 	} else {
   1507 		return $menu;
   1508 	}
   1509 }
   1510 
   1511 //
   1512 // Page helpers.
   1513 //
   1514 
   1515 /**
   1516  * Retrieve HTML list content for page list.
   1517  *
   1518  * @uses Walker_Page to create HTML list content.
   1519  * @since 2.1.0
   1520  *
   1521  * @param array $pages
   1522  * @param int   $depth
   1523  * @param int   $current_page
   1524  * @param array $r
   1525  * @return string
   1526  */
   1527 function walk_page_tree( $pages, $depth, $current_page, $r ) {
   1528 	if ( empty( $r['walker'] ) ) {
   1529 		$walker = new Walker_Page;
   1530 	} else {
   1531 		/**
   1532 		 * @var Walker $walker
   1533 		 */
   1534 		$walker = $r['walker'];
   1535 	}
   1536 
   1537 	foreach ( (array) $pages as $page ) {
   1538 		if ( $page->post_parent ) {
   1539 			$r['pages_with_children'][ $page->post_parent ] = true;
   1540 		}
   1541 	}
   1542 
   1543 	return $walker->walk( $pages, $depth, $r, $current_page );
   1544 }
   1545 
   1546 /**
   1547  * Retrieve HTML dropdown (select) content for page list.
   1548  *
   1549  * @since 2.1.0
   1550  * @since 5.3.0 Formalized the existing `...$args` parameter by adding it
   1551  *              to the function signature.
   1552  *
   1553  * @uses Walker_PageDropdown to create HTML dropdown content.
   1554  * @see Walker_PageDropdown::walk() for parameters and return description.
   1555  *
   1556  * @param mixed ...$args Elements array, maximum hierarchical depth and optional additional arguments.
   1557  * @return string
   1558  */
   1559 function walk_page_dropdown_tree( ...$args ) {
   1560 	if ( empty( $args[2]['walker'] ) ) { // The user's options are the third parameter.
   1561 		$walker = new Walker_PageDropdown;
   1562 	} else {
   1563 		/**
   1564 		 * @var Walker $walker
   1565 		 */
   1566 		$walker = $args[2]['walker'];
   1567 	}
   1568 
   1569 	return $walker->walk( ...$args );
   1570 }
   1571 
   1572 //
   1573 // Attachments.
   1574 //
   1575 
   1576 /**
   1577  * Display an attachment page link using an image or icon.
   1578  *
   1579  * @since 2.0.0
   1580  *
   1581  * @param int|WP_Post $id Optional. Post ID or post object.
   1582  * @param bool        $fullsize     Optional. Whether to use full size. Default false.
   1583  * @param bool        $deprecated   Deprecated. Not used.
   1584  * @param bool        $permalink    Optional. Whether to include permalink. Default false.
   1585  */
   1586 function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) {
   1587 	if ( ! empty( $deprecated ) ) {
   1588 		_deprecated_argument( __FUNCTION__, '2.5.0' );
   1589 	}
   1590 
   1591 	if ( $fullsize ) {
   1592 		echo wp_get_attachment_link( $id, 'full', $permalink );
   1593 	} else {
   1594 		echo wp_get_attachment_link( $id, 'thumbnail', $permalink );
   1595 	}
   1596 }
   1597 
   1598 /**
   1599  * Retrieve an attachment page link using an image or icon, if possible.
   1600  *
   1601  * @since 2.5.0
   1602  * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
   1603  *
   1604  * @param int|WP_Post  $id        Optional. Post ID or post object.
   1605  * @param string|int[] $size      Optional. Image size. Accepts any registered image size name, or an array
   1606  *                                of width and height values in pixels (in that order). Default 'thumbnail'.
   1607  * @param bool         $permalink Optional. Whether to add permalink to image. Default false.
   1608  * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
   1609  * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
   1610  *                                Default false.
   1611  * @param array|string $attr      Optional. Array or string of attributes. Default empty.
   1612  * @return string HTML content.
   1613  */
   1614 function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) {
   1615 	$_post = get_post( $id );
   1616 
   1617 	if ( empty( $_post ) || ( 'attachment' !== $_post->post_type ) || ! wp_get_attachment_url( $_post->ID ) ) {
   1618 		return __( 'Missing Attachment' );
   1619 	}
   1620 
   1621 	$url = wp_get_attachment_url( $_post->ID );
   1622 
   1623 	if ( $permalink ) {
   1624 		$url = get_attachment_link( $_post->ID );
   1625 	}
   1626 
   1627 	if ( $text ) {
   1628 		$link_text = $text;
   1629 	} elseif ( $size && 'none' !== $size ) {
   1630 		$link_text = wp_get_attachment_image( $_post->ID, $size, $icon, $attr );
   1631 	} else {
   1632 		$link_text = '';
   1633 	}
   1634 
   1635 	if ( '' === trim( $link_text ) ) {
   1636 		$link_text = $_post->post_title;
   1637 	}
   1638 
   1639 	if ( '' === trim( $link_text ) ) {
   1640 		$link_text = esc_html( pathinfo( get_attached_file( $_post->ID ), PATHINFO_FILENAME ) );
   1641 	}
   1642 	/**
   1643 	 * Filters a retrieved attachment page link.
   1644 	 *
   1645 	 * @since 2.7.0
   1646 	 * @since 5.1.0 Added the `$attr` parameter.
   1647 	 *
   1648 	 * @param string       $link_html The page link HTML output.
   1649 	 * @param int          $id        Post ID.
   1650 	 * @param string|int[] $size      Requested image size. Can be any registered image size name, or
   1651 	 *                                an array of width and height values in pixels (in that order).
   1652 	 * @param bool         $permalink Whether to add permalink to image. Default false.
   1653 	 * @param bool         $icon      Whether to include an icon.
   1654 	 * @param string|false $text      If string, will be link text.
   1655 	 * @param array|string $attr      Array or string of attributes.
   1656 	 */
   1657 	return apply_filters( 'wp_get_attachment_link', "<a href='" . esc_url( $url ) . "'>$link_text</a>", $id, $size, $permalink, $icon, $text, $attr );
   1658 }
   1659 
   1660 /**
   1661  * Wrap attachment in paragraph tag before content.
   1662  *
   1663  * @since 2.0.0
   1664  *
   1665  * @param string $content
   1666  * @return string
   1667  */
   1668 function prepend_attachment( $content ) {
   1669 	$post = get_post();
   1670 
   1671 	if ( empty( $post->post_type ) || 'attachment' !== $post->post_type ) {
   1672 		return $content;
   1673 	}
   1674 
   1675 	if ( wp_attachment_is( 'video', $post ) ) {
   1676 		$meta = wp_get_attachment_metadata( get_the_ID() );
   1677 		$atts = array( 'src' => wp_get_attachment_url() );
   1678 		if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
   1679 			$atts['width']  = (int) $meta['width'];
   1680 			$atts['height'] = (int) $meta['height'];
   1681 		}
   1682 		if ( has_post_thumbnail() ) {
   1683 			$atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() );
   1684 		}
   1685 		$p = wp_video_shortcode( $atts );
   1686 	} elseif ( wp_attachment_is( 'audio', $post ) ) {
   1687 		$p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) );
   1688 	} else {
   1689 		$p = '<p class="attachment">';
   1690 		// Show the medium sized image representation of the attachment if available, and link to the raw file.
   1691 		$p .= wp_get_attachment_link( 0, 'medium', false );
   1692 		$p .= '</p>';
   1693 	}
   1694 
   1695 	/**
   1696 	 * Filters the attachment markup to be prepended to the post content.
   1697 	 *
   1698 	 * @since 2.0.0
   1699 	 *
   1700 	 * @see prepend_attachment()
   1701 	 *
   1702 	 * @param string $p The attachment HTML output.
   1703 	 */
   1704 	$p = apply_filters( 'prepend_attachment', $p );
   1705 
   1706 	return "$p\n$content";
   1707 }
   1708 
   1709 //
   1710 // Misc.
   1711 //
   1712 
   1713 /**
   1714  * Retrieve protected post password form content.
   1715  *
   1716  * @since 1.0.0
   1717  *
   1718  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
   1719  * @return string HTML content for password form for password protected post.
   1720  */
   1721 function get_the_password_form( $post = 0 ) {
   1722 	$post   = get_post( $post );
   1723 	$label  = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID );
   1724 	$output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">
   1725 	<p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p>
   1726 	<p><label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr_x( 'Enter', 'post password form' ) . '" /></p></form>
   1727 	';
   1728 
   1729 	/**
   1730 	 * Filters the HTML output for the protected post password form.
   1731 	 *
   1732 	 * If modifying the password field, please note that the core database schema
   1733 	 * limits the password field to 20 characters regardless of the value of the
   1734 	 * size attribute in the form input.
   1735 	 *
   1736 	 * @since 2.7.0
   1737 	 * @since 5.8.0 Added the `$post` parameter.
   1738 	 *
   1739 	 * @param string  $output The password form HTML output.
   1740 	 * @param WP_Post $post   Post object.
   1741 	 */
   1742 	return apply_filters( 'the_password_form', $output, $post );
   1743 }
   1744 
   1745 /**
   1746  * Determines whether currently in a page template.
   1747  *
   1748  * This template tag allows you to determine if you are in a page template.
   1749  * You can optionally provide a template filename or array of template filenames
   1750  * and then the check will be specific to that template.
   1751  *
   1752  * For more information on this and similar theme functions, check out
   1753  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
   1754  * Conditional Tags} article in the Theme Developer Handbook.
   1755  *
   1756  * @since 2.5.0
   1757  * @since 4.2.0 The `$template` parameter was changed to also accept an array of page templates.
   1758  * @since 4.7.0 Now works with any post type, not just pages.
   1759  *
   1760  * @param string|string[] $template The specific template filename or array of templates to match.
   1761  * @return bool True on success, false on failure.
   1762  */
   1763 function is_page_template( $template = '' ) {
   1764 	if ( ! is_singular() ) {
   1765 		return false;
   1766 	}
   1767 
   1768 	$page_template = get_page_template_slug( get_queried_object_id() );
   1769 
   1770 	if ( empty( $template ) ) {
   1771 		return (bool) $page_template;
   1772 	}
   1773 
   1774 	if ( $template == $page_template ) {
   1775 		return true;
   1776 	}
   1777 
   1778 	if ( is_array( $template ) ) {
   1779 		if ( ( in_array( 'default', $template, true ) && ! $page_template )
   1780 			|| in_array( $page_template, $template, true )
   1781 		) {
   1782 			return true;
   1783 		}
   1784 	}
   1785 
   1786 	return ( 'default' === $template && ! $page_template );
   1787 }
   1788 
   1789 /**
   1790  * Get the specific template filename for a given post.
   1791  *
   1792  * @since 3.4.0
   1793  * @since 4.7.0 Now works with any post type, not just pages.
   1794  *
   1795  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
   1796  * @return string|false Page template filename. Returns an empty string when the default page template
   1797  *                      is in use. Returns false if the post does not exist.
   1798  */
   1799 function get_page_template_slug( $post = null ) {
   1800 	$post = get_post( $post );
   1801 
   1802 	if ( ! $post ) {
   1803 		return false;
   1804 	}
   1805 
   1806 	$template = get_post_meta( $post->ID, '_wp_page_template', true );
   1807 
   1808 	if ( ! $template || 'default' === $template ) {
   1809 		return '';
   1810 	}
   1811 
   1812 	return $template;
   1813 }
   1814 
   1815 /**
   1816  * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
   1817  *
   1818  * @since 2.6.0
   1819  *
   1820  * @param int|object $revision Revision ID or revision object.
   1821  * @param bool       $link     Optional. Whether to link to revision's page. Default true.
   1822  * @return string|false i18n formatted datetimestamp or localized 'Current Revision'.
   1823  */
   1824 function wp_post_revision_title( $revision, $link = true ) {
   1825 	$revision = get_post( $revision );
   1826 	if ( ! $revision ) {
   1827 		return $revision;
   1828 	}
   1829 
   1830 	if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ), true ) ) {
   1831 		return false;
   1832 	}
   1833 
   1834 	/* translators: Revision date format, see https://www.php.net/manual/datetime.format.php */
   1835 	$datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
   1836 	/* translators: %s: Revision date. */
   1837 	$autosavef = __( '%s [Autosave]' );
   1838 	/* translators: %s: Revision date. */
   1839 	$currentf = __( '%s [Current Revision]' );
   1840 
   1841 	$date      = date_i18n( $datef, strtotime( $revision->post_modified ) );
   1842 	$edit_link = get_edit_post_link( $revision->ID );
   1843 	if ( $link && current_user_can( 'edit_post', $revision->ID ) && $edit_link ) {
   1844 		$date = "<a href='$edit_link'>$date</a>";
   1845 	}
   1846 
   1847 	if ( ! wp_is_post_revision( $revision ) ) {
   1848 		$date = sprintf( $currentf, $date );
   1849 	} elseif ( wp_is_post_autosave( $revision ) ) {
   1850 		$date = sprintf( $autosavef, $date );
   1851 	}
   1852 
   1853 	return $date;
   1854 }
   1855 
   1856 /**
   1857  * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
   1858  *
   1859  * @since 3.6.0
   1860  *
   1861  * @param int|object $revision Revision ID or revision object.
   1862  * @param bool       $link     Optional. Whether to link to revision's page. Default true.
   1863  * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'.
   1864  */
   1865 function wp_post_revision_title_expanded( $revision, $link = true ) {
   1866 	$revision = get_post( $revision );
   1867 	if ( ! $revision ) {
   1868 		return $revision;
   1869 	}
   1870 
   1871 	if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ), true ) ) {
   1872 		return false;
   1873 	}
   1874 
   1875 	$author = get_the_author_meta( 'display_name', $revision->post_author );
   1876 	/* translators: Revision date format, see https://www.php.net/manual/datetime.format.php */
   1877 	$datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
   1878 
   1879 	$gravatar = get_avatar( $revision->post_author, 24 );
   1880 
   1881 	$date      = date_i18n( $datef, strtotime( $revision->post_modified ) );
   1882 	$edit_link = get_edit_post_link( $revision->ID );
   1883 	if ( $link && current_user_can( 'edit_post', $revision->ID ) && $edit_link ) {
   1884 		$date = "<a href='$edit_link'>$date</a>";
   1885 	}
   1886 
   1887 	$revision_date_author = sprintf(
   1888 		/* translators: Post revision title. 1: Author avatar, 2: Author name, 3: Time ago, 4: Date. */
   1889 		__( '%1$s %2$s, %3$s ago (%4$s)' ),
   1890 		$gravatar,
   1891 		$author,
   1892 		human_time_diff( strtotime( $revision->post_modified_gmt ) ),
   1893 		$date
   1894 	);
   1895 
   1896 	/* translators: %s: Revision date with author avatar. */
   1897 	$autosavef = __( '%s [Autosave]' );
   1898 	/* translators: %s: Revision date with author avatar. */
   1899 	$currentf = __( '%s [Current Revision]' );
   1900 
   1901 	if ( ! wp_is_post_revision( $revision ) ) {
   1902 		$revision_date_author = sprintf( $currentf, $revision_date_author );
   1903 	} elseif ( wp_is_post_autosave( $revision ) ) {
   1904 		$revision_date_author = sprintf( $autosavef, $revision_date_author );
   1905 	}
   1906 
   1907 	/**
   1908 	 * Filters the formatted author and date for a revision.
   1909 	 *
   1910 	 * @since 4.4.0
   1911 	 *
   1912 	 * @param string  $revision_date_author The formatted string.
   1913 	 * @param WP_Post $revision             The revision object.
   1914 	 * @param bool    $link                 Whether to link to the revisions page, as passed into
   1915 	 *                                      wp_post_revision_title_expanded().
   1916 	 */
   1917 	return apply_filters( 'wp_post_revision_title_expanded', $revision_date_author, $revision, $link );
   1918 }
   1919 
   1920 /**
   1921  * Display a list of a post's revisions.
   1922  *
   1923  * Can output either a UL with edit links or a TABLE with diff interface, and
   1924  * restore action links.
   1925  *
   1926  * @since 2.6.0
   1927  *
   1928  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
   1929  * @param string      $type    'all' (default), 'revision' or 'autosave'
   1930  */
   1931 function wp_list_post_revisions( $post_id = 0, $type = 'all' ) {
   1932 	$post = get_post( $post_id );
   1933 	if ( ! $post ) {
   1934 		return;
   1935 	}
   1936 
   1937 	// $args array with (parent, format, right, left, type) deprecated since 3.6.
   1938 	if ( is_array( $type ) ) {
   1939 		$type = ! empty( $type['type'] ) ? $type['type'] : $type;
   1940 		_deprecated_argument( __FUNCTION__, '3.6.0' );
   1941 	}
   1942 
   1943 	$revisions = wp_get_post_revisions( $post->ID );
   1944 	if ( ! $revisions ) {
   1945 		return;
   1946 	}
   1947 
   1948 	$rows = '';
   1949 	foreach ( $revisions as $revision ) {
   1950 		if ( ! current_user_can( 'read_post', $revision->ID ) ) {
   1951 			continue;
   1952 		}
   1953 
   1954 		$is_autosave = wp_is_post_autosave( $revision );
   1955 		if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) {
   1956 			continue;
   1957 		}
   1958 
   1959 		$rows .= "\t<li>" . wp_post_revision_title_expanded( $revision ) . "</li>\n";
   1960 	}
   1961 
   1962 	echo "<div class='hide-if-js'><p>" . __( 'JavaScript must be enabled to use this feature.' ) . "</p></div>\n";
   1963 
   1964 	echo "<ul class='post-revisions hide-if-no-js'>\n";
   1965 	echo $rows;
   1966 	echo '</ul>';
   1967 }
   1968 
   1969 /**
   1970  * Retrieves the parent post object for the given post.
   1971  *
   1972  * @since 5.7.0
   1973  *
   1974  * @param int|WP_Post|null $post Optional. Post ID or WP_Post object. Default is global $post.
   1975  * @return WP_Post|null Parent post object, or null if there isn't one.
   1976  */
   1977 function get_post_parent( $post = null ) {
   1978 	$wp_post = get_post( $post );
   1979 	return ! empty( $wp_post->post_parent ) ? get_post( $wp_post->post_parent ) : null;
   1980 }
   1981 
   1982 /**
   1983  * Returns whether the given post has a parent post.
   1984  *
   1985  * @since 5.7.0
   1986  *
   1987  * @param int|WP_Post|null $post Optional. Post ID or WP_Post object. Default is global $post.
   1988  * @return bool Whether the post has a parent post.
   1989  */
   1990 function has_post_parent( $post = null ) {
   1991 	return (bool) get_post_parent( $post );
   1992 }