wp/wp-includes/post-template.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    11 /**
    11 /**
    12  * Display the ID of the current item in the WordPress Loop.
    12  * Display the ID of the current item in the WordPress Loop.
    13  *
    13  *
    14  * @since 0.71
    14  * @since 0.71
    15  */
    15  */
    16 function the_ID() {
    16 function the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
    17 	echo get_the_ID();
    17 	echo get_the_ID();
    18 }
    18 }
    19 
    19 
    20 /**
    20 /**
    21  * Retrieve the ID of the current item in the WordPress Loop.
    21  * Retrieve the ID of the current item in the WordPress Loop.
    22  *
    22  *
    23  * @since 2.1.0
    23  * @since 2.1.0
    24  *
    24  *
    25  * @return int|false The ID of the current item in the WordPress Loop. False if $post is not set.
    25  * @return int|false The ID of the current item in the WordPress Loop. False if $post is not set.
    26  */
    26  */
    27 function get_the_ID() {
    27 function get_the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
    28 	$post = get_post();
    28 	$post = get_post();
    29 	return ! empty( $post ) ? $post->ID : false;
    29 	return ! empty( $post ) ? $post->ID : false;
    30 }
    30 }
    31 
    31 
    32 /**
    32 /**
    35  * @since 0.71
    35  * @since 0.71
    36  *
    36  *
    37  * @param string $before Optional. Markup to prepend to the title. Default empty.
    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.
    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.
    39  * @param bool   $echo   Optional. Whether to echo or return the title. Default true for echo.
    40  * @return string|void Current post title if $echo is false.
    40  * @return void|string Void if `$echo` argument is true, current post title if `$echo` is false.
    41  */
    41  */
    42 function the_title( $before = '', $after = '', $echo = true ) {
    42 function the_title( $before = '', $after = '', $echo = true ) {
    43 	$title = get_the_title();
    43 	$title = get_the_title();
    44 
    44 
    45 	if ( strlen( $title ) == 0 ) {
    45 	if ( strlen( $title ) == 0 ) {
    73  *     @type string  $before Markup to prepend to the title. Default empty.
    73  *     @type string  $before Markup to prepend to the title. Default empty.
    74  *     @type string  $after  Markup to append 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.
    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.
    76  *     @type WP_Post $post   Current post object to retrieve the title for.
    77  * }
    77  * }
    78  * @return string|void String when echo is false.
    78  * @return void|string Void if 'echo' argument is true, the title attribute if 'echo' is false.
    79  */
    79  */
    80 function the_title_attribute( $args = '' ) {
    80 function the_title_attribute( $args = '' ) {
    81 	$defaults = array(
    81 	$defaults    = array(
    82 		'before' => '',
    82 		'before' => '',
    83 		'after'  => '',
    83 		'after'  => '',
    84 		'echo'   => true,
    84 		'echo'   => true,
    85 		'post'   => get_post(),
    85 		'post'   => get_post(),
    86 	);
    86 	);
    87 	$r        = wp_parse_args( $args, $defaults );
    87 	$parsed_args = wp_parse_args( $args, $defaults );
    88 
    88 
    89 	$title = get_the_title( $r['post'] );
    89 	$title = get_the_title( $parsed_args['post'] );
    90 
    90 
    91 	if ( strlen( $title ) == 0 ) {
    91 	if ( strlen( $title ) == 0 ) {
    92 		return;
    92 		return;
    93 	}
    93 	}
    94 
    94 
    95 	$title = $r['before'] . $title . $r['after'];
    95 	$title = $parsed_args['before'] . $title . $parsed_args['after'];
    96 	$title = esc_attr( strip_tags( $title ) );
    96 	$title = esc_attr( strip_tags( $title ) );
    97 
    97 
    98 	if ( $r['echo'] ) {
    98 	if ( $parsed_args['echo'] ) {
    99 		echo $title;
    99 		echo $title;
   100 	} else {
   100 	} else {
   101 		return $title;
   101 		return $title;
   102 	}
   102 	}
   103 }
   103 }
   120 	$title = isset( $post->post_title ) ? $post->post_title : '';
   120 	$title = isset( $post->post_title ) ? $post->post_title : '';
   121 	$id    = isset( $post->ID ) ? $post->ID : 0;
   121 	$id    = isset( $post->ID ) ? $post->ID : 0;
   122 
   122 
   123 	if ( ! is_admin() ) {
   123 	if ( ! is_admin() ) {
   124 		if ( ! empty( $post->post_password ) ) {
   124 		if ( ! empty( $post->post_password ) ) {
       
   125 
       
   126 			/* translators: %s: Protected post title. */
       
   127 			$prepend = __( 'Protected: %s' );
   125 
   128 
   126 			/**
   129 			/**
   127 			 * Filters the text prepended to the post title for protected posts.
   130 			 * Filters the text prepended to the post title for protected posts.
   128 			 *
   131 			 *
   129 			 * The filter is only applied on the front end.
   132 			 * The filter is only applied on the front end.
   132 			 *
   135 			 *
   133 			 * @param string  $prepend Text displayed before the post title.
   136 			 * @param string  $prepend Text displayed before the post title.
   134 			 *                         Default 'Protected: %s'.
   137 			 *                         Default 'Protected: %s'.
   135 			 * @param WP_Post $post    Current post object.
   138 			 * @param WP_Post $post    Current post object.
   136 			 */
   139 			 */
   137 			$protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ), $post );
   140 			$protected_title_format = apply_filters( 'protected_title_format', $prepend, $post );
   138 			$title                  = sprintf( $protected_title_format, $title );
   141 			$title                  = sprintf( $protected_title_format, $title );
   139 		} elseif ( isset( $post->post_status ) && 'private' == $post->post_status ) {
   142 		} elseif ( isset( $post->post_status ) && 'private' === $post->post_status ) {
       
   143 
       
   144 			/* translators: %s: Private post title. */
       
   145 			$prepend = __( 'Private: %s' );
   140 
   146 
   141 			/**
   147 			/**
   142 			 * Filters the text prepended to the post title of private posts.
   148 			 * Filters the text prepended to the post title of private posts.
   143 			 *
   149 			 *
   144 			 * The filter is only applied on the front end.
   150 			 * The filter is only applied on the front end.
   147 			 *
   153 			 *
   148 			 * @param string  $prepend Text displayed before the post title.
   154 			 * @param string  $prepend Text displayed before the post title.
   149 			 *                         Default 'Private: %s'.
   155 			 *                         Default 'Private: %s'.
   150 			 * @param WP_Post $post    Current post object.
   156 			 * @param WP_Post $post    Current post object.
   151 			 */
   157 			 */
   152 			$private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ), $post );
   158 			$private_title_format = apply_filters( 'private_title_format', $prepend, $post );
   153 			$title                = sprintf( $private_title_format, $title );
   159 			$title                = sprintf( $private_title_format, $title );
   154 		}
   160 		}
   155 	}
   161 	}
   156 
   162 
   157 	/**
   163 	/**
   230  * Display the post content.
   236  * Display the post content.
   231  *
   237  *
   232  * @since 0.71
   238  * @since 0.71
   233  *
   239  *
   234  * @param string $more_link_text Optional. Content for when there is more text.
   240  * @param string $more_link_text Optional. Content for when there is more text.
   235  * @param bool   $strip_teaser   Optional. Strip teaser content before the more text. Default is false.
   241  * @param bool   $strip_teaser   Optional. Strip teaser content before the more text. Default false.
   236  */
   242  */
   237 function the_content( $more_link_text = null, $strip_teaser = false ) {
   243 function the_content( $more_link_text = null, $strip_teaser = false ) {
   238 	$content = get_the_content( $more_link_text, $strip_teaser );
   244 	$content = get_the_content( $more_link_text, $strip_teaser );
   239 
   245 
   240 	/**
   246 	/**
   261  * @global array $pages     Array of all pages in post/page. Each array element contains
   267  * @global array $pages     Array of all pages in post/page. Each array element contains
   262  *                          part of the content separated by the `<!--nextpage-->` tag.
   268  *                          part of the content separated by the `<!--nextpage-->` tag.
   263  * @global int   $multipage Boolean indicator for whether multiple pages are in play.
   269  * @global int   $multipage Boolean indicator for whether multiple pages are in play.
   264  *
   270  *
   265  * @param string             $more_link_text Optional. Content for when there is more text.
   271  * @param string             $more_link_text Optional. Content for when there is more text.
   266  * @param bool               $strip_teaser   Optional. Strip teaser content before the more text. Default is false.
   272  * @param bool               $strip_teaser   Optional. Strip teaser content before the more text. Default false.
   267  * @param WP_Post|object|int $post           Optional. WP_Post instance or Post ID/object. Default is null.
   273  * @param WP_Post|object|int $post           Optional. WP_Post instance or Post ID/object. Default null.
   268  * @return string
   274  * @return string
   269  */
   275  */
   270 function get_the_content( $more_link_text = null, $strip_teaser = false, $post = null ) {
   276 function get_the_content( $more_link_text = null, $strip_teaser = false, $post = null ) {
   271 	global $page, $more, $preview, $pages, $multipage;
   277 	global $page, $more, $preview, $pages, $multipage;
   272 
   278 
   274 
   280 
   275 	if ( ! ( $_post instanceof WP_Post ) ) {
   281 	if ( ! ( $_post instanceof WP_Post ) ) {
   276 		return '';
   282 		return '';
   277 	}
   283 	}
   278 
   284 
   279 	if ( null === $post ) {
   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' ) ) {
   280 		$elements = compact( 'page', 'more', 'preview', 'pages', 'multipage' );
   288 		$elements = compact( 'page', 'more', 'preview', 'pages', 'multipage' );
   281 	} else {
   289 	} else {
   282 		$elements = generate_postdata( $_post );
   290 		$elements = generate_postdata( $_post );
   283 	}
   291 	}
   284 
   292 
   285 	if ( null === $more_link_text ) {
   293 	if ( null === $more_link_text ) {
   286 		$more_link_text = sprintf(
   294 		$more_link_text = sprintf(
   287 			'<span aria-label="%1$s">%2$s</span>',
   295 			'<span aria-label="%1$s">%2$s</span>',
   288 			sprintf(
   296 			sprintf(
   289 				/* translators: %s: Name of current post */
   297 				/* translators: %s: Post title. */
   290 				__( 'Continue reading %s' ),
   298 				__( 'Continue reading %s' ),
   291 				the_title_attribute(
   299 				the_title_attribute(
   292 					array(
   300 					array(
   293 						'echo' => false,
   301 						'echo' => false,
   294 						'post' => $_post,
   302 						'post' => $_post,
   305 	// If post password required and it doesn't match the cookie.
   313 	// If post password required and it doesn't match the cookie.
   306 	if ( post_password_required( $_post ) ) {
   314 	if ( post_password_required( $_post ) ) {
   307 		return get_the_password_form( $_post );
   315 		return get_the_password_form( $_post );
   308 	}
   316 	}
   309 
   317 
   310 	if ( $elements['page'] > count( $elements['pages'] ) ) { // if the requested page doesn't exist
   318 	// If the requested page doesn't exist.
   311 		$elements['page'] = count( $elements['pages'] ); // give them the highest numbered page that DOES exist
   319 	if ( $elements['page'] > count( $elements['pages'] ) ) {
       
   320 		// Give them the highest numbered page that DOES exist.
       
   321 		$elements['page'] = count( $elements['pages'] );
   312 	}
   322 	}
   313 
   323 
   314 	$page_no = $elements['page'];
   324 	$page_no = $elements['page'];
   315 	$content = $elements['pages'][ $page_no - 1 ];
   325 	$content = $elements['pages'][ $page_no - 1 ];
   316 	if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
   326 	if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
   328 		$has_teaser = true;
   338 		$has_teaser = true;
   329 	} else {
   339 	} else {
   330 		$content = array( $content );
   340 		$content = array( $content );
   331 	}
   341 	}
   332 
   342 
   333 	if ( false !== strpos( $_post->post_content, '<!--noteaser-->' ) && ( ! $elements['multipage'] || $elements['page'] == 1 ) ) {
   343 	if ( false !== strpos( $_post->post_content, '<!--noteaser-->' ) && ( ! $elements['multipage'] || 1 == $elements['page'] ) ) {
   334 		$strip_teaser = true;
   344 		$strip_teaser = true;
   335 	}
   345 	}
   336 
   346 
   337 	$teaser = $content[0];
   347 	$teaser = $content[0];
   338 
   348 
   411 	 * Filters the retrieved post excerpt.
   421 	 * Filters the retrieved post excerpt.
   412 	 *
   422 	 *
   413 	 * @since 1.2.0
   423 	 * @since 1.2.0
   414 	 * @since 4.5.0 Introduced the `$post` parameter.
   424 	 * @since 4.5.0 Introduced the `$post` parameter.
   415 	 *
   425 	 *
   416 	 * @param string $post_excerpt The post excerpt.
   426 	 * @param string  $post_excerpt The post excerpt.
   417 	 * @param WP_Post $post Post object.
   427 	 * @param WP_Post $post         Post object.
   418 	 */
   428 	 */
   419 	return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );
   429 	return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );
   420 }
   430 }
   421 
   431 
   422 /**
   432 /**
   443  *
   453  *
   444  * @param string|array $class   One or more classes to add to the class list.
   454  * @param string|array $class   One or more classes to add to the class list.
   445  * @param int|WP_Post  $post_id Optional. Post ID or post object. Defaults to the global `$post`.
   455  * @param int|WP_Post  $post_id Optional. Post ID or post object. Defaults to the global `$post`.
   446  */
   456  */
   447 function post_class( $class = '', $post_id = null ) {
   457 function post_class( $class = '', $post_id = null ) {
   448 	// Separates classes with a single space, collates classes for post DIV
   458 	// Separates classes with a single space, collates classes for post DIV.
   449 	echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';
   459 	echo 'class="' . esc_attr( join( ' ', get_post_class( $class, $post_id ) ) ) . '"';
   450 }
   460 }
   451 
   461 
   452 /**
   462 /**
   453  * Retrieves an array of the class names for the post container element.
   463  * Retrieves an array of the class names for the post container element.
   454  *
   464  *
   494 		$classes[] = $post->post_type;
   504 		$classes[] = $post->post_type;
   495 	}
   505 	}
   496 	$classes[] = 'type-' . $post->post_type;
   506 	$classes[] = 'type-' . $post->post_type;
   497 	$classes[] = 'status-' . $post->post_status;
   507 	$classes[] = 'status-' . $post->post_status;
   498 
   508 
   499 	// Post Format
   509 	// Post Format.
   500 	if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
   510 	if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
   501 		$post_format = get_post_format( $post->ID );
   511 		$post_format = get_post_format( $post->ID );
   502 
   512 
   503 		if ( $post_format && ! is_wp_error( $post_format ) ) {
   513 		if ( $post_format && ! is_wp_error( $post_format ) ) {
   504 			$classes[] = 'format-' . sanitize_html_class( $post_format );
   514 			$classes[] = 'format-' . sanitize_html_class( $post_format );
   519 	// Post thumbnails.
   529 	// Post thumbnails.
   520 	if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) && ! is_attachment( $post ) && ! $post_password_required ) {
   530 	if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) && ! is_attachment( $post ) && ! $post_password_required ) {
   521 		$classes[] = 'has-post-thumbnail';
   531 		$classes[] = 'has-post-thumbnail';
   522 	}
   532 	}
   523 
   533 
   524 	// sticky for Sticky Posts
   534 	// Sticky for Sticky Posts.
   525 	if ( is_sticky( $post->ID ) ) {
   535 	if ( is_sticky( $post->ID ) ) {
   526 		if ( is_home() && ! is_paged() ) {
   536 		if ( is_home() && ! is_paged() ) {
   527 			$classes[] = 'sticky';
   537 			$classes[] = 'sticky';
   528 		} elseif ( is_admin() ) {
   538 		} elseif ( is_admin() ) {
   529 			$classes[] = 'status-sticky';
   539 			$classes[] = 'status-sticky';
   530 		}
   540 		}
   531 	}
   541 	}
   532 
   542 
   533 	// hentry for hAtom compliance
   543 	// hentry for hAtom compliance.
   534 	$classes[] = 'hentry';
   544 	$classes[] = 'hentry';
   535 
   545 
   536 	// All public taxonomies
   546 	// All public taxonomies.
   537 	$taxonomies = get_taxonomies( array( 'public' => true ) );
   547 	$taxonomies = get_taxonomies( array( 'public' => true ) );
   538 	foreach ( (array) $taxonomies as $taxonomy ) {
   548 	foreach ( (array) $taxonomies as $taxonomy ) {
   539 		if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) {
   549 		if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) {
   540 			foreach ( (array) get_the_terms( $post->ID, $taxonomy ) as $term ) {
   550 			foreach ( (array) get_the_terms( $post->ID, $taxonomy ) as $term ) {
   541 				if ( empty( $term->slug ) ) {
   551 				if ( empty( $term->slug ) ) {
   546 				if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) {
   556 				if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) {
   547 					$term_class = $term->term_id;
   557 					$term_class = $term->term_id;
   548 				}
   558 				}
   549 
   559 
   550 				// 'post_tag' uses the 'tag' prefix for backward compatibility.
   560 				// 'post_tag' uses the 'tag' prefix for backward compatibility.
   551 				if ( 'post_tag' == $taxonomy ) {
   561 				if ( 'post_tag' === $taxonomy ) {
   552 					$classes[] = 'tag-' . $term_class;
   562 					$classes[] = 'tag-' . $term_class;
   553 				} else {
   563 				} else {
   554 					$classes[] = sanitize_html_class( $taxonomy . '-' . $term_class, $taxonomy . '-' . $term->term_id );
   564 					$classes[] = sanitize_html_class( $taxonomy . '-' . $term_class, $taxonomy . '-' . $term->term_id );
   555 				}
   565 				}
   556 			}
   566 			}
   579  * @since 2.8.0
   589  * @since 2.8.0
   580  *
   590  *
   581  * @param string|string[] $class Space-separated string or array of class names to add to the class list.
   591  * @param string|string[] $class Space-separated string or array of class names to add to the class list.
   582  */
   592  */
   583 function body_class( $class = '' ) {
   593 function body_class( $class = '' ) {
   584 	// Separates class names with a single space, collates class names for body element
   594 	// Separates class names with a single space, collates class names for body element.
   585 	echo 'class="' . join( ' ', get_body_class( $class ) ) . '"';
   595 	echo 'class="' . esc_attr( join( ' ', get_body_class( $class ) ) ) . '"';
   586 }
   596 }
   587 
   597 
   588 /**
   598 /**
   589  * Retrieves an array of the class names for the body element.
   599  * Retrieves an array of the class names for the body element.
   590  *
   600  *
   591  * @since 2.8.0
   601  * @since 2.8.0
   592  *
   602  *
   593  * @global WP_Query $wp_query
   603  * @global WP_Query $wp_query WordPress Query object.
   594  *
   604  *
   595  * @param string|string[] $class Space-separated string or array of class names to add to the class list.
   605  * @param string|string[] $class Space-separated string or array of class names to add to the class list.
   596  * @return string[] Array of class names.
   606  * @return string[] Array of class names.
   597  */
   607  */
   598 function get_body_class( $class = '' ) {
   608 function get_body_class( $class = '' ) {
   656 			$classes[] = 'single';
   666 			$classes[] = 'single';
   657 			if ( isset( $post->post_type ) ) {
   667 			if ( isset( $post->post_type ) ) {
   658 				$classes[] = 'single-' . sanitize_html_class( $post->post_type, $post_id );
   668 				$classes[] = 'single-' . sanitize_html_class( $post->post_type, $post_id );
   659 				$classes[] = 'postid-' . $post_id;
   669 				$classes[] = 'postid-' . $post_id;
   660 
   670 
   661 				// Post Format
   671 				// Post Format.
   662 				if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
   672 				if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
   663 					$post_format = get_post_format( $post->ID );
   673 					$post_format = get_post_format( $post->ID );
   664 
   674 
   665 					if ( $post_format && ! is_wp_error( $post_format ) ) {
   675 					if ( $post_format && ! is_wp_error( $post_format ) ) {
   666 						$classes[] = 'single-format-' . sanitize_html_class( $post_format );
   676 						$classes[] = 'single-format-' . sanitize_html_class( $post_format );
   870 	 */
   880 	 */
   871 	return apply_filters( 'post_password_required', $required, $post );
   881 	return apply_filters( 'post_password_required', $required, $post );
   872 }
   882 }
   873 
   883 
   874 //
   884 //
   875 // Page Template Functions for usage in Themes
   885 // Page Template Functions for usage in Themes.
   876 //
   886 //
   877 
   887 
   878 /**
   888 /**
   879  * The formatted output of a list of pages.
   889  * The formatted output of a list of pages.
   880  *
   890  *
   927 		'previouspagelink' => __( 'Previous page' ),
   937 		'previouspagelink' => __( 'Previous page' ),
   928 		'pagelink'         => '%',
   938 		'pagelink'         => '%',
   929 		'echo'             => 1,
   939 		'echo'             => 1,
   930 	);
   940 	);
   931 
   941 
   932 	$params = wp_parse_args( $args, $defaults );
   942 	$parsed_args = wp_parse_args( $args, $defaults );
   933 
   943 
   934 	/**
   944 	/**
   935 	 * Filters the arguments used in retrieving page links for paginated posts.
   945 	 * Filters the arguments used in retrieving page links for paginated posts.
   936 	 *
   946 	 *
   937 	 * @since 3.0.0
   947 	 * @since 3.0.0
   938 	 *
   948 	 *
   939 	 * @param array $params An array of arguments for page links for paginated posts.
   949 	 * @param array $parsed_args An array of arguments for page links for paginated posts.
   940 	 */
   950 	 */
   941 	$r = apply_filters( 'wp_link_pages_args', $params );
   951 	$parsed_args = apply_filters( 'wp_link_pages_args', $parsed_args );
   942 
   952 
   943 	$output = '';
   953 	$output = '';
   944 	if ( $multipage ) {
   954 	if ( $multipage ) {
   945 		if ( 'number' == $r['next_or_number'] ) {
   955 		if ( 'number' === $parsed_args['next_or_number'] ) {
   946 			$output .= $r['before'];
   956 			$output .= $parsed_args['before'];
   947 			for ( $i = 1; $i <= $numpages; $i++ ) {
   957 			for ( $i = 1; $i <= $numpages; $i++ ) {
   948 				$link = $r['link_before'] . str_replace( '%', $i, $r['pagelink'] ) . $r['link_after'];
   958 				$link = $parsed_args['link_before'] . str_replace( '%', $i, $parsed_args['pagelink'] ) . $parsed_args['link_after'];
   949 				if ( $i != $page || ! $more && 1 == $page ) {
   959 				if ( $i != $page || ! $more && 1 == $page ) {
   950 					$link = _wp_link_page( $i ) . $link . '</a>';
   960 					$link = _wp_link_page( $i ) . $link . '</a>';
   951 				} elseif ( $i === $page ) {
   961 				} elseif ( $i === $page ) {
   952 					$link = '<span class="post-page-numbers current" aria-current="' . esc_attr( $r['aria_current'] ) . '">' . $link . '</span>';
   962 					$link = '<span class="post-page-numbers current" aria-current="' . esc_attr( $parsed_args['aria_current'] ) . '">' . $link . '</span>';
   953 				}
   963 				}
   954 				/**
   964 				/**
   955 				 * Filters the HTML output of individual page number links.
   965 				 * Filters the HTML output of individual page number links.
   956 				 *
   966 				 *
   957 				 * @since 3.6.0
   967 				 * @since 3.6.0
   960 				 * @param int    $i    Page number for paginated posts' page links.
   970 				 * @param int    $i    Page number for paginated posts' page links.
   961 				 */
   971 				 */
   962 				$link = apply_filters( 'wp_link_pages_link', $link, $i );
   972 				$link = apply_filters( 'wp_link_pages_link', $link, $i );
   963 
   973 
   964 				// Use the custom links separator beginning with the second link.
   974 				// Use the custom links separator beginning with the second link.
   965 				$output .= ( 1 === $i ) ? ' ' : $r['separator'];
   975 				$output .= ( 1 === $i ) ? ' ' : $parsed_args['separator'];
   966 				$output .= $link;
   976 				$output .= $link;
   967 			}
   977 			}
   968 			$output .= $r['after'];
   978 			$output .= $parsed_args['after'];
   969 		} elseif ( $more ) {
   979 		} elseif ( $more ) {
   970 			$output .= $r['before'];
   980 			$output .= $parsed_args['before'];
   971 			$prev    = $page - 1;
   981 			$prev    = $page - 1;
   972 			if ( $prev > 0 ) {
   982 			if ( $prev > 0 ) {
   973 				$link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '</a>';
   983 				$link = _wp_link_page( $prev ) . $parsed_args['link_before'] . $parsed_args['previouspagelink'] . $parsed_args['link_after'] . '</a>';
   974 
   984 
   975 				/** This filter is documented in wp-includes/post-template.php */
   985 				/** This filter is documented in wp-includes/post-template.php */
   976 				$output .= apply_filters( 'wp_link_pages_link', $link, $prev );
   986 				$output .= apply_filters( 'wp_link_pages_link', $link, $prev );
   977 			}
   987 			}
   978 			$next = $page + 1;
   988 			$next = $page + 1;
   979 			if ( $next <= $numpages ) {
   989 			if ( $next <= $numpages ) {
   980 				if ( $prev ) {
   990 				if ( $prev ) {
   981 					$output .= $r['separator'];
   991 					$output .= $parsed_args['separator'];
   982 				}
   992 				}
   983 				$link = _wp_link_page( $next ) . $r['link_before'] . $r['nextpagelink'] . $r['link_after'] . '</a>';
   993 				$link = _wp_link_page( $next ) . $parsed_args['link_before'] . $parsed_args['nextpagelink'] . $parsed_args['link_after'] . '</a>';
   984 
   994 
   985 				/** This filter is documented in wp-includes/post-template.php */
   995 				/** This filter is documented in wp-includes/post-template.php */
   986 				$output .= apply_filters( 'wp_link_pages_link', $link, $next );
   996 				$output .= apply_filters( 'wp_link_pages_link', $link, $next );
   987 			}
   997 			}
   988 			$output .= $r['after'];
   998 			$output .= $parsed_args['after'];
   989 		}
   999 		}
   990 	}
  1000 	}
   991 
  1001 
   992 	/**
  1002 	/**
   993 	 * Filters the HTML output of page links for paginated posts.
  1003 	 * Filters the HTML output of page links for paginated posts.
   997 	 * @param string $output HTML output of paginated posts' page links.
  1007 	 * @param string $output HTML output of paginated posts' page links.
   998 	 * @param array  $args   An array of arguments.
  1008 	 * @param array  $args   An array of arguments.
   999 	 */
  1009 	 */
  1000 	$html = apply_filters( 'wp_link_pages', $output, $args );
  1010 	$html = apply_filters( 'wp_link_pages', $output, $args );
  1001 
  1011 
  1002 	if ( $r['echo'] ) {
  1012 	if ( $parsed_args['echo'] ) {
  1003 		echo $html;
  1013 		echo $html;
  1004 	}
  1014 	}
  1005 	return $html;
  1015 	return $html;
  1006 }
  1016 }
  1007 
  1017 
  1009  * Helper function for wp_link_pages().
  1019  * Helper function for wp_link_pages().
  1010  *
  1020  *
  1011  * @since 3.1.0
  1021  * @since 3.1.0
  1012  * @access private
  1022  * @access private
  1013  *
  1023  *
  1014  * @global WP_Rewrite $wp_rewrite
  1024  * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
  1015  *
  1025  *
  1016  * @param int $i Page number.
  1026  * @param int $i Page number.
  1017  * @return string Link.
  1027  * @return string Link.
  1018  */
  1028  */
  1019 function _wp_link_page( $i ) {
  1029 function _wp_link_page( $i ) {
  1022 	$query_args = array();
  1032 	$query_args = array();
  1023 
  1033 
  1024 	if ( 1 == $i ) {
  1034 	if ( 1 == $i ) {
  1025 		$url = get_permalink();
  1035 		$url = get_permalink();
  1026 	} else {
  1036 	} else {
  1027 		if ( '' == get_option( 'permalink_structure' ) || in_array( $post->post_status, array( 'draft', 'pending' ) ) ) {
  1037 		if ( ! get_option( 'permalink_structure' ) || in_array( $post->post_status, array( 'draft', 'pending' ), true ) ) {
  1028 			$url = add_query_arg( 'page', $i, get_permalink() );
  1038 			$url = add_query_arg( 'page', $i, get_permalink() );
  1029 		} elseif ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) {
  1039 		} elseif ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) {
  1030 			$url = trailingslashit( get_permalink() ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $i, 'single_paged' );
  1040 			$url = trailingslashit( get_permalink() ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $i, 'single_paged' );
  1031 		} else {
  1041 		} else {
  1032 			$url = trailingslashit( get_permalink() ) . user_trailingslashit( $i, 'single_paged' );
  1042 			$url = trailingslashit( get_permalink() ) . user_trailingslashit( $i, 'single_paged' );
  1033 		}
  1043 		}
  1034 	}
  1044 	}
  1054  * Retrieve post custom meta data field.
  1064  * Retrieve post custom meta data field.
  1055  *
  1065  *
  1056  * @since 1.5.0
  1066  * @since 1.5.0
  1057  *
  1067  *
  1058  * @param string $key Meta data key name.
  1068  * @param string $key Meta data key name.
  1059  * @return false|string|array Array of values or single value, if only one element exists. False will be returned if key does not exist.
  1069  * @return array|string|false Array of values, or single value if only one element exists.
       
  1070  *                            False if the key does not exist.
  1060  */
  1071  */
  1061 function post_custom( $key = '' ) {
  1072 function post_custom( $key = '' ) {
  1062 	$custom = get_post_custom();
  1073 	$custom = get_post_custom();
  1063 
  1074 
  1064 	if ( ! isset( $custom[ $key ] ) ) {
  1075 	if ( ! isset( $custom[ $key ] ) ) {
  1065 		return false;
  1076 		return false;
  1066 	} elseif ( 1 == count( $custom[ $key ] ) ) {
  1077 	} elseif ( 1 === count( $custom[ $key ] ) ) {
  1067 		return $custom[ $key ][0];
  1078 		return $custom[ $key ][0];
  1068 	} else {
  1079 	} else {
  1069 		return $custom[ $key ];
  1080 		return $custom[ $key ];
  1070 	}
  1081 	}
  1071 }
  1082 }
  1076  * @since 1.2.0
  1087  * @since 1.2.0
  1077  *
  1088  *
  1078  * @internal This will probably change at some point...
  1089  * @internal This will probably change at some point...
  1079  */
  1090  */
  1080 function the_meta() {
  1091 function the_meta() {
  1081 	if ( $keys = get_post_custom_keys() ) {
  1092 	$keys = get_post_custom_keys();
       
  1093 	if ( $keys ) {
  1082 		$li_html = '';
  1094 		$li_html = '';
  1083 		foreach ( (array) $keys as $key ) {
  1095 		foreach ( (array) $keys as $key ) {
  1084 			$keyt = trim( $key );
  1096 			$keyt = trim( $key );
  1085 			if ( is_protected_meta( $keyt, 'post' ) ) {
  1097 			if ( is_protected_meta( $keyt, 'post' ) ) {
  1086 				continue;
  1098 				continue;
  1087 			}
  1099 			}
  1088 
  1100 
  1089 			$values = array_map( 'trim', get_post_custom_values( $key ) );
  1101 			$values = array_map( 'trim', get_post_custom_values( $key ) );
  1090 			$value  = implode( $values, ', ' );
  1102 			$value  = implode( ', ', $values );
  1091 
  1103 
  1092 			$html = sprintf(
  1104 			$html = sprintf(
  1093 				"<li><span class='post-meta-key'>%s</span> %s</li>\n",
  1105 				"<li><span class='post-meta-key'>%s</span> %s</li>\n",
  1094 				/* translators: %s: Post custom field name */
  1106 				/* translators: %s: Post custom field name. */
  1095 				sprintf( _x( '%s:', 'Post custom field name' ), $key ),
  1107 				sprintf( _x( '%s:', 'Post custom field name' ), $key ),
  1096 				$value
  1108 				$value
  1097 			);
  1109 			);
  1098 
  1110 
  1099 			/**
  1111 			/**
  1113 		}
  1125 		}
  1114 	}
  1126 	}
  1115 }
  1127 }
  1116 
  1128 
  1117 //
  1129 //
  1118 // Pages
  1130 // Pages.
  1119 //
  1131 //
  1120 
  1132 
  1121 /**
  1133 /**
  1122  * Retrieve or display a list of pages as a dropdown (select list).
  1134  * Retrieve or display a list of pages as a dropdown (select list).
  1123  *
  1135  *
  1144  *     @type string       $show_option_no_change Text to display for "no change" option. Default empty (does not display).
  1156  *     @type string       $show_option_no_change Text to display for "no change" option. Default empty (does not display).
  1145  *     @type string       $option_none_value     Value to use when no page is selected. Default empty.
  1157  *     @type string       $option_none_value     Value to use when no page is selected. Default empty.
  1146  *     @type string       $value_field           Post field used to populate the 'value' attribute of the option
  1158  *     @type string       $value_field           Post field used to populate the 'value' attribute of the option
  1147  *                                               elements. Accepts any valid post field. Default 'ID'.
  1159  *                                               elements. Accepts any valid post field. Default 'ID'.
  1148  * }
  1160  * }
  1149  * @return string HTML content, if not displaying.
  1161  * @return string HTML dropdown list of pages.
  1150  */
  1162  */
  1151 function wp_dropdown_pages( $args = '' ) {
  1163 function wp_dropdown_pages( $args = '' ) {
  1152 	$defaults = array(
  1164 	$defaults = array(
  1153 		'depth'                 => 0,
  1165 		'depth'                 => 0,
  1154 		'child_of'              => 0,
  1166 		'child_of'              => 0,
  1161 		'show_option_no_change' => '',
  1173 		'show_option_no_change' => '',
  1162 		'option_none_value'     => '',
  1174 		'option_none_value'     => '',
  1163 		'value_field'           => 'ID',
  1175 		'value_field'           => 'ID',
  1164 	);
  1176 	);
  1165 
  1177 
  1166 	$r = wp_parse_args( $args, $defaults );
  1178 	$parsed_args = wp_parse_args( $args, $defaults );
  1167 
  1179 
  1168 	$pages  = get_pages( $r );
  1180 	$pages  = get_pages( $parsed_args );
  1169 	$output = '';
  1181 	$output = '';
  1170 	// Back-compat with old system where both id and name were based on $name argument
  1182 	// Back-compat with old system where both id and name were based on $name argument.
  1171 	if ( empty( $r['id'] ) ) {
  1183 	if ( empty( $parsed_args['id'] ) ) {
  1172 		$r['id'] = $r['name'];
  1184 		$parsed_args['id'] = $parsed_args['name'];
  1173 	}
  1185 	}
  1174 
  1186 
  1175 	if ( ! empty( $pages ) ) {
  1187 	if ( ! empty( $pages ) ) {
  1176 		$class = '';
  1188 		$class = '';
  1177 		if ( ! empty( $r['class'] ) ) {
  1189 		if ( ! empty( $parsed_args['class'] ) ) {
  1178 			$class = " class='" . esc_attr( $r['class'] ) . "'";
  1190 			$class = " class='" . esc_attr( $parsed_args['class'] ) . "'";
  1179 		}
  1191 		}
  1180 
  1192 
  1181 		$output = "<select name='" . esc_attr( $r['name'] ) . "'" . $class . " id='" . esc_attr( $r['id'] ) . "'>\n";
  1193 		$output = "<select name='" . esc_attr( $parsed_args['name'] ) . "'" . $class . " id='" . esc_attr( $parsed_args['id'] ) . "'>\n";
  1182 		if ( $r['show_option_no_change'] ) {
  1194 		if ( $parsed_args['show_option_no_change'] ) {
  1183 			$output .= "\t<option value=\"-1\">" . $r['show_option_no_change'] . "</option>\n";
  1195 			$output .= "\t<option value=\"-1\">" . $parsed_args['show_option_no_change'] . "</option>\n";
  1184 		}
  1196 		}
  1185 		if ( $r['show_option_none'] ) {
  1197 		if ( $parsed_args['show_option_none'] ) {
  1186 			$output .= "\t<option value=\"" . esc_attr( $r['option_none_value'] ) . '">' . $r['show_option_none'] . "</option>\n";
  1198 			$output .= "\t<option value=\"" . esc_attr( $parsed_args['option_none_value'] ) . '">' . $parsed_args['show_option_none'] . "</option>\n";
  1187 		}
  1199 		}
  1188 		$output .= walk_page_dropdown_tree( $pages, $r['depth'], $r );
  1200 		$output .= walk_page_dropdown_tree( $pages, $parsed_args['depth'], $parsed_args );
  1189 		$output .= "</select>\n";
  1201 		$output .= "</select>\n";
  1190 	}
  1202 	}
  1191 
  1203 
  1192 	/**
  1204 	/**
  1193 	 * Filters the HTML output of a list of pages as a drop down.
  1205 	 * Filters the HTML output of a list of pages as a drop down.
  1194 	 *
  1206 	 *
  1195 	 * @since 2.1.0
  1207 	 * @since 2.1.0
  1196 	 * @since 4.4.0 `$r` and `$pages` added as arguments.
  1208 	 * @since 4.4.0 `$parsed_args` and `$pages` added as arguments.
  1197 	 *
  1209 	 *
  1198 	 * @param string $output HTML output for drop down list of pages.
  1210 	 * @param string    $output      HTML output for drop down list of pages.
  1199 	 * @param array  $r      The parsed arguments array.
  1211 	 * @param array     $parsed_args The parsed arguments array.
  1200 	 * @param array  $pages  List of WP_Post objects returned by `get_pages()`
  1212 	 * @param WP_Post[] $pages       Array of the page objects.
  1201 	 */
  1213 	 */
  1202 	$html = apply_filters( 'wp_dropdown_pages', $output, $r, $pages );
  1214 	$html = apply_filters( 'wp_dropdown_pages', $output, $parsed_args, $pages );
  1203 
  1215 
  1204 	if ( $r['echo'] ) {
  1216 	if ( $parsed_args['echo'] ) {
  1205 		echo $html;
  1217 		echo $html;
  1206 	}
  1218 	}
       
  1219 
  1207 	return $html;
  1220 	return $html;
  1208 }
  1221 }
  1209 
  1222 
  1210 /**
  1223 /**
  1211  * Retrieve or display a list of pages (or hierarchical post type items) in list (li) format.
  1224  * Retrieve or display a list of pages (or hierarchical post type items) in list (li) format.
  1213  * @since 1.5.0
  1226  * @since 1.5.0
  1214  * @since 4.7.0 Added the `item_spacing` argument.
  1227  * @since 4.7.0 Added the `item_spacing` argument.
  1215  *
  1228  *
  1216  * @see get_pages()
  1229  * @see get_pages()
  1217  *
  1230  *
  1218  * @global WP_Query $wp_query
  1231  * @global WP_Query $wp_query WordPress Query object.
  1219  *
  1232  *
  1220  * @param array|string $args {
  1233  * @param array|string $args {
  1221  *     Optional. Array or string of arguments to generate a list of pages. See `get_pages()` for additional arguments.
  1234  *     Optional. Array or string of arguments to generate a list of pages. See `get_pages()` for additional arguments.
  1222  *
  1235  *
  1223  *     @type int          $child_of     Display only the sub-pages of a single page by ID. Default 0 (all pages).
  1236  *     @type int          $child_of     Display only the sub-pages of a single page by ID. Default 0 (all pages).
  1243  *                                      will not be wrapped with unordered list `<ul>` tags. Default 'Pages'.
  1256  *                                      will not be wrapped with unordered list `<ul>` tags. Default 'Pages'.
  1244  *     @type string       $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve' or 'discard'.
  1257  *     @type string       $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve' or 'discard'.
  1245  *                                      Default 'preserve'.
  1258  *                                      Default 'preserve'.
  1246  *     @type Walker       $walker       Walker instance to use for listing pages. Default empty (Walker_Page).
  1259  *     @type Walker       $walker       Walker instance to use for listing pages. Default empty (Walker_Page).
  1247  * }
  1260  * }
  1248  * @return string|void HTML list of pages.
  1261  * @return void|string Void if 'echo' argument is true, HTML list of pages if 'echo' is false.
  1249  */
  1262  */
  1250 function wp_list_pages( $args = '' ) {
  1263 function wp_list_pages( $args = '' ) {
  1251 	$defaults = array(
  1264 	$defaults = array(
  1252 		'depth'        => 0,
  1265 		'depth'        => 0,
  1253 		'show_date'    => '',
  1266 		'show_date'    => '',
  1262 		'link_after'   => '',
  1275 		'link_after'   => '',
  1263 		'item_spacing' => 'preserve',
  1276 		'item_spacing' => 'preserve',
  1264 		'walker'       => '',
  1277 		'walker'       => '',
  1265 	);
  1278 	);
  1266 
  1279 
  1267 	$r = wp_parse_args( $args, $defaults );
  1280 	$parsed_args = wp_parse_args( $args, $defaults );
  1268 
  1281 
  1269 	if ( ! in_array( $r['item_spacing'], array( 'preserve', 'discard' ), true ) ) {
  1282 	if ( ! in_array( $parsed_args['item_spacing'], array( 'preserve', 'discard' ), true ) ) {
  1270 		// invalid value, fall back to default.
  1283 		// Invalid value, fall back to default.
  1271 		$r['item_spacing'] = $defaults['item_spacing'];
  1284 		$parsed_args['item_spacing'] = $defaults['item_spacing'];
  1272 	}
  1285 	}
  1273 
  1286 
  1274 	$output       = '';
  1287 	$output       = '';
  1275 	$current_page = 0;
  1288 	$current_page = 0;
  1276 
  1289 
  1277 	// sanitize, mostly to keep spaces out
  1290 	// Sanitize, mostly to keep spaces out.
  1278 	$r['exclude'] = preg_replace( '/[^0-9,]/', '', $r['exclude'] );
  1291 	$parsed_args['exclude'] = preg_replace( '/[^0-9,]/', '', $parsed_args['exclude'] );
  1279 
  1292 
  1280 	// Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array)
  1293 	// Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array).
  1281 	$exclude_array = ( $r['exclude'] ) ? explode( ',', $r['exclude'] ) : array();
  1294 	$exclude_array = ( $parsed_args['exclude'] ) ? explode( ',', $parsed_args['exclude'] ) : array();
  1282 
  1295 
  1283 	/**
  1296 	/**
  1284 	 * Filters the array of pages to exclude from the pages list.
  1297 	 * Filters the array of pages to exclude from the pages list.
  1285 	 *
  1298 	 *
  1286 	 * @since 2.1.0
  1299 	 * @since 2.1.0
  1287 	 *
  1300 	 *
  1288 	 * @param array $exclude_array An array of page IDs to exclude.
  1301 	 * @param string[] $exclude_array An array of page IDs to exclude.
  1289 	 */
  1302 	 */
  1290 	$r['exclude'] = implode( ',', apply_filters( 'wp_list_pages_excludes', $exclude_array ) );
  1303 	$parsed_args['exclude'] = implode( ',', apply_filters( 'wp_list_pages_excludes', $exclude_array ) );
       
  1304 
       
  1305 	$parsed_args['hierarchical'] = 0;
  1291 
  1306 
  1292 	// Query pages.
  1307 	// Query pages.
  1293 	$r['hierarchical'] = 0;
  1308 	$pages = get_pages( $parsed_args );
  1294 	$pages             = get_pages( $r );
       
  1295 
  1309 
  1296 	if ( ! empty( $pages ) ) {
  1310 	if ( ! empty( $pages ) ) {
  1297 		if ( $r['title_li'] ) {
  1311 		if ( $parsed_args['title_li'] ) {
  1298 			$output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
  1312 			$output .= '<li class="pagenav">' . $parsed_args['title_li'] . '<ul>';
  1299 		}
  1313 		}
  1300 		global $wp_query;
  1314 		global $wp_query;
  1301 		if ( is_page() || is_attachment() || $wp_query->is_posts_page ) {
  1315 		if ( is_page() || is_attachment() || $wp_query->is_posts_page ) {
  1302 			$current_page = get_queried_object_id();
  1316 			$current_page = get_queried_object_id();
  1303 		} elseif ( is_singular() ) {
  1317 		} elseif ( is_singular() ) {
  1305 			if ( is_post_type_hierarchical( $queried_object->post_type ) ) {
  1319 			if ( is_post_type_hierarchical( $queried_object->post_type ) ) {
  1306 				$current_page = $queried_object->ID;
  1320 				$current_page = $queried_object->ID;
  1307 			}
  1321 			}
  1308 		}
  1322 		}
  1309 
  1323 
  1310 		$output .= walk_page_tree( $pages, $r['depth'], $current_page, $r );
  1324 		$output .= walk_page_tree( $pages, $parsed_args['depth'], $current_page, $parsed_args );
  1311 
  1325 
  1312 		if ( $r['title_li'] ) {
  1326 		if ( $parsed_args['title_li'] ) {
  1313 			$output .= '</ul></li>';
  1327 			$output .= '</ul></li>';
  1314 		}
  1328 		}
  1315 	}
  1329 	}
  1316 
  1330 
  1317 	/**
  1331 	/**
  1320 	 * @since 1.5.1
  1334 	 * @since 1.5.1
  1321 	 * @since 4.4.0 `$pages` added as arguments.
  1335 	 * @since 4.4.0 `$pages` added as arguments.
  1322 	 *
  1336 	 *
  1323 	 * @see wp_list_pages()
  1337 	 * @see wp_list_pages()
  1324 	 *
  1338 	 *
  1325 	 * @param string $output HTML output of the pages list.
  1339 	 * @param string    $output      HTML output of the pages list.
  1326 	 * @param array  $r      An array of page-listing arguments.
  1340 	 * @param array     $parsed_args An array of page-listing arguments.
  1327 	 * @param array  $pages  List of WP_Post objects returned by `get_pages()`
  1341 	 * @param WP_Post[] $pages       Array of the page objects.
  1328 	 */
  1342 	 */
  1329 	$html = apply_filters( 'wp_list_pages', $output, $r, $pages );
  1343 	$html = apply_filters( 'wp_list_pages', $output, $parsed_args, $pages );
  1330 
  1344 
  1331 	if ( $r['echo'] ) {
  1345 	if ( $parsed_args['echo'] ) {
  1332 		echo $html;
  1346 		echo $html;
  1333 	} else {
  1347 	} else {
  1334 		return $html;
  1348 		return $html;
  1335 	}
  1349 	}
  1336 }
  1350 }
  1363  *     @type string          $after        The HTML or text to append to the menu. Default is '</ul>'.
  1377  *     @type string          $after        The HTML or text to append to the menu. Default is '</ul>'.
  1364  *     @type string          $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve'
  1378  *     @type string          $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve'
  1365  *                                         or 'discard'. Default 'discard'.
  1379  *                                         or 'discard'. Default 'discard'.
  1366  *     @type Walker          $walker       Walker instance to use for listing pages. Default empty (Walker_Page).
  1380  *     @type Walker          $walker       Walker instance to use for listing pages. Default empty (Walker_Page).
  1367  * }
  1381  * }
  1368  * @return string|void HTML menu
  1382  * @return void|string Void if 'echo' argument is true, HTML menu if 'echo' is false.
  1369  */
  1383  */
  1370 function wp_page_menu( $args = array() ) {
  1384 function wp_page_menu( $args = array() ) {
  1371 	$defaults = array(
  1385 	$defaults = array(
  1372 		'sort_column'  => 'menu_order, post_title',
  1386 		'sort_column'  => 'menu_order, post_title',
  1373 		'menu_id'      => '',
  1387 		'menu_id'      => '',
  1381 		'item_spacing' => 'discard',
  1395 		'item_spacing' => 'discard',
  1382 		'walker'       => '',
  1396 		'walker'       => '',
  1383 	);
  1397 	);
  1384 	$args     = wp_parse_args( $args, $defaults );
  1398 	$args     = wp_parse_args( $args, $defaults );
  1385 
  1399 
  1386 	if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ) ) ) {
  1400 	if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ), true ) ) {
  1387 		// invalid value, fall back to default.
  1401 		// Invalid value, fall back to default.
  1388 		$args['item_spacing'] = $defaults['item_spacing'];
  1402 		$args['item_spacing'] = $defaults['item_spacing'];
  1389 	}
  1403 	}
  1390 
  1404 
  1391 	if ( 'preserve' === $args['item_spacing'] ) {
  1405 	if ( 'preserve' === $args['item_spacing'] ) {
  1392 		$t = "\t";
  1406 		$t = "\t";
  1409 
  1423 
  1410 	$menu = '';
  1424 	$menu = '';
  1411 
  1425 
  1412 	$list_args = $args;
  1426 	$list_args = $args;
  1413 
  1427 
  1414 	// Show Home in the menu
  1428 	// Show Home in the menu.
  1415 	if ( ! empty( $args['show_home'] ) ) {
  1429 	if ( ! empty( $args['show_home'] ) ) {
  1416 		if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) {
  1430 		if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) {
  1417 			$text = __( 'Home' );
  1431 			$text = __( 'Home' );
  1418 		} else {
  1432 		} else {
  1419 			$text = $args['show_home'];
  1433 			$text = $args['show_home'];
  1421 		$class = '';
  1435 		$class = '';
  1422 		if ( is_front_page() && ! is_paged() ) {
  1436 		if ( is_front_page() && ! is_paged() ) {
  1423 			$class = 'class="current_page_item"';
  1437 			$class = 'class="current_page_item"';
  1424 		}
  1438 		}
  1425 		$menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
  1439 		$menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
  1426 		// If the front page is a page, add it to the exclude list
  1440 		// If the front page is a page, add it to the exclude list.
  1427 		if ( get_option( 'show_on_front' ) == 'page' ) {
  1441 		if ( 'page' === get_option( 'show_on_front' ) ) {
  1428 			if ( ! empty( $list_args['exclude'] ) ) {
  1442 			if ( ! empty( $list_args['exclude'] ) ) {
  1429 				$list_args['exclude'] .= ',';
  1443 				$list_args['exclude'] .= ',';
  1430 			} else {
  1444 			} else {
  1431 				$list_args['exclude'] = '';
  1445 				$list_args['exclude'] = '';
  1432 			}
  1446 			}
  1445 		$container = 'div';
  1459 		$container = 'div';
  1446 	}
  1460 	}
  1447 
  1461 
  1448 	if ( $menu ) {
  1462 	if ( $menu ) {
  1449 
  1463 
  1450 		// wp_nav_menu doesn't set before and after
  1464 		// wp_nav_menu() doesn't set before and after.
  1451 		if ( isset( $args['fallback_cb'] ) &&
  1465 		if ( isset( $args['fallback_cb'] ) &&
  1452 			'wp_page_menu' === $args['fallback_cb'] &&
  1466 			'wp_page_menu' === $args['fallback_cb'] &&
  1453 			'ul' !== $container ) {
  1467 			'ul' !== $container ) {
  1454 			$args['before'] = "<ul>{$n}";
  1468 			$args['before'] = "<ul>{$n}";
  1455 			$args['after']  = '</ul>';
  1469 			$args['after']  = '</ul>';
  1478 	 *
  1492 	 *
  1479 	 * @param string $menu The HTML output.
  1493 	 * @param string $menu The HTML output.
  1480 	 * @param array  $args An array of arguments.
  1494 	 * @param array  $args An array of arguments.
  1481 	 */
  1495 	 */
  1482 	$menu = apply_filters( 'wp_page_menu', $menu, $args );
  1496 	$menu = apply_filters( 'wp_page_menu', $menu, $args );
       
  1497 
  1483 	if ( $args['echo'] ) {
  1498 	if ( $args['echo'] ) {
  1484 		echo $menu;
  1499 		echo $menu;
  1485 	} else {
  1500 	} else {
  1486 		return $menu;
  1501 		return $menu;
  1487 	}
  1502 	}
  1488 }
  1503 }
  1489 
  1504 
  1490 //
  1505 //
  1491 // Page helpers
  1506 // Page helpers.
  1492 //
  1507 //
  1493 
  1508 
  1494 /**
  1509 /**
  1495  * Retrieve HTML list content for page list.
  1510  * Retrieve HTML list content for page list.
  1496  *
  1511  *
  1505  */
  1520  */
  1506 function walk_page_tree( $pages, $depth, $current_page, $r ) {
  1521 function walk_page_tree( $pages, $depth, $current_page, $r ) {
  1507 	if ( empty( $r['walker'] ) ) {
  1522 	if ( empty( $r['walker'] ) ) {
  1508 		$walker = new Walker_Page;
  1523 		$walker = new Walker_Page;
  1509 	} else {
  1524 	} else {
       
  1525 		/**
       
  1526 		 * @var Walker $walker
       
  1527 		 */
  1510 		$walker = $r['walker'];
  1528 		$walker = $r['walker'];
  1511 	}
  1529 	}
  1512 
  1530 
  1513 	foreach ( (array) $pages as $page ) {
  1531 	foreach ( (array) $pages as $page ) {
  1514 		if ( $page->post_parent ) {
  1532 		if ( $page->post_parent ) {
  1515 			$r['pages_with_children'][ $page->post_parent ] = true;
  1533 			$r['pages_with_children'][ $page->post_parent ] = true;
  1516 		}
  1534 		}
  1517 	}
  1535 	}
  1518 
  1536 
  1519 	$args = array( $pages, $depth, $r, $current_page );
  1537 	return $walker->walk( $pages, $depth, $r, $current_page );
  1520 	return call_user_func_array( array( $walker, 'walk' ), $args );
       
  1521 }
  1538 }
  1522 
  1539 
  1523 /**
  1540 /**
  1524  * Retrieve HTML dropdown (select) content for page list.
  1541  * Retrieve HTML dropdown (select) content for page list.
  1525  *
  1542  *
       
  1543  * @since 2.1.0
       
  1544  * @since 5.3.0 Formalized the existing `...$args` parameter by adding it
       
  1545  *              to the function signature.
       
  1546  *
  1526  * @uses Walker_PageDropdown to create HTML dropdown content.
  1547  * @uses Walker_PageDropdown to create HTML dropdown content.
  1527  * @since 2.1.0
       
  1528  * @see Walker_PageDropdown::walk() for parameters and return description.
  1548  * @see Walker_PageDropdown::walk() for parameters and return description.
  1529  *
  1549  *
       
  1550  * @param mixed ...$args Elements array, maximum hierarchical depth and optional additional arguments.
  1530  * @return string
  1551  * @return string
  1531  */
  1552  */
  1532 function walk_page_dropdown_tree() {
  1553 function walk_page_dropdown_tree( ...$args ) {
  1533 	$args = func_get_args();
  1554 	if ( empty( $args[2]['walker'] ) ) { // The user's options are the third parameter.
  1534 	if ( empty( $args[2]['walker'] ) ) { // the user's options are the third parameter
       
  1535 		$walker = new Walker_PageDropdown;
  1555 		$walker = new Walker_PageDropdown;
  1536 	} else {
  1556 	} else {
       
  1557 		/**
       
  1558 		 * @var Walker $walker
       
  1559 		 */
  1537 		$walker = $args[2]['walker'];
  1560 		$walker = $args[2]['walker'];
  1538 	}
  1561 	}
  1539 
  1562 
  1540 	return call_user_func_array( array( $walker, 'walk' ), $args );
  1563 	return $walker->walk( ...$args );
  1541 }
  1564 }
  1542 
  1565 
  1543 //
  1566 //
  1544 // Attachments
  1567 // Attachments.
  1545 //
  1568 //
  1546 
  1569 
  1547 /**
  1570 /**
  1548  * Display an attachment page link using an image or icon.
  1571  * Display an attachment page link using an image or icon.
  1549  *
  1572  *
  1550  * @since 2.0.0
  1573  * @since 2.0.0
  1551  *
  1574  *
  1552  * @param int|WP_Post $id Optional. Post ID or post object.
  1575  * @param int|WP_Post $id Optional. Post ID or post object.
  1553  * @param bool        $fullsize     Optional, default is false. Whether to use full size.
  1576  * @param bool        $fullsize     Optional. Whether to use full size. Default false.
  1554  * @param bool        $deprecated   Deprecated. Not used.
  1577  * @param bool        $deprecated   Deprecated. Not used.
  1555  * @param bool        $permalink    Optional, default is false. Whether to include permalink.
  1578  * @param bool        $permalink    Optional. Whether to include permalink. Default false.
  1556  */
  1579  */
  1557 function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) {
  1580 function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) {
  1558 	if ( ! empty( $deprecated ) ) {
  1581 	if ( ! empty( $deprecated ) ) {
  1559 		_deprecated_argument( __FUNCTION__, '2.5.0' );
  1582 		_deprecated_argument( __FUNCTION__, '2.5.0' );
  1560 	}
  1583 	}
  1574  *
  1597  *
  1575  * @param int|WP_Post  $id        Optional. Post ID or post object.
  1598  * @param int|WP_Post  $id        Optional. Post ID or post object.
  1576  * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
  1599  * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
  1577  *                                of width and height values in pixels (in that order).
  1600  *                                of width and height values in pixels (in that order).
  1578  *                                Default 'thumbnail'.
  1601  *                                Default 'thumbnail'.
  1579  * @param bool         $permalink Optional, Whether to add permalink to image. Default false.
  1602  * @param bool         $permalink Optional. Whether to add permalink to image. Default false.
  1580  * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
  1603  * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
  1581  * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
  1604  * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
  1582  *                                Default false.
  1605  *                                Default false.
  1583  * @param array|string $attr      Optional. Array or string of attributes. Default empty.
  1606  * @param array|string $attr      Optional. Array or string of attributes. Default empty.
  1584  * @return string HTML content.
  1607  * @return string HTML content.
  1585  */
  1608  */
  1586 function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) {
  1609 function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) {
  1587 	$_post = get_post( $id );
  1610 	$_post = get_post( $id );
  1588 
  1611 
  1589 	if ( empty( $_post ) || ( 'attachment' !== $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) ) {
  1612 	if ( empty( $_post ) || ( 'attachment' !== $_post->post_type ) || ! wp_get_attachment_url( $_post->ID ) ) {
  1590 		return __( 'Missing Attachment' );
  1613 		return __( 'Missing Attachment' );
  1591 	}
  1614 	}
       
  1615 
       
  1616 	$url = wp_get_attachment_url( $_post->ID );
  1592 
  1617 
  1593 	if ( $permalink ) {
  1618 	if ( $permalink ) {
  1594 		$url = get_attachment_link( $_post->ID );
  1619 		$url = get_attachment_link( $_post->ID );
  1595 	}
  1620 	}
  1596 
  1621 
  1597 	if ( $text ) {
  1622 	if ( $text ) {
  1598 		$link_text = $text;
  1623 		$link_text = $text;
  1599 	} elseif ( $size && 'none' != $size ) {
  1624 	} elseif ( $size && 'none' !== $size ) {
  1600 		$link_text = wp_get_attachment_image( $_post->ID, $size, $icon, $attr );
  1625 		$link_text = wp_get_attachment_image( $_post->ID, $size, $icon, $attr );
  1601 	} else {
  1626 	} else {
  1602 		$link_text = '';
  1627 		$link_text = '';
  1603 	}
  1628 	}
  1604 
  1629 
  1636  * @return string
  1661  * @return string
  1637  */
  1662  */
  1638 function prepend_attachment( $content ) {
  1663 function prepend_attachment( $content ) {
  1639 	$post = get_post();
  1664 	$post = get_post();
  1640 
  1665 
  1641 	if ( empty( $post->post_type ) || $post->post_type != 'attachment' ) {
  1666 	if ( empty( $post->post_type ) || 'attachment' !== $post->post_type ) {
  1642 		return $content;
  1667 		return $content;
  1643 	}
  1668 	}
  1644 
  1669 
  1645 	if ( wp_attachment_is( 'video', $post ) ) {
  1670 	if ( wp_attachment_is( 'video', $post ) ) {
  1646 		$meta = wp_get_attachment_metadata( get_the_ID() );
  1671 		$meta = wp_get_attachment_metadata( get_the_ID() );
  1655 		$p = wp_video_shortcode( $atts );
  1680 		$p = wp_video_shortcode( $atts );
  1656 	} elseif ( wp_attachment_is( 'audio', $post ) ) {
  1681 	} elseif ( wp_attachment_is( 'audio', $post ) ) {
  1657 		$p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) );
  1682 		$p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) );
  1658 	} else {
  1683 	} else {
  1659 		$p = '<p class="attachment">';
  1684 		$p = '<p class="attachment">';
  1660 		// show the medium sized image representation of the attachment if available, and link to the raw file
  1685 		// Show the medium sized image representation of the attachment if available, and link to the raw file.
  1661 		$p .= wp_get_attachment_link( 0, 'medium', false );
  1686 		$p .= wp_get_attachment_link( 0, 'medium', false );
  1662 		$p .= '</p>';
  1687 		$p .= '</p>';
  1663 	}
  1688 	}
  1664 
  1689 
  1665 	/**
  1690 	/**
  1675 
  1700 
  1676 	return "$p\n$content";
  1701 	return "$p\n$content";
  1677 }
  1702 }
  1678 
  1703 
  1679 //
  1704 //
  1680 // Misc
  1705 // Misc.
  1681 //
  1706 //
  1682 
  1707 
  1683 /**
  1708 /**
  1684  * Retrieve protected post password form content.
  1709  * Retrieve protected post password form content.
  1685  *
  1710  *
  1712 
  1737 
  1713 /**
  1738 /**
  1714  * Determines whether currently in a page template.
  1739  * Determines whether currently in a page template.
  1715  *
  1740  *
  1716  * This template tag allows you to determine if you are in a page template.
  1741  * This template tag allows you to determine if you are in a page template.
  1717  * You can optionally provide a template name or array of template names
  1742  * You can optionally provide a template filename or array of template filenames
  1718  * and then the check will be specific to that template.
  1743  * and then the check will be specific to that template.
  1719  *
  1744  *
  1720  * For more information on this and similar theme functions, check out
  1745  * For more information on this and similar theme functions, check out
  1721  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
  1746  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
  1722  * Conditional Tags} article in the Theme Developer Handbook.
  1747  * Conditional Tags} article in the Theme Developer Handbook.
  1723  *
  1748  *
  1724  * @since 2.5.0
  1749  * @since 2.5.0
  1725  * @since 4.2.0 The `$template` parameter was changed to also accept an array of page templates.
  1750  * @since 4.2.0 The `$template` parameter was changed to also accept an array of page templates.
  1726  * @since 4.7.0 Now works with any post type, not just pages.
  1751  * @since 4.7.0 Now works with any post type, not just pages.
  1727  *
  1752  *
  1728  * @param string|array $template The specific template name or array of templates to match.
  1753  * @param string|array $template The specific template filename or array of templates to match.
  1729  * @return bool True on success, false on failure.
  1754  * @return bool True on success, false on failure.
  1730  */
  1755  */
  1731 function is_page_template( $template = '' ) {
  1756 function is_page_template( $template = '' ) {
  1732 	if ( ! is_singular() ) {
  1757 	if ( ! is_singular() ) {
  1733 		return false;
  1758 		return false;
  1753 
  1778 
  1754 	return ( 'default' === $template && ! $page_template );
  1779 	return ( 'default' === $template && ! $page_template );
  1755 }
  1780 }
  1756 
  1781 
  1757 /**
  1782 /**
  1758  * Get the specific template name for a given post.
  1783  * Get the specific template filename for a given post.
  1759  *
  1784  *
  1760  * @since 3.4.0
  1785  * @since 3.4.0
  1761  * @since 4.7.0 Now works with any post type, not just pages.
  1786  * @since 4.7.0 Now works with any post type, not just pages.
  1762  *
  1787  *
  1763  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
  1788  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
  1764  * @return string|false Page template filename. Returns an empty string when the default page template
  1789  * @return string|false Page template filename. Returns an empty string when the default page template
  1765  *  is in use. Returns false if the post does not exist.
  1790  *                      is in use. Returns false if the post does not exist.
  1766  */
  1791  */
  1767 function get_page_template_slug( $post = null ) {
  1792 function get_page_template_slug( $post = null ) {
  1768 	$post = get_post( $post );
  1793 	$post = get_post( $post );
  1769 
  1794 
  1770 	if ( ! $post ) {
  1795 	if ( ! $post ) {
  1771 		return false;
  1796 		return false;
  1772 	}
  1797 	}
  1773 
  1798 
  1774 	$template = get_post_meta( $post->ID, '_wp_page_template', true );
  1799 	$template = get_post_meta( $post->ID, '_wp_page_template', true );
  1775 
  1800 
  1776 	if ( ! $template || 'default' == $template ) {
  1801 	if ( ! $template || 'default' === $template ) {
  1777 		return '';
  1802 		return '';
  1778 	}
  1803 	}
  1779 
  1804 
  1780 	return $template;
  1805 	return $template;
  1781 }
  1806 }
  1784  * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
  1809  * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
  1785  *
  1810  *
  1786  * @since 2.6.0
  1811  * @since 2.6.0
  1787  *
  1812  *
  1788  * @param int|object $revision Revision ID or revision object.
  1813  * @param int|object $revision Revision ID or revision object.
  1789  * @param bool       $link     Optional, default is true. Link to revisions's page?
  1814  * @param bool       $link     Optional. Whether to link to revision's page. Default true.
  1790  * @return string|false i18n formatted datetimestamp or localized 'Current Revision'.
  1815  * @return string|false i18n formatted datetimestamp or localized 'Current Revision'.
  1791  */
  1816  */
  1792 function wp_post_revision_title( $revision, $link = true ) {
  1817 function wp_post_revision_title( $revision, $link = true ) {
  1793 	if ( ! $revision = get_post( $revision ) ) {
  1818 	$revision = get_post( $revision );
       
  1819 	if ( ! $revision ) {
  1794 		return $revision;
  1820 		return $revision;
  1795 	}
  1821 	}
  1796 
  1822 
  1797 	if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) {
  1823 	if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ), true ) ) {
  1798 		return false;
  1824 		return false;
  1799 	}
  1825 	}
  1800 
  1826 
  1801 	/* translators: revision date format, see https://secure.php.net/date */
  1827 	/* translators: Revision date format, see https://www.php.net/date */
  1802 	$datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
  1828 	$datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
  1803 	/* translators: %s: revision date */
  1829 	/* translators: %s: Revision date. */
  1804 	$autosavef = __( '%s [Autosave]' );
  1830 	$autosavef = __( '%s [Autosave]' );
  1805 	/* translators: %s: revision date */
  1831 	/* translators: %s: Revision date. */
  1806 	$currentf = __( '%s [Current Revision]' );
  1832 	$currentf = __( '%s [Current Revision]' );
  1807 
  1833 
  1808 	$date = date_i18n( $datef, strtotime( $revision->post_modified ) );
  1834 	$date      = date_i18n( $datef, strtotime( $revision->post_modified ) );
  1809 	if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) {
  1835 	$edit_link = get_edit_post_link( $revision->ID );
  1810 		$date = "<a href='$link'>$date</a>";
  1836 	if ( $link && current_user_can( 'edit_post', $revision->ID ) && $edit_link ) {
       
  1837 		$date = "<a href='$edit_link'>$date</a>";
  1811 	}
  1838 	}
  1812 
  1839 
  1813 	if ( ! wp_is_post_revision( $revision ) ) {
  1840 	if ( ! wp_is_post_revision( $revision ) ) {
  1814 		$date = sprintf( $currentf, $date );
  1841 		$date = sprintf( $currentf, $date );
  1815 	} elseif ( wp_is_post_autosave( $revision ) ) {
  1842 	} elseif ( wp_is_post_autosave( $revision ) ) {
  1823  * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
  1850  * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
  1824  *
  1851  *
  1825  * @since 3.6.0
  1852  * @since 3.6.0
  1826  *
  1853  *
  1827  * @param int|object $revision Revision ID or revision object.
  1854  * @param int|object $revision Revision ID or revision object.
  1828  * @param bool       $link     Optional, default is true. Link to revisions's page?
  1855  * @param bool       $link     Optional. Whether to link to revision's page. Default true.
  1829  * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'.
  1856  * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'.
  1830  */
  1857  */
  1831 function wp_post_revision_title_expanded( $revision, $link = true ) {
  1858 function wp_post_revision_title_expanded( $revision, $link = true ) {
  1832 	if ( ! $revision = get_post( $revision ) ) {
  1859 	$revision = get_post( $revision );
       
  1860 	if ( ! $revision ) {
  1833 		return $revision;
  1861 		return $revision;
  1834 	}
  1862 	}
  1835 
  1863 
  1836 	if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) {
  1864 	if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ), true ) ) {
  1837 		return false;
  1865 		return false;
  1838 	}
  1866 	}
  1839 
  1867 
  1840 	$author = get_the_author_meta( 'display_name', $revision->post_author );
  1868 	$author = get_the_author_meta( 'display_name', $revision->post_author );
  1841 	/* translators: revision date format, see https://secure.php.net/date */
  1869 	/* translators: Revision date format, see https://www.php.net/date */
  1842 	$datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
  1870 	$datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
  1843 
  1871 
  1844 	$gravatar = get_avatar( $revision->post_author, 24 );
  1872 	$gravatar = get_avatar( $revision->post_author, 24 );
  1845 
  1873 
  1846 	$date = date_i18n( $datef, strtotime( $revision->post_modified ) );
  1874 	$date      = date_i18n( $datef, strtotime( $revision->post_modified ) );
  1847 	if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) {
  1875 	$edit_link = get_edit_post_link( $revision->ID );
  1848 		$date = "<a href='$link'>$date</a>";
  1876 	if ( $link && current_user_can( 'edit_post', $revision->ID ) && $edit_link ) {
       
  1877 		$date = "<a href='$edit_link'>$date</a>";
  1849 	}
  1878 	}
  1850 
  1879 
  1851 	$revision_date_author = sprintf(
  1880 	$revision_date_author = sprintf(
  1852 		/* translators: post revision title: 1: author avatar, 2: author name, 3: time ago, 4: date */
  1881 		/* translators: Post revision title. 1: Author avatar, 2: Author name, 3: Time ago, 4: Date. */
  1853 		__( '%1$s %2$s, %3$s ago (%4$s)' ),
  1882 		__( '%1$s %2$s, %3$s ago (%4$s)' ),
  1854 		$gravatar,
  1883 		$gravatar,
  1855 		$author,
  1884 		$author,
  1856 		human_time_diff( strtotime( $revision->post_modified ), current_time( 'timestamp' ) ),
  1885 		human_time_diff( strtotime( $revision->post_modified_gmt ) ),
  1857 		$date
  1886 		$date
  1858 	);
  1887 	);
  1859 
  1888 
  1860 	/* translators: %s: revision date with author avatar */
  1889 	/* translators: %s: Revision date with author avatar. */
  1861 	$autosavef = __( '%s [Autosave]' );
  1890 	$autosavef = __( '%s [Autosave]' );
  1862 	/* translators: %s: revision date with author avatar */
  1891 	/* translators: %s: Revision date with author avatar. */
  1863 	$currentf = __( '%s [Current Revision]' );
  1892 	$currentf = __( '%s [Current Revision]' );
  1864 
  1893 
  1865 	if ( ! wp_is_post_revision( $revision ) ) {
  1894 	if ( ! wp_is_post_revision( $revision ) ) {
  1866 		$revision_date_author = sprintf( $currentf, $revision_date_author );
  1895 		$revision_date_author = sprintf( $currentf, $revision_date_author );
  1867 	} elseif ( wp_is_post_autosave( $revision ) ) {
  1896 	} elseif ( wp_is_post_autosave( $revision ) ) {
  1891  *
  1920  *
  1892  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
  1921  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
  1893  * @param string      $type    'all' (default), 'revision' or 'autosave'
  1922  * @param string      $type    'all' (default), 'revision' or 'autosave'
  1894  */
  1923  */
  1895 function wp_list_post_revisions( $post_id = 0, $type = 'all' ) {
  1924 function wp_list_post_revisions( $post_id = 0, $type = 'all' ) {
  1896 	if ( ! $post = get_post( $post_id ) ) {
  1925 	$post = get_post( $post_id );
       
  1926 	if ( ! $post ) {
  1897 		return;
  1927 		return;
  1898 	}
  1928 	}
  1899 
  1929 
  1900 	// $args array with (parent, format, right, left, type) deprecated since 3.6
  1930 	// $args array with (parent, format, right, left, type) deprecated since 3.6.
  1901 	if ( is_array( $type ) ) {
  1931 	if ( is_array( $type ) ) {
  1902 		$type = ! empty( $type['type'] ) ? $type['type'] : $type;
  1932 		$type = ! empty( $type['type'] ) ? $type['type'] : $type;
  1903 		_deprecated_argument( __FUNCTION__, '3.6.0' );
  1933 		_deprecated_argument( __FUNCTION__, '3.6.0' );
  1904 	}
  1934 	}
  1905 
  1935 
  1906 	if ( ! $revisions = wp_get_post_revisions( $post->ID ) ) {
  1936 	$revisions = wp_get_post_revisions( $post->ID );
       
  1937 	if ( ! $revisions ) {
  1907 		return;
  1938 		return;
  1908 	}
  1939 	}
  1909 
  1940 
  1910 	$rows = '';
  1941 	$rows = '';
  1911 	foreach ( $revisions as $revision ) {
  1942 	foreach ( $revisions as $revision ) {