wp/wp-includes/post-template.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    40  * @return string|void Current post title if $echo is false.
    40  * @return string|void 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 ) {
    46 		return;
    46 		return;
       
    47 	}
    47 
    48 
    48 	$title = $before . $title . $after;
    49 	$title = $before . $title . $after;
    49 
    50 
    50 	if ( $echo )
    51 	if ( $echo ) {
    51 		echo $title;
    52 		echo $title;
    52 	else
    53 	} else {
    53 		return $title;
    54 		return $title;
       
    55 	}
    54 }
    56 }
    55 
    57 
    56 /**
    58 /**
    57  * Sanitize the current title when retrieving or displaying.
    59  * Sanitize the current title when retrieving or displaying.
    58  *
    60  *
    74  *     @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.
    75  * }
    77  * }
    76  * @return string|void String when echo is false.
    78  * @return string|void String when echo is false.
    77  */
    79  */
    78 function the_title_attribute( $args = '' ) {
    80 function the_title_attribute( $args = '' ) {
    79 	$defaults = array( 'before' => '', 'after' =>  '', 'echo' => true, 'post' => get_post() );
    81 	$defaults = array(
    80 	$r = wp_parse_args( $args, $defaults );
    82 		'before' => '',
       
    83 		'after'  => '',
       
    84 		'echo'   => true,
       
    85 		'post'   => get_post(),
       
    86 	);
       
    87 	$r        = wp_parse_args( $args, $defaults );
    81 
    88 
    82 	$title = get_the_title( $r['post'] );
    89 	$title = get_the_title( $r['post'] );
    83 
    90 
    84 	if ( strlen( $title ) == 0 ) {
    91 	if ( strlen( $title ) == 0 ) {
    85 		return;
    92 		return;
   109  */
   116  */
   110 function get_the_title( $post = 0 ) {
   117 function get_the_title( $post = 0 ) {
   111 	$post = get_post( $post );
   118 	$post = get_post( $post );
   112 
   119 
   113 	$title = isset( $post->post_title ) ? $post->post_title : '';
   120 	$title = isset( $post->post_title ) ? $post->post_title : '';
   114 	$id = isset( $post->ID ) ? $post->ID : 0;
   121 	$id    = isset( $post->ID ) ? $post->ID : 0;
   115 
   122 
   116 	if ( ! is_admin() ) {
   123 	if ( ! is_admin() ) {
   117 		if ( ! empty( $post->post_password ) ) {
   124 		if ( ! empty( $post->post_password ) ) {
   118 
   125 
   119 			/**
   126 			/**
   126 			 * @param string  $prepend Text displayed before the post title.
   133 			 * @param string  $prepend Text displayed before the post title.
   127 			 *                         Default 'Protected: %s'.
   134 			 *                         Default 'Protected: %s'.
   128 			 * @param WP_Post $post    Current post object.
   135 			 * @param WP_Post $post    Current post object.
   129 			 */
   136 			 */
   130 			$protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ), $post );
   137 			$protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ), $post );
   131 			$title = sprintf( $protected_title_format, $title );
   138 			$title                  = sprintf( $protected_title_format, $title );
   132 		} elseif ( isset( $post->post_status ) && 'private' == $post->post_status ) {
   139 		} elseif ( isset( $post->post_status ) && 'private' == $post->post_status ) {
   133 
   140 
   134 			/**
   141 			/**
   135 			 * Filters the text prepended to the post title of private posts.
   142 			 * Filters the text prepended to the post title of private posts.
   136 			 *
   143 			 *
   141 			 * @param string  $prepend Text displayed before the post title.
   148 			 * @param string  $prepend Text displayed before the post title.
   142 			 *                         Default 'Private: %s'.
   149 			 *                         Default 'Private: %s'.
   143 			 * @param WP_Post $post    Current post object.
   150 			 * @param WP_Post $post    Current post object.
   144 			 */
   151 			 */
   145 			$private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ), $post );
   152 			$private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ), $post );
   146 			$title = sprintf( $private_title_format, $title );
   153 			$title                = sprintf( $private_title_format, $title );
   147 		}
   154 		}
   148 	}
   155 	}
   149 
   156 
   150 	/**
   157 	/**
   151 	 * Filters the post title.
   158 	 * Filters the post title.
   225  * @since 0.71
   232  * @since 0.71
   226  *
   233  *
   227  * @param string $more_link_text Optional. Content for when there is more text.
   234  * @param string $more_link_text Optional. Content for when there is more text.
   228  * @param bool   $strip_teaser   Optional. Strip teaser content before the more text. Default is false.
   235  * @param bool   $strip_teaser   Optional. Strip teaser content before the more text. Default is false.
   229  */
   236  */
   230 function the_content( $more_link_text = null, $strip_teaser = false) {
   237 function the_content( $more_link_text = null, $strip_teaser = false ) {
   231 	$content = get_the_content( $more_link_text, $strip_teaser );
   238 	$content = get_the_content( $more_link_text, $strip_teaser );
   232 
   239 
   233 	/**
   240 	/**
   234 	 * Filters the post content.
   241 	 * Filters the post content.
   235 	 *
   242 	 *
   244 
   251 
   245 /**
   252 /**
   246  * Retrieve the post content.
   253  * Retrieve the post content.
   247  *
   254  *
   248  * @since 0.71
   255  * @since 0.71
       
   256  * @since 5.2.0 Added the `$post` parameter.
   249  *
   257  *
   250  * @global int   $page      Page number of a single post/page.
   258  * @global int   $page      Page number of a single post/page.
   251  * @global int   $more      Boolean indicator for whether single post/page is being viewed.
   259  * @global int   $more      Boolean indicator for whether single post/page is being viewed.
   252  * @global bool  $preview   Whether post/page is in preview mode.
   260  * @global bool  $preview   Whether post/page is in preview mode.
   253  * @global array $pages     Array of all pages in post/page. Each array element contains part of the content separated by the <!--nextpage--> tag.
   261  * @global array $pages     Array of all pages in post/page. Each array element contains
       
   262  *                          part of the content separated by the `<!--nextpage-->` tag.
   254  * @global int   $multipage Boolean indicator for whether multiple pages are in play.
   263  * @global int   $multipage Boolean indicator for whether multiple pages are in play.
   255  *
   264  *
   256  * @param string $more_link_text Optional. Content for when there is more text.
   265  * @param string             $more_link_text Optional. Content for when there is more text.
   257  * @param bool   $strip_teaser   Optional. Strip teaser content before the more text. Default is false.
   266  * @param bool               $strip_teaser   Optional. Strip teaser content before the more text. Default is false.
       
   267  * @param WP_Post|object|int $post           Optional. WP_Post instance or Post ID/object. Default is null.
   258  * @return string
   268  * @return string
   259  */
   269  */
   260 function get_the_content( $more_link_text = null, $strip_teaser = false ) {
   270 function get_the_content( $more_link_text = null, $strip_teaser = false, $post = null ) {
   261 	global $page, $more, $preview, $pages, $multipage;
   271 	global $page, $more, $preview, $pages, $multipage;
   262 
   272 
   263 	$post = get_post();
   273 	$_post = get_post( $post );
       
   274 
       
   275 	if ( ! ( $_post instanceof WP_Post ) ) {
       
   276 		return '';
       
   277 	}
       
   278 
       
   279 	if ( null === $post ) {
       
   280 		$elements = compact( 'page', 'more', 'preview', 'pages', 'multipage' );
       
   281 	} else {
       
   282 		$elements = generate_postdata( $_post );
       
   283 	}
   264 
   284 
   265 	if ( null === $more_link_text ) {
   285 	if ( null === $more_link_text ) {
   266 		$more_link_text = sprintf(
   286 		$more_link_text = sprintf(
   267 			'<span aria-label="%1$s">%2$s</span>',
   287 			'<span aria-label="%1$s">%2$s</span>',
   268 			sprintf(
   288 			sprintf(
   269 				/* translators: %s: Name of current post */
   289 				/* translators: %s: Name of current post */
   270 				__( 'Continue reading %s' ),
   290 				__( 'Continue reading %s' ),
   271 				the_title_attribute( array( 'echo' => false ) )
   291 				the_title_attribute(
       
   292 					array(
       
   293 						'echo' => false,
       
   294 						'post' => $_post,
       
   295 					)
       
   296 				)
   272 			),
   297 			),
   273 			__( '(more&hellip;)' )
   298 			__( '(more&hellip;)' )
   274 		);
   299 		);
   275 	}
   300 	}
   276 
   301 
   277 	$output = '';
   302 	$output     = '';
   278 	$has_teaser = false;
   303 	$has_teaser = false;
   279 
   304 
   280 	// If post password required and it doesn't match the cookie.
   305 	// If post password required and it doesn't match the cookie.
   281 	if ( post_password_required( $post ) )
   306 	if ( post_password_required( $_post ) ) {
   282 		return get_the_password_form( $post );
   307 		return get_the_password_form( $_post );
   283 
   308 	}
   284 	if ( $page > count( $pages ) ) // if the requested page doesn't exist
   309 
   285 		$page = count( $pages ); // give them the highest numbered page that DOES exist
   310 	if ( $elements['page'] > count( $elements['pages'] ) ) { // if the requested page doesn't exist
   286 
   311 		$elements['page'] = count( $elements['pages'] ); // give them the highest numbered page that DOES exist
   287 	$content = $pages[$page - 1];
   312 	}
       
   313 
       
   314 	$page_no = $elements['page'];
       
   315 	$content = $elements['pages'][ $page_no - 1 ];
   288 	if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
   316 	if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
       
   317 		if ( has_block( 'more', $content ) ) {
       
   318 			// Remove the core/more block delimiters. They will be left over after $content is split up.
       
   319 			$content = preg_replace( '/<!-- \/?wp:more(.*?) -->/', '', $content );
       
   320 		}
       
   321 
   289 		$content = explode( $matches[0], $content, 2 );
   322 		$content = explode( $matches[0], $content, 2 );
   290 		if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) )
   323 
       
   324 		if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) {
   291 			$more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
   325 			$more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
       
   326 		}
   292 
   327 
   293 		$has_teaser = true;
   328 		$has_teaser = true;
   294 	} else {
   329 	} else {
   295 		$content = array( $content );
   330 		$content = array( $content );
   296 	}
   331 	}
   297 
   332 
   298 	if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) )
   333 	if ( false !== strpos( $_post->post_content, '<!--noteaser-->' ) && ( ! $elements['multipage'] || $elements['page'] == 1 ) ) {
   299 		$strip_teaser = true;
   334 		$strip_teaser = true;
       
   335 	}
   300 
   336 
   301 	$teaser = $content[0];
   337 	$teaser = $content[0];
   302 
   338 
   303 	if ( $more && $strip_teaser && $has_teaser )
   339 	if ( $elements['more'] && $strip_teaser && $has_teaser ) {
   304 		$teaser = '';
   340 		$teaser = '';
       
   341 	}
   305 
   342 
   306 	$output .= $teaser;
   343 	$output .= $teaser;
   307 
   344 
   308 	if ( count( $content ) > 1 ) {
   345 	if ( count( $content ) > 1 ) {
   309 		if ( $more ) {
   346 		if ( $elements['more'] ) {
   310 			$output .= '<span id="more-' . $post->ID . '"></span>' . $content[1];
   347 			$output .= '<span id="more-' . $_post->ID . '"></span>' . $content[1];
   311 		} else {
   348 		} else {
   312 			if ( ! empty( $more_link_text ) )
   349 			if ( ! empty( $more_link_text ) ) {
   313 
   350 
   314 				/**
   351 				/**
   315 				 * Filters the Read More link text.
   352 				 * Filters the Read More link text.
   316 				 *
   353 				 *
   317 				 * @since 2.8.0
   354 				 * @since 2.8.0
   318 				 *
   355 				 *
   319 				 * @param string $more_link_element Read More link element.
   356 				 * @param string $more_link_element Read More link element.
   320 				 * @param string $more_link_text    Read More text.
   357 				 * @param string $more_link_text    Read More text.
   321 				 */
   358 				 */
   322 				$output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
   359 				$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 );
       
   360 			}
   323 			$output = force_balance_tags( $output );
   361 			$output = force_balance_tags( $output );
   324 		}
   362 		}
   325 	}
   363 	}
   326 
   364 
   327 	if ( $preview ) // Preview fix for JavaScript bug with foreign languages.
       
   328 		$output =	preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output );
       
   329 
       
   330 	return $output;
   365 	return $output;
   331 }
       
   332 
       
   333 /**
       
   334  * Preview fix for JavaScript bug with foreign languages.
       
   335  *
       
   336  * @since 3.1.0
       
   337  * @access private
       
   338  *
       
   339  * @param array $match Match array from preg_replace_callback.
       
   340  * @return string
       
   341  */
       
   342 function _convert_urlencoded_to_entities( $match ) {
       
   343 	return '&#' . base_convert( $match[1], 16, 10 ) . ';';
       
   344 }
   366 }
   345 
   367 
   346 /**
   368 /**
   347  * Display the post excerpt.
   369  * Display the post excerpt.
   348  *
   370  *
   396 	 */
   418 	 */
   397 	return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );
   419 	return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );
   398 }
   420 }
   399 
   421 
   400 /**
   422 /**
   401  * Whether the post has a custom excerpt.
   423  * Determines whether the post has a custom excerpt.
       
   424  *
       
   425  * For more information on this and similar theme functions, check out
       
   426  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
   427  * Conditional Tags} article in the Theme Developer Handbook.
   402  *
   428  *
   403  * @since 2.3.0
   429  * @since 2.3.0
   404  *
   430  *
   405  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
   431  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
   406  * @return bool True if the post has a custom excerpt, false otherwise.
   432  * @return bool True if the post has a custom excerpt, false otherwise.
   407  */
   433  */
   408 function has_excerpt( $post = 0 ) {
   434 function has_excerpt( $post = 0 ) {
   409 	$post = get_post( $post );
   435 	$post = get_post( $post );
   410 	return ( !empty( $post->post_excerpt ) );
   436 	return ( ! empty( $post->post_excerpt ) );
   411 }
   437 }
   412 
   438 
   413 /**
   439 /**
   414  * Display the classes for the post div.
   440  * Displays the classes for the post container element.
   415  *
   441  *
   416  * @since 2.7.0
   442  * @since 2.7.0
   417  *
   443  *
   418  * @param string|array $class   One or more classes to add to the class list.
   444  * @param string|array $class   One or more classes to add to the class list.
   419  * @param int|WP_Post  $post_id Optional. Post ID or post object. Defaults to the global `$post`.
   445  * @param int|WP_Post  $post_id Optional. Post ID or post object. Defaults to the global `$post`.
   422 	// Separates classes with a single space, collates classes for post DIV
   448 	// Separates classes with a single space, collates classes for post DIV
   423 	echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';
   449 	echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';
   424 }
   450 }
   425 
   451 
   426 /**
   452 /**
   427  * Retrieves the classes for the post div as an array.
   453  * Retrieves an array of the class names for the post container element.
   428  *
   454  *
   429  * The class names are many. If the post is a sticky, then the 'sticky'
   455  * The class names are many. If the post is a sticky, then the 'sticky'
   430  * class name. The class 'hentry' is always added to each post. If the post has a
   456  * class name. The class 'hentry' is always added to each post. If the post has a
   431  * post thumbnail, 'has-post-thumbnail' is added as a class. For each taxonomy that
   457  * post thumbnail, 'has-post-thumbnail' is added as a class. For each taxonomy that
   432  * the post belongs to, a class will be added of the format '{$taxonomy}-{$slug}' -
   458  * the post belongs to, a class will be added of the format '{$taxonomy}-{$slug}' -
   433  * eg 'category-foo' or 'my_custom_taxonomy-bar'.
   459  * eg 'category-foo' or 'my_custom_taxonomy-bar'.
   434  *
   460  *
   435  * The 'post_tag' taxonomy is a special
   461  * The 'post_tag' taxonomy is a special
   436  * case; the class has the 'tag-' prefix instead of 'post_tag-'. All classes are
   462  * case; the class has the 'tag-' prefix instead of 'post_tag-'. All class names are
   437  * passed through the filter, {@see 'post_class'}, with the list of classes, followed by
   463  * passed through the filter, {@see 'post_class'}, with the list of class names, followed by
   438  * $class parameter value, with the post ID as the last parameter.
   464  * $class parameter value, with the post ID as the last parameter.
   439  *
   465  *
   440  * @since 2.7.0
   466  * @since 2.7.0
   441  * @since 4.2.0 Custom taxonomy classes were added.
   467  * @since 4.2.0 Custom taxonomy class names were added.
   442  *
   468  *
   443  * @param string|array $class   One or more classes to add to the class list.
   469  * @param string|string[] $class   Space-separated string or array of class names to add to the class list.
   444  * @param int|WP_Post  $post_id Optional. Post ID or post object.
   470  * @param int|WP_Post     $post_id Optional. Post ID or post object.
   445  * @return array Array of classes.
   471  * @return string[] Array of class names.
   446  */
   472  */
   447 function get_post_class( $class = '', $post_id = null ) {
   473 function get_post_class( $class = '', $post_id = null ) {
   448 	$post = get_post( $post_id );
   474 	$post = get_post( $post_id );
   449 
   475 
   450 	$classes = array();
   476 	$classes = array();
   462 	if ( ! $post ) {
   488 	if ( ! $post ) {
   463 		return $classes;
   489 		return $classes;
   464 	}
   490 	}
   465 
   491 
   466 	$classes[] = 'post-' . $post->ID;
   492 	$classes[] = 'post-' . $post->ID;
   467 	if ( ! is_admin() )
   493 	if ( ! is_admin() ) {
   468 		$classes[] = $post->post_type;
   494 		$classes[] = $post->post_type;
       
   495 	}
   469 	$classes[] = 'type-' . $post->post_type;
   496 	$classes[] = 'type-' . $post->post_type;
   470 	$classes[] = 'status-' . $post->post_status;
   497 	$classes[] = 'status-' . $post->post_status;
   471 
   498 
   472 	// Post Format
   499 	// Post Format
   473 	if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
   500 	if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
   474 		$post_format = get_post_format( $post->ID );
   501 		$post_format = get_post_format( $post->ID );
   475 
   502 
   476 		if ( $post_format && !is_wp_error($post_format) )
   503 		if ( $post_format && ! is_wp_error( $post_format ) ) {
   477 			$classes[] = 'format-' . sanitize_html_class( $post_format );
   504 			$classes[] = 'format-' . sanitize_html_class( $post_format );
   478 		else
   505 		} else {
   479 			$classes[] = 'format-standard';
   506 			$classes[] = 'format-standard';
       
   507 		}
   480 	}
   508 	}
   481 
   509 
   482 	$post_password_required = post_password_required( $post->ID );
   510 	$post_password_required = post_password_required( $post->ID );
   483 
   511 
   484 	// Post requires password.
   512 	// Post requires password.
   530 	}
   558 	}
   531 
   559 
   532 	$classes = array_map( 'esc_attr', $classes );
   560 	$classes = array_map( 'esc_attr', $classes );
   533 
   561 
   534 	/**
   562 	/**
   535 	 * Filters the list of CSS classes for the current post.
   563 	 * Filters the list of CSS class names for the current post.
   536 	 *
   564 	 *
   537 	 * @since 2.7.0
   565 	 * @since 2.7.0
   538 	 *
   566 	 *
   539 	 * @param array $classes An array of post classes.
   567 	 * @param string[] $classes An array of post class names.
   540 	 * @param array $class   An array of additional classes added to the post.
   568 	 * @param string[] $class   An array of additional class names added to the post.
   541 	 * @param int   $post_id The post ID.
   569 	 * @param int      $post_id The post ID.
   542 	 */
   570 	 */
   543 	$classes = apply_filters( 'post_class', $classes, $class, $post->ID );
   571 	$classes = apply_filters( 'post_class', $classes, $class, $post->ID );
   544 
   572 
   545 	return array_unique( $classes );
   573 	return array_unique( $classes );
   546 }
   574 }
   547 
   575 
   548 /**
   576 /**
   549  * Display the classes for the body element.
   577  * Displays the class names for the body element.
   550  *
   578  *
   551  * @since 2.8.0
   579  * @since 2.8.0
   552  *
   580  *
   553  * @param string|array $class One or more classes to add to the class list.
   581  * @param string|string[] $class Space-separated string or array of class names to add to the class list.
   554  */
   582  */
   555 function body_class( $class = '' ) {
   583 function body_class( $class = '' ) {
   556 	// Separates classes with a single space, collates classes for body element
   584 	// Separates class names with a single space, collates class names for body element
   557 	echo 'class="' . join( ' ', get_body_class( $class ) ) . '"';
   585 	echo 'class="' . join( ' ', get_body_class( $class ) ) . '"';
   558 }
   586 }
   559 
   587 
   560 /**
   588 /**
   561  * Retrieve the classes for the body element as an array.
   589  * Retrieves an array of the class names for the body element.
   562  *
   590  *
   563  * @since 2.8.0
   591  * @since 2.8.0
   564  *
   592  *
   565  * @global WP_Query $wp_query
   593  * @global WP_Query $wp_query
   566  *
   594  *
   567  * @param string|array $class One or more classes to add to the class list.
   595  * @param string|string[] $class Space-separated string or array of class names to add to the class list.
   568  * @return array Array of classes.
   596  * @return string[] Array of class names.
   569  */
   597  */
   570 function get_body_class( $class = '' ) {
   598 function get_body_class( $class = '' ) {
   571 	global $wp_query;
   599 	global $wp_query;
   572 
   600 
   573 	$classes = array();
   601 	$classes = array();
   574 
   602 
   575 	if ( is_rtl() )
   603 	if ( is_rtl() ) {
   576 		$classes[] = 'rtl';
   604 		$classes[] = 'rtl';
   577 
   605 	}
   578 	if ( is_front_page() )
   606 
       
   607 	if ( is_front_page() ) {
   579 		$classes[] = 'home';
   608 		$classes[] = 'home';
   580 	if ( is_home() )
   609 	}
       
   610 	if ( is_home() ) {
   581 		$classes[] = 'blog';
   611 		$classes[] = 'blog';
   582 	if ( is_archive() )
   612 	}
       
   613 	if ( is_privacy_policy() ) {
       
   614 		$classes[] = 'privacy-policy';
       
   615 	}
       
   616 	if ( is_archive() ) {
   583 		$classes[] = 'archive';
   617 		$classes[] = 'archive';
   584 	if ( is_date() )
   618 	}
       
   619 	if ( is_date() ) {
   585 		$classes[] = 'date';
   620 		$classes[] = 'date';
       
   621 	}
   586 	if ( is_search() ) {
   622 	if ( is_search() ) {
   587 		$classes[] = 'search';
   623 		$classes[] = 'search';
   588 		$classes[] = $wp_query->posts ? 'search-results' : 'search-no-results';
   624 		$classes[] = $wp_query->posts ? 'search-results' : 'search-no-results';
   589 	}
   625 	}
   590 	if ( is_paged() )
   626 	if ( is_paged() ) {
   591 		$classes[] = 'paged';
   627 		$classes[] = 'paged';
   592 	if ( is_attachment() )
   628 	}
       
   629 	if ( is_attachment() ) {
   593 		$classes[] = 'attachment';
   630 		$classes[] = 'attachment';
   594 	if ( is_404() )
   631 	}
       
   632 	if ( is_404() ) {
   595 		$classes[] = 'error404';
   633 		$classes[] = 'error404';
       
   634 	}
   596 
   635 
   597 	if ( is_singular() ) {
   636 	if ( is_singular() ) {
   598 		$post_id = $wp_query->get_queried_object_id();
   637 		$post_id   = $wp_query->get_queried_object_id();
   599 		$post = $wp_query->get_queried_object();
   638 		$post      = $wp_query->get_queried_object();
   600 		$post_type = $post->post_type;
   639 		$post_type = $post->post_type;
   601 
   640 
   602 		if ( is_page_template() ) {
   641 		if ( is_page_template() ) {
   603 			$classes[] = "{$post_type}-template";
   642 			$classes[] = "{$post_type}-template";
   604 
   643 
   621 
   660 
   622 				// Post Format
   661 				// Post Format
   623 				if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
   662 				if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
   624 					$post_format = get_post_format( $post->ID );
   663 					$post_format = get_post_format( $post->ID );
   625 
   664 
   626 					if ( $post_format && !is_wp_error($post_format) )
   665 					if ( $post_format && ! is_wp_error( $post_format ) ) {
   627 						$classes[] = 'single-format-' . sanitize_html_class( $post_format );
   666 						$classes[] = 'single-format-' . sanitize_html_class( $post_format );
   628 					else
   667 					} else {
   629 						$classes[] = 'single-format-standard';
   668 						$classes[] = 'single-format-standard';
       
   669 					}
   630 				}
   670 				}
   631 			}
   671 			}
   632 		}
   672 		}
   633 
   673 
   634 		if ( is_attachment() ) {
   674 		if ( is_attachment() ) {
   635 			$mime_type = get_post_mime_type($post_id);
   675 			$mime_type   = get_post_mime_type( $post_id );
   636 			$mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
   676 			$mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
   637 			$classes[] = 'attachmentid-' . $post_id;
   677 			$classes[]   = 'attachmentid-' . $post_id;
   638 			$classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );
   678 			$classes[]   = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );
   639 		} elseif ( is_page() ) {
   679 		} elseif ( is_page() ) {
   640 			$classes[] = 'page';
   680 			$classes[] = 'page';
   641 
   681 
   642 			$page_id = $wp_query->get_queried_object_id();
   682 			$page_id = $wp_query->get_queried_object_id();
   643 
   683 
   644 			$post = get_post($page_id);
   684 			$post = get_post( $page_id );
   645 
   685 
   646 			$classes[] = 'page-id-' . $page_id;
   686 			$classes[] = 'page-id-' . $page_id;
   647 
   687 
   648 			if ( get_pages( array( 'parent' => $page_id, 'number' => 1 ) ) ) {
   688 			if ( get_pages(
       
   689 				array(
       
   690 					'parent' => $page_id,
       
   691 					'number' => 1,
       
   692 				)
       
   693 			) ) {
   649 				$classes[] = 'page-parent';
   694 				$classes[] = 'page-parent';
   650 			}
   695 			}
   651 
   696 
   652 			if ( $post->post_parent ) {
   697 			if ( $post->post_parent ) {
   653 				$classes[] = 'page-child';
   698 				$classes[] = 'page-child';
   656 		}
   701 		}
   657 	} elseif ( is_archive() ) {
   702 	} elseif ( is_archive() ) {
   658 		if ( is_post_type_archive() ) {
   703 		if ( is_post_type_archive() ) {
   659 			$classes[] = 'post-type-archive';
   704 			$classes[] = 'post-type-archive';
   660 			$post_type = get_query_var( 'post_type' );
   705 			$post_type = get_query_var( 'post_type' );
   661 			if ( is_array( $post_type ) )
   706 			if ( is_array( $post_type ) ) {
   662 				$post_type = reset( $post_type );
   707 				$post_type = reset( $post_type );
       
   708 			}
   663 			$classes[] = 'post-type-archive-' . sanitize_html_class( $post_type );
   709 			$classes[] = 'post-type-archive-' . sanitize_html_class( $post_type );
   664 		} elseif ( is_author() ) {
   710 		} elseif ( is_author() ) {
   665 			$author = $wp_query->get_queried_object();
   711 			$author    = $wp_query->get_queried_object();
   666 			$classes[] = 'author';
   712 			$classes[] = 'author';
   667 			if ( isset( $author->user_nicename ) ) {
   713 			if ( isset( $author->user_nicename ) ) {
   668 				$classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID );
   714 				$classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID );
   669 				$classes[] = 'author-' . $author->ID;
   715 				$classes[] = 'author-' . $author->ID;
   670 			}
   716 			}
   671 		} elseif ( is_category() ) {
   717 		} elseif ( is_category() ) {
   672 			$cat = $wp_query->get_queried_object();
   718 			$cat       = $wp_query->get_queried_object();
   673 			$classes[] = 'category';
   719 			$classes[] = 'category';
   674 			if ( isset( $cat->term_id ) ) {
   720 			if ( isset( $cat->term_id ) ) {
   675 				$cat_class = sanitize_html_class( $cat->slug, $cat->term_id );
   721 				$cat_class = sanitize_html_class( $cat->slug, $cat->term_id );
   676 				if ( is_numeric( $cat_class ) || ! trim( $cat_class, '-' ) ) {
   722 				if ( is_numeric( $cat_class ) || ! trim( $cat_class, '-' ) ) {
   677 					$cat_class = $cat->term_id;
   723 					$cat_class = $cat->term_id;
   679 
   725 
   680 				$classes[] = 'category-' . $cat_class;
   726 				$classes[] = 'category-' . $cat_class;
   681 				$classes[] = 'category-' . $cat->term_id;
   727 				$classes[] = 'category-' . $cat->term_id;
   682 			}
   728 			}
   683 		} elseif ( is_tag() ) {
   729 		} elseif ( is_tag() ) {
   684 			$tag = $wp_query->get_queried_object();
   730 			$tag       = $wp_query->get_queried_object();
   685 			$classes[] = 'tag';
   731 			$classes[] = 'tag';
   686 			if ( isset( $tag->term_id ) ) {
   732 			if ( isset( $tag->term_id ) ) {
   687 				$tag_class = sanitize_html_class( $tag->slug, $tag->term_id );
   733 				$tag_class = sanitize_html_class( $tag->slug, $tag->term_id );
   688 				if ( is_numeric( $tag_class ) || ! trim( $tag_class, '-' ) ) {
   734 				if ( is_numeric( $tag_class ) || ! trim( $tag_class, '-' ) ) {
   689 					$tag_class = $tag->term_id;
   735 					$tag_class = $tag->term_id;
   705 				$classes[] = 'term-' . $term->term_id;
   751 				$classes[] = 'term-' . $term->term_id;
   706 			}
   752 			}
   707 		}
   753 		}
   708 	}
   754 	}
   709 
   755 
   710 	if ( is_user_logged_in() )
   756 	if ( is_user_logged_in() ) {
   711 		$classes[] = 'logged-in';
   757 		$classes[] = 'logged-in';
       
   758 	}
   712 
   759 
   713 	if ( is_admin_bar_showing() ) {
   760 	if ( is_admin_bar_showing() ) {
   714 		$classes[] = 'admin-bar';
   761 		$classes[] = 'admin-bar';
   715 		$classes[] = 'no-customize-support';
   762 		$classes[] = 'no-customize-support';
   716 	}
   763 	}
   717 
   764 
   718 	if ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() )
   765 	if ( current_theme_supports( 'custom-background' )
       
   766 		&& ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() ) ) {
   719 		$classes[] = 'custom-background';
   767 		$classes[] = 'custom-background';
       
   768 	}
   720 
   769 
   721 	if ( has_custom_logo() ) {
   770 	if ( has_custom_logo() ) {
   722 		$classes[] = 'wp-custom-logo';
   771 		$classes[] = 'wp-custom-logo';
   723 	}
   772 	}
   724 
   773 
       
   774 	if ( current_theme_supports( 'responsive-embeds' ) ) {
       
   775 		$classes[] = 'wp-embed-responsive';
       
   776 	}
       
   777 
   725 	$page = $wp_query->get( 'page' );
   778 	$page = $wp_query->get( 'page' );
   726 
   779 
   727 	if ( ! $page || $page < 2 )
   780 	if ( ! $page || $page < 2 ) {
   728 		$page = $wp_query->get( 'paged' );
   781 		$page = $wp_query->get( 'paged' );
       
   782 	}
   729 
   783 
   730 	if ( $page && $page > 1 && ! is_404() ) {
   784 	if ( $page && $page > 1 && ! is_404() ) {
   731 		$classes[] = 'paged-' . $page;
   785 		$classes[] = 'paged-' . $page;
   732 
   786 
   733 		if ( is_single() )
   787 		if ( is_single() ) {
   734 			$classes[] = 'single-paged-' . $page;
   788 			$classes[] = 'single-paged-' . $page;
   735 		elseif ( is_page() )
   789 		} elseif ( is_page() ) {
   736 			$classes[] = 'page-paged-' . $page;
   790 			$classes[] = 'page-paged-' . $page;
   737 		elseif ( is_category() )
   791 		} elseif ( is_category() ) {
   738 			$classes[] = 'category-paged-' . $page;
   792 			$classes[] = 'category-paged-' . $page;
   739 		elseif ( is_tag() )
   793 		} elseif ( is_tag() ) {
   740 			$classes[] = 'tag-paged-' . $page;
   794 			$classes[] = 'tag-paged-' . $page;
   741 		elseif ( is_date() )
   795 		} elseif ( is_date() ) {
   742 			$classes[] = 'date-paged-' . $page;
   796 			$classes[] = 'date-paged-' . $page;
   743 		elseif ( is_author() )
   797 		} elseif ( is_author() ) {
   744 			$classes[] = 'author-paged-' . $page;
   798 			$classes[] = 'author-paged-' . $page;
   745 		elseif ( is_search() )
   799 		} elseif ( is_search() ) {
   746 			$classes[] = 'search-paged-' . $page;
   800 			$classes[] = 'search-paged-' . $page;
   747 		elseif ( is_post_type_archive() )
   801 		} elseif ( is_post_type_archive() ) {
   748 			$classes[] = 'post-type-paged-' . $page;
   802 			$classes[] = 'post-type-paged-' . $page;
       
   803 		}
   749 	}
   804 	}
   750 
   805 
   751 	if ( ! empty( $class ) ) {
   806 	if ( ! empty( $class ) ) {
   752 		if ( !is_array( $class ) )
   807 		if ( ! is_array( $class ) ) {
   753 			$class = preg_split( '#\s+#', $class );
   808 			$class = preg_split( '#\s+#', $class );
       
   809 		}
   754 		$classes = array_merge( $classes, $class );
   810 		$classes = array_merge( $classes, $class );
   755 	} else {
   811 	} else {
   756 		// Ensure that we always coerce class to being an array.
   812 		// Ensure that we always coerce class to being an array.
   757 		$class = array();
   813 		$class = array();
   758 	}
   814 	}
   759 
   815 
   760 	$classes = array_map( 'esc_attr', $classes );
   816 	$classes = array_map( 'esc_attr', $classes );
   761 
   817 
   762 	/**
   818 	/**
   763 	 * Filters the list of CSS body classes for the current post or page.
   819 	 * Filters the list of CSS body class names for the current post or page.
   764 	 *
   820 	 *
   765 	 * @since 2.8.0
   821 	 * @since 2.8.0
   766 	 *
   822 	 *
   767 	 * @param array $classes An array of body classes.
   823 	 * @param string[] $classes An array of body class names.
   768 	 * @param array $class   An array of additional classes added to the body.
   824 	 * @param string[] $class   An array of additional class names added to the body.
   769 	 */
   825 	 */
   770 	$classes = apply_filters( 'body_class', $classes, $class );
   826 	$classes = apply_filters( 'body_class', $classes, $class );
   771 
   827 
   772 	return array_unique( $classes );
   828 	return array_unique( $classes );
   773 }
   829 }
   779  *
   835  *
   780  * @param int|WP_Post|null $post An optional post. Global $post used if not provided.
   836  * @param int|WP_Post|null $post An optional post. Global $post used if not provided.
   781  * @return bool false if a password is not required or the correct password cookie is present, true otherwise.
   837  * @return bool false if a password is not required or the correct password cookie is present, true otherwise.
   782  */
   838  */
   783 function post_password_required( $post = null ) {
   839 function post_password_required( $post = null ) {
   784 	$post = get_post($post);
   840 	$post = get_post( $post );
   785 
   841 
   786 	if ( empty( $post->post_password ) ) {
   842 	if ( empty( $post->post_password ) ) {
   787 		/** This filter is documented in wp-includes/post-template.php */
   843 		/** This filter is documented in wp-includes/post-template.php */
   788 		return apply_filters( 'post_password_required', false, $post );
   844 		return apply_filters( 'post_password_required', false, $post );
   789 	}
   845 	}
   820 //
   876 //
   821 
   877 
   822 /**
   878 /**
   823  * The formatted output of a list of pages.
   879  * The formatted output of a list of pages.
   824  *
   880  *
   825  * Displays page links for paginated posts (i.e. includes the <!--nextpage-->.
   881  * Displays page links for paginated posts (i.e. including the `<!--nextpage-->`
   826  * Quicktag one or more times). This tag must be within The Loop.
   882  * Quicktag one or more times). This tag must be within The Loop.
   827  *
   883  *
   828  * @since 1.2.0
   884  * @since 1.2.0
       
   885  * @since 5.1.0 Added the `aria_current` argument.
   829  *
   886  *
   830  * @global int $page
   887  * @global int $page
   831  * @global int $numpages
   888  * @global int $numpages
   832  * @global int $multipage
   889  * @global int $multipage
   833  * @global int $more
   890  * @global int $more
   839  *     @type string       $after            HTML or text to append to each link. Default is `</p>`.
   896  *     @type string       $after            HTML or text to append to each link. Default is `</p>`.
   840  *     @type string       $link_before      HTML or text to prepend to each link, inside the `<a>` tag.
   897  *     @type string       $link_before      HTML or text to prepend to each link, inside the `<a>` tag.
   841  *                                          Also prepended to the current item, which is not linked. Default empty.
   898  *                                          Also prepended to the current item, which is not linked. Default empty.
   842  *     @type string       $link_after       HTML or text to append to each Pages link inside the `<a>` tag.
   899  *     @type string       $link_after       HTML or text to append to each Pages link inside the `<a>` tag.
   843  *                                          Also appended to the current item, which is not linked. Default empty.
   900  *                                          Also appended to the current item, which is not linked. Default empty.
       
   901  *     @type string       $aria_current     The value for the aria-current attribute. Possible values are 'page',
       
   902  *                                          'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'.
   844  *     @type string       $next_or_number   Indicates whether page numbers should be used. Valid values are number
   903  *     @type string       $next_or_number   Indicates whether page numbers should be used. Valid values are number
   845  *                                          and next. Default is 'number'.
   904  *                                          and next. Default is 'number'.
   846  *     @type string       $separator        Text between pagination links. Default is ' '.
   905  *     @type string       $separator        Text between pagination links. Default is ' '.
   847  *     @type string       $nextpagelink     Link text for the next page link, if available. Default is 'Next Page'.
   906  *     @type string       $nextpagelink     Link text for the next page link, if available. Default is 'Next Page'.
   848  *     @type string       $previouspagelink Link text for the previous page link, if available. Default is 'Previous Page'.
   907  *     @type string       $previouspagelink Link text for the previous page link, if available. Default is 'Previous Page'.
   855  */
   914  */
   856 function wp_link_pages( $args = '' ) {
   915 function wp_link_pages( $args = '' ) {
   857 	global $page, $numpages, $multipage, $more;
   916 	global $page, $numpages, $multipage, $more;
   858 
   917 
   859 	$defaults = array(
   918 	$defaults = array(
   860 		'before'           => '<p>' . __( 'Pages:' ),
   919 		'before'           => '<p class="post-nav-links">' . __( 'Pages:' ),
   861 		'after'            => '</p>',
   920 		'after'            => '</p>',
   862 		'link_before'      => '',
   921 		'link_before'      => '',
   863 		'link_after'       => '',
   922 		'link_after'       => '',
       
   923 		'aria_current'     => 'page',
   864 		'next_or_number'   => 'number',
   924 		'next_or_number'   => 'number',
   865 		'separator'        => ' ',
   925 		'separator'        => ' ',
   866 		'nextpagelink'     => __( 'Next page' ),
   926 		'nextpagelink'     => __( 'Next page' ),
   867 		'previouspagelink' => __( 'Previous page' ),
   927 		'previouspagelink' => __( 'Previous page' ),
   868 		'pagelink'         => '%',
   928 		'pagelink'         => '%',
   869 		'echo'             => 1
   929 		'echo'             => 1,
   870 	);
   930 	);
   871 
   931 
   872 	$params = wp_parse_args( $args, $defaults );
   932 	$params = wp_parse_args( $args, $defaults );
   873 
   933 
   874 	/**
   934 	/**
   886 			$output .= $r['before'];
   946 			$output .= $r['before'];
   887 			for ( $i = 1; $i <= $numpages; $i++ ) {
   947 			for ( $i = 1; $i <= $numpages; $i++ ) {
   888 				$link = $r['link_before'] . str_replace( '%', $i, $r['pagelink'] ) . $r['link_after'];
   948 				$link = $r['link_before'] . str_replace( '%', $i, $r['pagelink'] ) . $r['link_after'];
   889 				if ( $i != $page || ! $more && 1 == $page ) {
   949 				if ( $i != $page || ! $more && 1 == $page ) {
   890 					$link = _wp_link_page( $i ) . $link . '</a>';
   950 					$link = _wp_link_page( $i ) . $link . '</a>';
       
   951 				} elseif ( $i === $page ) {
       
   952 					$link = '<span class="post-page-numbers current" aria-current="' . esc_attr( $r['aria_current'] ) . '">' . $link . '</span>';
   891 				}
   953 				}
   892 				/**
   954 				/**
   893 				 * Filters the HTML output of individual page number links.
   955 				 * Filters the HTML output of individual page number links.
   894 				 *
   956 				 *
   895 				 * @since 3.6.0
   957 				 * @since 3.6.0
   904 				$output .= $link;
   966 				$output .= $link;
   905 			}
   967 			}
   906 			$output .= $r['after'];
   968 			$output .= $r['after'];
   907 		} elseif ( $more ) {
   969 		} elseif ( $more ) {
   908 			$output .= $r['before'];
   970 			$output .= $r['before'];
   909 			$prev = $page - 1;
   971 			$prev    = $page - 1;
   910 			if ( $prev > 0 ) {
   972 			if ( $prev > 0 ) {
   911 				$link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '</a>';
   973 				$link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '</a>';
   912 
   974 
   913 				/** This filter is documented in wp-includes/post-template.php */
   975 				/** This filter is documented in wp-includes/post-template.php */
   914 				$output .= apply_filters( 'wp_link_pages_link', $link, $prev );
   976 				$output .= apply_filters( 'wp_link_pages_link', $link, $prev );
   954  * @param int $i Page number.
  1016  * @param int $i Page number.
   955  * @return string Link.
  1017  * @return string Link.
   956  */
  1018  */
   957 function _wp_link_page( $i ) {
  1019 function _wp_link_page( $i ) {
   958 	global $wp_rewrite;
  1020 	global $wp_rewrite;
   959 	$post = get_post();
  1021 	$post       = get_post();
   960 	$query_args = array();
  1022 	$query_args = array();
   961 
  1023 
   962 	if ( 1 == $i ) {
  1024 	if ( 1 == $i ) {
   963 		$url = get_permalink();
  1025 		$url = get_permalink();
   964 	} else {
  1026 	} else {
   965 		if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
  1027 		if ( '' == get_option( 'permalink_structure' ) || in_array( $post->post_status, array( 'draft', 'pending' ) ) ) {
   966 			$url = add_query_arg( 'page', $i, get_permalink() );
  1028 			$url = add_query_arg( 'page', $i, get_permalink() );
   967 		elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID )
  1029 		} elseif ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) {
   968 			$url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged');
  1030 			$url = trailingslashit( get_permalink() ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $i, 'single_paged' );
   969 		else
  1031 		} else {
   970 			$url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged');
  1032 			$url = trailingslashit( get_permalink() ) . user_trailingslashit( $i, 'single_paged' );
       
  1033 		}
   971 	}
  1034 	}
   972 
  1035 
   973 	if ( is_preview() ) {
  1036 	if ( is_preview() ) {
   974 
  1037 
   975 		if ( ( 'draft' !== $post->post_status ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) {
  1038 		if ( ( 'draft' !== $post->post_status ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) {
   976 			$query_args['preview_id'] = wp_unslash( $_GET['preview_id'] );
  1039 			$query_args['preview_id']    = wp_unslash( $_GET['preview_id'] );
   977 			$query_args['preview_nonce'] = wp_unslash( $_GET['preview_nonce'] );
  1040 			$query_args['preview_nonce'] = wp_unslash( $_GET['preview_nonce'] );
   978 		}
  1041 		}
   979 
  1042 
   980 		$url = get_preview_post_link( $post, $query_args, $url );
  1043 		$url = get_preview_post_link( $post, $query_args, $url );
   981 	}
  1044 	}
   982 
  1045 
   983 	return '<a href="' . esc_url( $url ) . '">';
  1046 	return '<a href="' . esc_url( $url ) . '" class="post-page-numbers">';
   984 }
  1047 }
   985 
  1048 
   986 //
  1049 //
   987 // Post-meta: Custom per-post fields.
  1050 // Post-meta: Custom per-post fields.
   988 //
  1051 //
   996  * @return false|string|array Array of values or single value, if only one element exists. False will be returned if key does not exist.
  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.
   997  */
  1060  */
   998 function post_custom( $key = '' ) {
  1061 function post_custom( $key = '' ) {
   999 	$custom = get_post_custom();
  1062 	$custom = get_post_custom();
  1000 
  1063 
  1001 	if ( !isset( $custom[$key] ) )
  1064 	if ( ! isset( $custom[ $key ] ) ) {
  1002 		return false;
  1065 		return false;
  1003 	elseif ( 1 == count($custom[$key]) )
  1066 	} elseif ( 1 == count( $custom[ $key ] ) ) {
  1004 		return $custom[$key][0];
  1067 		return $custom[ $key ][0];
  1005 	else
  1068 	} else {
  1006 		return $custom[$key];
  1069 		return $custom[ $key ];
  1007 }
  1070 	}
  1008 
  1071 }
  1009 /**
  1072 
  1010  * Display list of post custom fields.
  1073 /**
       
  1074  * Display a list of post custom fields.
  1011  *
  1075  *
  1012  * @since 1.2.0
  1076  * @since 1.2.0
  1013  *
  1077  *
  1014  * @internal This will probably change at some point...
  1078  * @internal This will probably change at some point...
  1015  *
       
  1016  */
  1079  */
  1017 function the_meta() {
  1080 function the_meta() {
  1018 	if ( $keys = get_post_custom_keys() ) {
  1081 	if ( $keys = get_post_custom_keys() ) {
  1019 		echo "<ul class='post-meta'>\n";
  1082 		$li_html = '';
  1020 		foreach ( (array) $keys as $key ) {
  1083 		foreach ( (array) $keys as $key ) {
  1021 			$keyt = trim( $key );
  1084 			$keyt = trim( $key );
  1022 			if ( is_protected_meta( $keyt, 'post' ) ) {
  1085 			if ( is_protected_meta( $keyt, 'post' ) ) {
  1023 				continue;
  1086 				continue;
  1024 			}
  1087 			}
  1025 
  1088 
  1026 			$values = array_map( 'trim', get_post_custom_values( $key ) );
  1089 			$values = array_map( 'trim', get_post_custom_values( $key ) );
  1027 			$value = implode( $values, ', ' );
  1090 			$value  = implode( $values, ', ' );
  1028 
  1091 
  1029 			$html = sprintf( "<li><span class='post-meta-key'>%s</span> %s</li>\n",
  1092 			$html = sprintf(
       
  1093 				"<li><span class='post-meta-key'>%s</span> %s</li>\n",
  1030 				/* translators: %s: Post custom field name */
  1094 				/* translators: %s: Post custom field name */
  1031 				sprintf( _x( '%s:', 'Post custom field name' ), $key ),
  1095 				sprintf( _x( '%s:', 'Post custom field name' ), $key ),
  1032 				$value
  1096 				$value
  1033 			);
  1097 			);
  1034 
  1098 
  1039 			 *
  1103 			 *
  1040 			 * @param string $html  The HTML output for the li element.
  1104 			 * @param string $html  The HTML output for the li element.
  1041 			 * @param string $key   Meta key.
  1105 			 * @param string $key   Meta key.
  1042 			 * @param string $value Meta value.
  1106 			 * @param string $value Meta value.
  1043 			 */
  1107 			 */
  1044 			echo apply_filters( 'the_meta_key', $html, $key, $value );
  1108 			$li_html .= apply_filters( 'the_meta_key', $html, $key, $value );
  1045 		}
  1109 		}
  1046 		echo "</ul>\n";
  1110 
       
  1111 		if ( $li_html ) {
       
  1112 			echo "<ul class='post-meta'>\n{$li_html}</ul>\n";
       
  1113 		}
  1047 	}
  1114 	}
  1048 }
  1115 }
  1049 
  1116 
  1050 //
  1117 //
  1051 // Pages
  1118 // Pages
  1052 //
  1119 //
  1053 
  1120 
  1054 /**
  1121 /**
  1055  * Retrieve or display list of pages as a dropdown (select list).
  1122  * Retrieve or display a list of pages as a dropdown (select list).
  1056  *
  1123  *
  1057  * @since 2.1.0
  1124  * @since 2.1.0
  1058  * @since 4.2.0 The `$value_field` argument was added.
  1125  * @since 4.2.0 The `$value_field` argument was added.
  1059  * @since 4.3.0 The `$class` argument was added.
  1126  * @since 4.3.0 The `$class` argument was added.
  1060  *
  1127  *
       
  1128  * @see get_pages()
       
  1129  *
  1061  * @param array|string $args {
  1130  * @param array|string $args {
  1062  *     Optional. Array or string of arguments to generate a pages drop-down element.
  1131  *     Optional. Array or string of arguments to generate a page dropdown. See `get_pages()` for additional arguments.
  1063  *
  1132  *
  1064  *     @type int          $depth                 Maximum depth. Default 0.
  1133  *     @type int          $depth                 Maximum depth. Default 0.
  1065  *     @type int          $child_of              Page ID to retrieve child pages of. Default 0.
  1134  *     @type int          $child_of              Page ID to retrieve child pages of. Default 0.
  1066  *     @type int|string   $selected              Value of the option that should be selected. Default 0.
  1135  *     @type int|string   $selected              Value of the option that should be selected. Default 0.
  1067  *     @type bool|int     $echo                  Whether to echo or return the generated markup. Accepts 0, 1,
  1136  *     @type bool|int     $echo                  Whether to echo or return the generated markup. Accepts 0, 1,
  1079  * }
  1148  * }
  1080  * @return string HTML content, if not displaying.
  1149  * @return string HTML content, if not displaying.
  1081  */
  1150  */
  1082 function wp_dropdown_pages( $args = '' ) {
  1151 function wp_dropdown_pages( $args = '' ) {
  1083 	$defaults = array(
  1152 	$defaults = array(
  1084 		'depth' => 0, 'child_of' => 0,
  1153 		'depth'                 => 0,
  1085 		'selected' => 0, 'echo' => 1,
  1154 		'child_of'              => 0,
  1086 		'name' => 'page_id', 'id' => '',
  1155 		'selected'              => 0,
  1087 		'class' => '',
  1156 		'echo'                  => 1,
  1088 		'show_option_none' => '', 'show_option_no_change' => '',
  1157 		'name'                  => 'page_id',
  1089 		'option_none_value' => '',
  1158 		'id'                    => '',
  1090 		'value_field' => 'ID',
  1159 		'class'                 => '',
       
  1160 		'show_option_none'      => '',
       
  1161 		'show_option_no_change' => '',
       
  1162 		'option_none_value'     => '',
       
  1163 		'value_field'           => 'ID',
  1091 	);
  1164 	);
  1092 
  1165 
  1093 	$r = wp_parse_args( $args, $defaults );
  1166 	$r = wp_parse_args( $args, $defaults );
  1094 
  1167 
  1095 	$pages = get_pages( $r );
  1168 	$pages  = get_pages( $r );
  1096 	$output = '';
  1169 	$output = '';
  1097 	// Back-compat with old system where both id and name were based on $name argument
  1170 	// Back-compat with old system where both id and name were based on $name argument
  1098 	if ( empty( $r['id'] ) ) {
  1171 	if ( empty( $r['id'] ) ) {
  1099 		$r['id'] = $r['name'];
  1172 		$r['id'] = $r['name'];
  1100 	}
  1173 	}
  1123 	 * @since 4.4.0 `$r` and `$pages` added as arguments.
  1196 	 * @since 4.4.0 `$r` and `$pages` added as arguments.
  1124 	 *
  1197 	 *
  1125 	 * @param string $output HTML output for drop down list of pages.
  1198 	 * @param string $output HTML output for drop down list of pages.
  1126 	 * @param array  $r      The parsed arguments array.
  1199 	 * @param array  $r      The parsed arguments array.
  1127 	 * @param array  $pages  List of WP_Post objects returned by `get_pages()`
  1200 	 * @param array  $pages  List of WP_Post objects returned by `get_pages()`
  1128  	 */
  1201 	 */
  1129 	$html = apply_filters( 'wp_dropdown_pages', $output, $r, $pages );
  1202 	$html = apply_filters( 'wp_dropdown_pages', $output, $r, $pages );
  1130 
  1203 
  1131 	if ( $r['echo'] ) {
  1204 	if ( $r['echo'] ) {
  1132 		echo $html;
  1205 		echo $html;
  1133 	}
  1206 	}
  1134 	return $html;
  1207 	return $html;
  1135 }
  1208 }
  1136 
  1209 
  1137 /**
  1210 /**
  1138  * Retrieve or display list of pages (or hierarchical post type items) in list (li) format.
  1211  * Retrieve or display a list of pages (or hierarchical post type items) in list (li) format.
  1139  *
  1212  *
  1140  * @since 1.5.0
  1213  * @since 1.5.0
  1141  * @since 4.7.0 Added the `item_spacing` argument.
  1214  * @since 4.7.0 Added the `item_spacing` argument.
  1142  *
  1215  *
  1143  * @see get_pages()
  1216  * @see get_pages()
  1144  *
  1217  *
  1145  * @global WP_Query $wp_query
  1218  * @global WP_Query $wp_query
  1146  *
  1219  *
  1147  * @param array|string $args {
  1220  * @param array|string $args {
  1148  *     Array or string of arguments. Optional.
  1221  *     Optional. Array or string of arguments to generate a list of pages. See `get_pages()` for additional arguments.
  1149  *
  1222  *
  1150  *     @type int          $child_of     Display only the sub-pages of a single page by ID. Default 0 (all pages).
  1223  *     @type int          $child_of     Display only the sub-pages of a single page by ID. Default 0 (all pages).
  1151  *     @type string       $authors      Comma-separated list of author IDs. Default empty (all authors).
  1224  *     @type string       $authors      Comma-separated list of author IDs. Default empty (all authors).
  1152  *     @type string       $date_format  PHP date format to use for the listed pages. Relies on the 'show_date' parameter.
  1225  *     @type string       $date_format  PHP date format to use for the listed pages. Relies on the 'show_date' parameter.
  1153  *                                      Default is the value of 'date_format' option.
  1226  *                                      Default is the value of 'date_format' option.
  1196 	if ( ! in_array( $r['item_spacing'], array( 'preserve', 'discard' ), true ) ) {
  1269 	if ( ! in_array( $r['item_spacing'], array( 'preserve', 'discard' ), true ) ) {
  1197 		// invalid value, fall back to default.
  1270 		// invalid value, fall back to default.
  1198 		$r['item_spacing'] = $defaults['item_spacing'];
  1271 		$r['item_spacing'] = $defaults['item_spacing'];
  1199 	}
  1272 	}
  1200 
  1273 
  1201 	$output = '';
  1274 	$output       = '';
  1202 	$current_page = 0;
  1275 	$current_page = 0;
  1203 
  1276 
  1204 	// sanitize, mostly to keep spaces out
  1277 	// sanitize, mostly to keep spaces out
  1205 	$r['exclude'] = preg_replace( '/[^0-9,]/', '', $r['exclude'] );
  1278 	$r['exclude'] = preg_replace( '/[^0-9,]/', '', $r['exclude'] );
  1206 
  1279 
  1216 	 */
  1289 	 */
  1217 	$r['exclude'] = implode( ',', apply_filters( 'wp_list_pages_excludes', $exclude_array ) );
  1290 	$r['exclude'] = implode( ',', apply_filters( 'wp_list_pages_excludes', $exclude_array ) );
  1218 
  1291 
  1219 	// Query pages.
  1292 	// Query pages.
  1220 	$r['hierarchical'] = 0;
  1293 	$r['hierarchical'] = 0;
  1221 	$pages = get_pages( $r );
  1294 	$pages             = get_pages( $r );
  1222 
  1295 
  1223 	if ( ! empty( $pages ) ) {
  1296 	if ( ! empty( $pages ) ) {
  1224 		if ( $r['title_li'] ) {
  1297 		if ( $r['title_li'] ) {
  1225 			$output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
  1298 			$output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
  1226 		}
  1299 		}
  1263 }
  1336 }
  1264 
  1337 
  1265 /**
  1338 /**
  1266  * Displays or retrieves a list of pages with an optional home link.
  1339  * Displays or retrieves a list of pages with an optional home link.
  1267  *
  1340  *
  1268  * The arguments are listed below and part of the arguments are for wp_list_pages()} function.
  1341  * The arguments are listed below and part of the arguments are for wp_list_pages() function.
  1269  * Check that function for more info on those arguments.
  1342  * Check that function for more info on those arguments.
  1270  *
  1343  *
  1271  * @since 2.7.0
  1344  * @since 2.7.0
  1272  * @since 4.4.0 Added `menu_id`, `container`, `before`, `after`, and `walker` arguments.
  1345  * @since 4.4.0 Added `menu_id`, `container`, `before`, `after`, and `walker` arguments.
  1273  * @since 4.7.0 Added the `item_spacing` argument.
  1346  * @since 4.7.0 Added the `item_spacing` argument.
  1274  *
  1347  *
  1275  * @param array|string $args {
  1348  * @param array|string $args {
  1276  *     Optional. Arguments to generate a page menu. See wp_list_pages() for additional arguments.
  1349  *     Optional. Array or string of arguments to generate a page menu. See `wp_list_pages()` for additional arguments.
  1277  *
  1350  *
  1278  *     @type string          $sort_column  How to sort the list of pages. Accepts post column names.
  1351  *     @type string          $sort_column  How to sort the list of pages. Accepts post column names.
  1279  *                                         Default 'menu_order, post_title'.
  1352  *                                         Default 'menu_order, post_title'.
  1280  *     @type string          $menu_id      ID for the div containing the page list. Default is empty string.
  1353  *     @type string          $menu_id      ID for the div containing the page list. Default is empty string.
  1281  *     @type string          $menu_class   Class to use for the element containing the page list. Default 'menu'.
  1354  *     @type string          $menu_class   Class to use for the element containing the page list. Default 'menu'.
  1286  *                                         you'd like shown for the home link. 1|true defaults to 'Home'.
  1359  *                                         you'd like shown for the home link. 1|true defaults to 'Home'.
  1287  *     @type string          $link_before  The HTML or text to prepend to $show_home text. Default empty.
  1360  *     @type string          $link_before  The HTML or text to prepend to $show_home text. Default empty.
  1288  *     @type string          $link_after   The HTML or text to append to $show_home text. Default empty.
  1361  *     @type string          $link_after   The HTML or text to append to $show_home text. Default empty.
  1289  *     @type string          $before       The HTML or text to prepend to the menu. Default is '<ul>'.
  1362  *     @type string          $before       The HTML or text to prepend to the menu. Default is '<ul>'.
  1290  *     @type string          $after        The HTML or text to append to the menu. Default is '</ul>'.
  1363  *     @type string          $after        The HTML or text to append to the menu. Default is '</ul>'.
  1291  *     @type string          $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve' or 'discard'. Default 'discard'.
  1364  *     @type string          $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve'
       
  1365  *                                         or 'discard'. Default 'discard'.
  1292  *     @type Walker          $walker       Walker instance to use for listing pages. Default empty (Walker_Page).
  1366  *     @type Walker          $walker       Walker instance to use for listing pages. Default empty (Walker_Page).
  1293  * }
  1367  * }
  1294  * @return string|void HTML menu
  1368  * @return string|void HTML menu
  1295  */
  1369  */
  1296 function wp_page_menu( $args = array() ) {
  1370 function wp_page_menu( $args = array() ) {
  1305 		'before'       => '<ul>',
  1379 		'before'       => '<ul>',
  1306 		'after'        => '</ul>',
  1380 		'after'        => '</ul>',
  1307 		'item_spacing' => 'discard',
  1381 		'item_spacing' => 'discard',
  1308 		'walker'       => '',
  1382 		'walker'       => '',
  1309 	);
  1383 	);
  1310 	$args = wp_parse_args( $args, $defaults );
  1384 	$args     = wp_parse_args( $args, $defaults );
  1311 
  1385 
  1312 	if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ) ) ) {
  1386 	if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ) ) ) {
  1313 		// invalid value, fall back to default.
  1387 		// invalid value, fall back to default.
  1314 		$args['item_spacing'] = $defaults['item_spacing'];
  1388 		$args['item_spacing'] = $defaults['item_spacing'];
  1315 	}
  1389 	}
  1336 	$menu = '';
  1410 	$menu = '';
  1337 
  1411 
  1338 	$list_args = $args;
  1412 	$list_args = $args;
  1339 
  1413 
  1340 	// Show Home in the menu
  1414 	// Show Home in the menu
  1341 	if ( ! empty($args['show_home']) ) {
  1415 	if ( ! empty( $args['show_home'] ) ) {
  1342 		if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] )
  1416 		if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) {
  1343 			$text = __('Home');
  1417 			$text = __( 'Home' );
  1344 		else
  1418 		} else {
  1345 			$text = $args['show_home'];
  1419 			$text = $args['show_home'];
       
  1420 		}
  1346 		$class = '';
  1421 		$class = '';
  1347 		if ( is_front_page() && !is_paged() )
  1422 		if ( is_front_page() && ! is_paged() ) {
  1348 			$class = 'class="current_page_item"';
  1423 			$class = 'class="current_page_item"';
       
  1424 		}
  1349 		$menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
  1425 		$menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
  1350 		// If the front page is a page, add it to the exclude list
  1426 		// If the front page is a page, add it to the exclude list
  1351 		if (get_option('show_on_front') == 'page') {
  1427 		if ( get_option( 'show_on_front' ) == 'page' ) {
  1352 			if ( !empty( $list_args['exclude'] ) ) {
  1428 			if ( ! empty( $list_args['exclude'] ) ) {
  1353 				$list_args['exclude'] .= ',';
  1429 				$list_args['exclude'] .= ',';
  1354 			} else {
  1430 			} else {
  1355 				$list_args['exclude'] = '';
  1431 				$list_args['exclude'] = '';
  1356 			}
  1432 			}
  1357 			$list_args['exclude'] .= get_option('page_on_front');
  1433 			$list_args['exclude'] .= get_option( 'page_on_front' );
  1358 		}
  1434 		}
  1359 	}
  1435 	}
  1360 
  1436 
  1361 	$list_args['echo'] = false;
  1437 	$list_args['echo']     = false;
  1362 	$list_args['title_li'] = '';
  1438 	$list_args['title_li'] = '';
  1363 	$menu .= wp_list_pages( $list_args );
  1439 	$menu                 .= wp_list_pages( $list_args );
  1364 
  1440 
  1365 	$container = sanitize_text_field( $args['container'] );
  1441 	$container = sanitize_text_field( $args['container'] );
  1366 
  1442 
  1367 	// Fallback in case `wp_nav_menu()` was called without a container.
  1443 	// Fallback in case `wp_nav_menu()` was called without a container.
  1368 	if ( empty( $container ) ) {
  1444 	if ( empty( $container ) ) {
  1374 		// wp_nav_menu doesn't set before and after
  1450 		// wp_nav_menu doesn't set before and after
  1375 		if ( isset( $args['fallback_cb'] ) &&
  1451 		if ( isset( $args['fallback_cb'] ) &&
  1376 			'wp_page_menu' === $args['fallback_cb'] &&
  1452 			'wp_page_menu' === $args['fallback_cb'] &&
  1377 			'ul' !== $container ) {
  1453 			'ul' !== $container ) {
  1378 			$args['before'] = "<ul>{$n}";
  1454 			$args['before'] = "<ul>{$n}";
  1379 			$args['after'] = '</ul>';
  1455 			$args['after']  = '</ul>';
  1380 		}
  1456 		}
  1381 
  1457 
  1382 		$menu = $args['before'] . $menu . $args['after'];
  1458 		$menu = $args['before'] . $menu . $args['after'];
  1383 	}
  1459 	}
  1384 
  1460 
  1402 	 *
  1478 	 *
  1403 	 * @param string $menu The HTML output.
  1479 	 * @param string $menu The HTML output.
  1404 	 * @param array  $args An array of arguments.
  1480 	 * @param array  $args An array of arguments.
  1405 	 */
  1481 	 */
  1406 	$menu = apply_filters( 'wp_page_menu', $menu, $args );
  1482 	$menu = apply_filters( 'wp_page_menu', $menu, $args );
  1407 	if ( $args['echo'] )
  1483 	if ( $args['echo'] ) {
  1408 		echo $menu;
  1484 		echo $menu;
  1409 	else
  1485 	} else {
  1410 		return $menu;
  1486 		return $menu;
       
  1487 	}
  1411 }
  1488 }
  1412 
  1489 
  1413 //
  1490 //
  1414 // Page helpers
  1491 // Page helpers
  1415 //
  1492 //
  1425  * @param int   $current_page
  1502  * @param int   $current_page
  1426  * @param array $r
  1503  * @param array $r
  1427  * @return string
  1504  * @return string
  1428  */
  1505  */
  1429 function walk_page_tree( $pages, $depth, $current_page, $r ) {
  1506 function walk_page_tree( $pages, $depth, $current_page, $r ) {
  1430 	if ( empty($r['walker']) )
  1507 	if ( empty( $r['walker'] ) ) {
  1431 		$walker = new Walker_Page;
  1508 		$walker = new Walker_Page;
  1432 	else
  1509 	} else {
  1433 		$walker = $r['walker'];
  1510 		$walker = $r['walker'];
       
  1511 	}
  1434 
  1512 
  1435 	foreach ( (array) $pages as $page ) {
  1513 	foreach ( (array) $pages as $page ) {
  1436 		if ( $page->post_parent )
  1514 		if ( $page->post_parent ) {
  1437 			$r['pages_with_children'][ $page->post_parent ] = true;
  1515 			$r['pages_with_children'][ $page->post_parent ] = true;
  1438 	}
  1516 		}
  1439 
  1517 	}
  1440 	$args = array($pages, $depth, $r, $current_page);
  1518 
  1441 	return call_user_func_array(array($walker, 'walk'), $args);
  1519 	$args = array( $pages, $depth, $r, $current_page );
       
  1520 	return call_user_func_array( array( $walker, 'walk' ), $args );
  1442 }
  1521 }
  1443 
  1522 
  1444 /**
  1523 /**
  1445  * Retrieve HTML dropdown (select) content for page list.
  1524  * Retrieve HTML dropdown (select) content for page list.
  1446  *
  1525  *
  1450  *
  1529  *
  1451  * @return string
  1530  * @return string
  1452  */
  1531  */
  1453 function walk_page_dropdown_tree() {
  1532 function walk_page_dropdown_tree() {
  1454 	$args = func_get_args();
  1533 	$args = func_get_args();
  1455 	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
  1456 		$walker = new Walker_PageDropdown;
  1535 		$walker = new Walker_PageDropdown;
  1457 	else
  1536 	} else {
  1458 		$walker = $args[2]['walker'];
  1537 		$walker = $args[2]['walker'];
  1459 
  1538 	}
  1460 	return call_user_func_array(array($walker, 'walk'), $args);
  1539 
       
  1540 	return call_user_func_array( array( $walker, 'walk' ), $args );
  1461 }
  1541 }
  1462 
  1542 
  1463 //
  1543 //
  1464 // Attachments
  1544 // Attachments
  1465 //
  1545 //
  1473  * @param bool        $fullsize     Optional, default is false. Whether to use full size.
  1553  * @param bool        $fullsize     Optional, default is false. Whether to use full size.
  1474  * @param bool        $deprecated   Deprecated. Not used.
  1554  * @param bool        $deprecated   Deprecated. Not used.
  1475  * @param bool        $permalink    Optional, default is false. Whether to include permalink.
  1555  * @param bool        $permalink    Optional, default is false. Whether to include permalink.
  1476  */
  1556  */
  1477 function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) {
  1557 function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) {
  1478 	if ( !empty( $deprecated ) )
  1558 	if ( ! empty( $deprecated ) ) {
  1479 		_deprecated_argument( __FUNCTION__, '2.5.0' );
  1559 		_deprecated_argument( __FUNCTION__, '2.5.0' );
  1480 
  1560 	}
  1481 	if ( $fullsize )
  1561 
  1482 		echo wp_get_attachment_link($id, 'full', $permalink);
  1562 	if ( $fullsize ) {
  1483 	else
  1563 		echo wp_get_attachment_link( $id, 'full', $permalink );
  1484 		echo wp_get_attachment_link($id, 'thumbnail', $permalink);
  1564 	} else {
       
  1565 		echo wp_get_attachment_link( $id, 'thumbnail', $permalink );
       
  1566 	}
  1485 }
  1567 }
  1486 
  1568 
  1487 /**
  1569 /**
  1488  * Retrieve an attachment page link using an image or icon, if possible.
  1570  * Retrieve an attachment page link using an image or icon, if possible.
  1489  *
  1571  *
  1529 	}
  1611 	}
  1530 	/**
  1612 	/**
  1531 	 * Filters a retrieved attachment page link.
  1613 	 * Filters a retrieved attachment page link.
  1532 	 *
  1614 	 *
  1533 	 * @since 2.7.0
  1615 	 * @since 2.7.0
       
  1616 	 * @since 5.1.0 Added the $attr parameter.
  1534 	 *
  1617 	 *
  1535 	 * @param string       $link_html The page link HTML output.
  1618 	 * @param string       $link_html The page link HTML output.
  1536 	 * @param int          $id        Post ID.
  1619 	 * @param int          $id        Post ID.
  1537 	 * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
  1620 	 * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
  1538 	 *                                Default 'thumbnail'.
  1621 	 *                                Default 'thumbnail'.
  1539 	 * @param bool         $permalink Whether to add permalink to image. Default false.
  1622 	 * @param bool         $permalink Whether to add permalink to image. Default false.
  1540 	 * @param bool         $icon      Whether to include an icon. Default false.
  1623 	 * @param bool         $icon      Whether to include an icon. Default false.
  1541 	 * @param string|bool  $text      If string, will be link text. Default false.
  1624 	 * @param string|bool  $text      If string, will be link text. Default false.
       
  1625 	 * @param array|string $attr      Array or string of attributes. Default empty.
  1542 	 */
  1626 	 */
  1543 	return apply_filters( 'wp_get_attachment_link', "<a href='" . esc_url( $url ) . "'>$link_text</a>", $id, $size, $permalink, $icon, $text );
  1627 	return apply_filters( 'wp_get_attachment_link', "<a href='" . esc_url( $url ) . "'>$link_text</a>", $id, $size, $permalink, $icon, $text, $attr );
  1544 }
  1628 }
  1545 
  1629 
  1546 /**
  1630 /**
  1547  * Wrap attachment in paragraph tag before content.
  1631  * Wrap attachment in paragraph tag before content.
  1548  *
  1632  *
  1549  * @since 2.0.0
  1633  * @since 2.0.0
  1550  *
  1634  *
  1551  * @param string $content
  1635  * @param string $content
  1552  * @return string
  1636  * @return string
  1553  */
  1637  */
  1554 function prepend_attachment($content) {
  1638 function prepend_attachment( $content ) {
  1555 	$post = get_post();
  1639 	$post = get_post();
  1556 
  1640 
  1557 	if ( empty($post->post_type) || $post->post_type != 'attachment' )
  1641 	if ( empty( $post->post_type ) || $post->post_type != 'attachment' ) {
  1558 		return $content;
  1642 		return $content;
       
  1643 	}
  1559 
  1644 
  1560 	if ( wp_attachment_is( 'video', $post ) ) {
  1645 	if ( wp_attachment_is( 'video', $post ) ) {
  1561 		$meta = wp_get_attachment_metadata( get_the_ID() );
  1646 		$meta = wp_get_attachment_metadata( get_the_ID() );
  1562 		$atts = array( 'src' => wp_get_attachment_url() );
  1647 		$atts = array( 'src' => wp_get_attachment_url() );
  1563 		if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
  1648 		if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
  1564 			$atts['width'] = (int) $meta['width'];
  1649 			$atts['width']  = (int) $meta['width'];
  1565 			$atts['height'] = (int) $meta['height'];
  1650 			$atts['height'] = (int) $meta['height'];
  1566 		}
  1651 		}
  1567 		if ( has_post_thumbnail() ) {
  1652 		if ( has_post_thumbnail() ) {
  1568 			$atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() );
  1653 			$atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() );
  1569 		}
  1654 		}
  1571 	} elseif ( wp_attachment_is( 'audio', $post ) ) {
  1656 	} elseif ( wp_attachment_is( 'audio', $post ) ) {
  1572 		$p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) );
  1657 		$p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) );
  1573 	} else {
  1658 	} else {
  1574 		$p = '<p class="attachment">';
  1659 		$p = '<p class="attachment">';
  1575 		// show the medium sized image representation of the attachment if available, and link to the raw file
  1660 		// show the medium sized image representation of the attachment if available, and link to the raw file
  1576 		$p .= wp_get_attachment_link(0, 'medium', false);
  1661 		$p .= wp_get_attachment_link( 0, 'medium', false );
  1577 		$p .= '</p>';
  1662 		$p .= '</p>';
  1578 	}
  1663 	}
  1579 
  1664 
  1580 	/**
  1665 	/**
  1581 	 * Filters the attachment markup to be prepended to the post content.
  1666 	 * Filters the attachment markup to be prepended to the post content.
  1602  *
  1687  *
  1603  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
  1688  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
  1604  * @return string HTML content for password form for password protected post.
  1689  * @return string HTML content for password form for password protected post.
  1605  */
  1690  */
  1606 function get_the_password_form( $post = 0 ) {
  1691 function get_the_password_form( $post = 0 ) {
  1607 	$post = get_post( $post );
  1692 	$post   = get_post( $post );
  1608 	$label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );
  1693 	$label  = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID );
  1609 	$output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">
  1694 	$output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">
  1610 	<p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p>
  1695 	<p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p>
  1611 	<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>
  1696 	<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>
  1612 	';
  1697 	';
  1613 
  1698 
  1624 	 */
  1709 	 */
  1625 	return apply_filters( 'the_password_form', $output );
  1710 	return apply_filters( 'the_password_form', $output );
  1626 }
  1711 }
  1627 
  1712 
  1628 /**
  1713 /**
  1629  * Whether currently in a page template.
  1714  * Determines whether currently in a page template.
  1630  *
  1715  *
  1631  * This template tag allows you to determine if you are in a page template.
  1716  * This template tag allows you to determine if you are in a page template.
  1632  * You can optionally provide a template name or array of template names
  1717  * You can optionally provide a template name or array of template names
  1633  * and then the check will be specific to that template.
  1718  * and then the check will be specific to that template.
  1634  *
  1719  *
       
  1720  * For more information on this and similar theme functions, check out
       
  1721  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
       
  1722  * Conditional Tags} article in the Theme Developer Handbook.
       
  1723  *
  1635  * @since 2.5.0
  1724  * @since 2.5.0
  1636  * @since 4.2.0 The `$template` parameter was changed to also accept an array of page templates.
  1725  * @since 4.2.0 The `$template` parameter was changed to also accept an array of page templates.
  1637  * @since 4.7.0 Now works with any post type, not just pages.
  1726  * @since 4.7.0 Now works with any post type, not just pages.
  1638  *
  1727  *
  1639  * @param string|array $template The specific template name or array of templates to match.
  1728  * @param string|array $template The specific template name or array of templates to match.
  1644 		return false;
  1733 		return false;
  1645 	}
  1734 	}
  1646 
  1735 
  1647 	$page_template = get_page_template_slug( get_queried_object_id() );
  1736 	$page_template = get_page_template_slug( get_queried_object_id() );
  1648 
  1737 
  1649 	if ( empty( $template ) )
  1738 	if ( empty( $template ) ) {
  1650 		return (bool) $page_template;
  1739 		return (bool) $page_template;
  1651 
  1740 	}
  1652 	if ( $template == $page_template )
  1741 
       
  1742 	if ( $template == $page_template ) {
  1653 		return true;
  1743 		return true;
       
  1744 	}
  1654 
  1745 
  1655 	if ( is_array( $template ) ) {
  1746 	if ( is_array( $template ) ) {
  1656 		if ( ( in_array( 'default', $template, true ) && ! $page_template )
  1747 		if ( ( in_array( 'default', $template, true ) && ! $page_template )
  1657 			|| in_array( $page_template, $template, true )
  1748 			|| in_array( $page_template, $template, true )
  1658 		) {
  1749 		) {
  1669  * @since 3.4.0
  1760  * @since 3.4.0
  1670  * @since 4.7.0 Now works with any post type, not just pages.
  1761  * @since 4.7.0 Now works with any post type, not just pages.
  1671  *
  1762  *
  1672  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
  1763  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
  1673  * @return string|false Page template filename. Returns an empty string when the default page template
  1764  * @return string|false Page template filename. Returns an empty string when the default page template
  1674  * 	is in use. Returns false if the post does not exist.
  1765  *  is in use. Returns false if the post does not exist.
  1675  */
  1766  */
  1676 function get_page_template_slug( $post = null ) {
  1767 function get_page_template_slug( $post = null ) {
  1677 	$post = get_post( $post );
  1768 	$post = get_post( $post );
  1678 
  1769 
  1679 	if ( ! $post ) {
  1770 	if ( ! $post ) {
  1697  * @param int|object $revision Revision ID or revision object.
  1788  * @param int|object $revision Revision ID or revision object.
  1698  * @param bool       $link     Optional, default is true. Link to revisions's page?
  1789  * @param bool       $link     Optional, default is true. Link to revisions's page?
  1699  * @return string|false i18n formatted datetimestamp or localized 'Current Revision'.
  1790  * @return string|false i18n formatted datetimestamp or localized 'Current Revision'.
  1700  */
  1791  */
  1701 function wp_post_revision_title( $revision, $link = true ) {
  1792 function wp_post_revision_title( $revision, $link = true ) {
  1702 	if ( !$revision = get_post( $revision ) )
  1793 	if ( ! $revision = get_post( $revision ) ) {
  1703 		return $revision;
  1794 		return $revision;
  1704 
  1795 	}
  1705 	if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
  1796 
       
  1797 	if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) {
  1706 		return false;
  1798 		return false;
       
  1799 	}
  1707 
  1800 
  1708 	/* translators: revision date format, see https://secure.php.net/date */
  1801 	/* translators: revision date format, see https://secure.php.net/date */
  1709 	$datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
  1802 	$datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
  1710 	/* translators: %s: revision date */
  1803 	/* translators: %s: revision date */
  1711 	$autosavef = __( '%s [Autosave]' );
  1804 	$autosavef = __( '%s [Autosave]' );
  1712 	/* translators: %s: revision date */
  1805 	/* translators: %s: revision date */
  1713 	$currentf  = __( '%s [Current Revision]' );
  1806 	$currentf = __( '%s [Current Revision]' );
  1714 
  1807 
  1715 	$date = date_i18n( $datef, strtotime( $revision->post_modified ) );
  1808 	$date = date_i18n( $datef, strtotime( $revision->post_modified ) );
  1716 	if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
  1809 	if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) {
  1717 		$date = "<a href='$link'>$date</a>";
  1810 		$date = "<a href='$link'>$date</a>";
  1718 
  1811 	}
  1719 	if ( !wp_is_post_revision( $revision ) )
  1812 
       
  1813 	if ( ! wp_is_post_revision( $revision ) ) {
  1720 		$date = sprintf( $currentf, $date );
  1814 		$date = sprintf( $currentf, $date );
  1721 	elseif ( wp_is_post_autosave( $revision ) )
  1815 	} elseif ( wp_is_post_autosave( $revision ) ) {
  1722 		$date = sprintf( $autosavef, $date );
  1816 		$date = sprintf( $autosavef, $date );
       
  1817 	}
  1723 
  1818 
  1724 	return $date;
  1819 	return $date;
  1725 }
  1820 }
  1726 
  1821 
  1727 /**
  1822 /**
  1732  * @param int|object $revision Revision ID or revision object.
  1827  * @param int|object $revision Revision ID or revision object.
  1733  * @param bool       $link     Optional, default is true. Link to revisions's page?
  1828  * @param bool       $link     Optional, default is true. Link to revisions's page?
  1734  * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'.
  1829  * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'.
  1735  */
  1830  */
  1736 function wp_post_revision_title_expanded( $revision, $link = true ) {
  1831 function wp_post_revision_title_expanded( $revision, $link = true ) {
  1737 	if ( !$revision = get_post( $revision ) )
  1832 	if ( ! $revision = get_post( $revision ) ) {
  1738 		return $revision;
  1833 		return $revision;
  1739 
  1834 	}
  1740 	if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
  1835 
       
  1836 	if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) {
  1741 		return false;
  1837 		return false;
       
  1838 	}
  1742 
  1839 
  1743 	$author = get_the_author_meta( 'display_name', $revision->post_author );
  1840 	$author = get_the_author_meta( 'display_name', $revision->post_author );
  1744 	/* translators: revision date format, see https://secure.php.net/date */
  1841 	/* translators: revision date format, see https://secure.php.net/date */
  1745 	$datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
  1842 	$datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
  1746 
  1843 
  1747 	$gravatar = get_avatar( $revision->post_author, 24 );
  1844 	$gravatar = get_avatar( $revision->post_author, 24 );
  1748 
  1845 
  1749 	$date = date_i18n( $datef, strtotime( $revision->post_modified ) );
  1846 	$date = date_i18n( $datef, strtotime( $revision->post_modified ) );
  1750 	if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
  1847 	if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) {
  1751 		$date = "<a href='$link'>$date</a>";
  1848 		$date = "<a href='$link'>$date</a>";
       
  1849 	}
  1752 
  1850 
  1753 	$revision_date_author = sprintf(
  1851 	$revision_date_author = sprintf(
  1754 		/* translators: post revision title: 1: author avatar, 2: author name, 3: time ago, 4: date */
  1852 		/* translators: post revision title: 1: author avatar, 2: author name, 3: time ago, 4: date */
  1755 		__( '%1$s %2$s, %3$s ago (%4$s)' ),
  1853 		__( '%1$s %2$s, %3$s ago (%4$s)' ),
  1756 		$gravatar,
  1854 		$gravatar,
  1760 	);
  1858 	);
  1761 
  1859 
  1762 	/* translators: %s: revision date with author avatar */
  1860 	/* translators: %s: revision date with author avatar */
  1763 	$autosavef = __( '%s [Autosave]' );
  1861 	$autosavef = __( '%s [Autosave]' );
  1764 	/* translators: %s: revision date with author avatar */
  1862 	/* translators: %s: revision date with author avatar */
  1765 	$currentf  = __( '%s [Current Revision]' );
  1863 	$currentf = __( '%s [Current Revision]' );
  1766 
  1864 
  1767 	if ( !wp_is_post_revision( $revision ) )
  1865 	if ( ! wp_is_post_revision( $revision ) ) {
  1768 		$revision_date_author = sprintf( $currentf, $revision_date_author );
  1866 		$revision_date_author = sprintf( $currentf, $revision_date_author );
  1769 	elseif ( wp_is_post_autosave( $revision ) )
  1867 	} elseif ( wp_is_post_autosave( $revision ) ) {
  1770 		$revision_date_author = sprintf( $autosavef, $revision_date_author );
  1868 		$revision_date_author = sprintf( $autosavef, $revision_date_author );
       
  1869 	}
  1771 
  1870 
  1772 	/**
  1871 	/**
  1773 	 * Filters the formatted author and date for a revision.
  1872 	 * Filters the formatted author and date for a revision.
  1774 	 *
  1873 	 *
  1775 	 * @since 4.4.0
  1874 	 * @since 4.4.0
  1781 	 */
  1880 	 */
  1782 	return apply_filters( 'wp_post_revision_title_expanded', $revision_date_author, $revision, $link );
  1881 	return apply_filters( 'wp_post_revision_title_expanded', $revision_date_author, $revision, $link );
  1783 }
  1882 }
  1784 
  1883 
  1785 /**
  1884 /**
  1786  * Display list of a post's revisions.
  1885  * Display a list of a post's revisions.
  1787  *
  1886  *
  1788  * Can output either a UL with edit links or a TABLE with diff interface, and
  1887  * Can output either a UL with edit links or a TABLE with diff interface, and
  1789  * restore action links.
  1888  * restore action links.
  1790  *
  1889  *
  1791  * @since 2.6.0
  1890  * @since 2.6.0
  1792  *
  1891  *
  1793  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
  1892  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
  1794  * @param string      $type    'all' (default), 'revision' or 'autosave'
  1893  * @param string      $type    'all' (default), 'revision' or 'autosave'
  1795  */
  1894  */
  1796 function wp_list_post_revisions( $post_id = 0, $type = 'all' ) {
  1895 function wp_list_post_revisions( $post_id = 0, $type = 'all' ) {
  1797 	if ( ! $post = get_post( $post_id ) )
  1896 	if ( ! $post = get_post( $post_id ) ) {
  1798 		return;
  1897 		return;
       
  1898 	}
  1799 
  1899 
  1800 	// $args array with (parent, format, right, left, type) deprecated since 3.6
  1900 	// $args array with (parent, format, right, left, type) deprecated since 3.6
  1801 	if ( is_array( $type ) ) {
  1901 	if ( is_array( $type ) ) {
  1802 		$type = ! empty( $type['type'] ) ? $type['type']  : $type;
  1902 		$type = ! empty( $type['type'] ) ? $type['type'] : $type;
  1803 		_deprecated_argument( __FUNCTION__, '3.6.0' );
  1903 		_deprecated_argument( __FUNCTION__, '3.6.0' );
  1804 	}
  1904 	}
  1805 
  1905 
  1806 	if ( ! $revisions = wp_get_post_revisions( $post->ID ) )
  1906 	if ( ! $revisions = wp_get_post_revisions( $post->ID ) ) {
  1807 		return;
  1907 		return;
       
  1908 	}
  1808 
  1909 
  1809 	$rows = '';
  1910 	$rows = '';
  1810 	foreach ( $revisions as $revision ) {
  1911 	foreach ( $revisions as $revision ) {
  1811 		if ( ! current_user_can( 'read_post', $revision->ID ) )
  1912 		if ( ! current_user_can( 'read_post', $revision->ID ) ) {
  1812 			continue;
  1913 			continue;
       
  1914 		}
  1813 
  1915 
  1814 		$is_autosave = wp_is_post_autosave( $revision );
  1916 		$is_autosave = wp_is_post_autosave( $revision );
  1815 		if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) )
  1917 		if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) {
  1816 			continue;
  1918 			continue;
       
  1919 		}
  1817 
  1920 
  1818 		$rows .= "\t<li>" . wp_post_revision_title_expanded( $revision ) . "</li>\n";
  1921 		$rows .= "\t<li>" . wp_post_revision_title_expanded( $revision ) . "</li>\n";
  1819 	}
  1922 	}
  1820 
  1923 
  1821 	echo "<div class='hide-if-js'><p>" . __( 'JavaScript must be enabled to use this feature.' ) . "</p></div>\n";
  1924 	echo "<div class='hide-if-js'><p>" . __( 'JavaScript must be enabled to use this feature.' ) . "</p></div>\n";
  1822 
  1925 
  1823 	echo "<ul class='post-revisions hide-if-no-js'>\n";
  1926 	echo "<ul class='post-revisions hide-if-no-js'>\n";
  1824 	echo $rows;
  1927 	echo $rows;
  1825 	echo "</ul>";
  1928 	echo '</ul>';
  1826 }
  1929 }