X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/af50974463450c98503e763a7836a50e260461a9..d3947bc013df7edd54b46deed8230d2eeafc5ecb:/wp-includes/post-template.php?ds=sidebyside
diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php
index f13a458b..a441d742 100644
--- a/wp-includes/post-template.php
+++ b/wp-includes/post-template.php
@@ -22,7 +22,7 @@ function the_ID() {
*
* @since 2.1.0
*
- * @return int|bool The ID of the current item in the WordPress Loop. False if $post is not set.
+ * @return int|false The ID of the current item in the WordPress Loop. False if $post is not set.
*/
function get_the_ID() {
$post = get_post();
@@ -35,11 +35,11 @@ function get_the_ID() {
* @since 0.71
*
* @param string $before Optional. Content to prepend to the title.
- * @param string $after Optional. Content to append to the title.
- * @param bool $echo Optional, default to true.Whether to display or return.
- * @return null|string Null on no title. String if $echo parameter is false.
+ * @param string $after Optional. Content to append to the title.
+ * @param bool $echo Optional, default to true.Whether to display or return.
+ * @return string|void String if $echo parameter is false.
*/
-function the_title($before = '', $after = '', $echo = true) {
+function the_title( $before = '', $after = '', $echo = true ) {
$title = get_the_title();
if ( strlen($title) == 0 )
@@ -73,7 +73,7 @@ function the_title($before = '', $after = '', $echo = true) {
* @type bool $echo Whether to echo or return the title. Default true for echo.
* @type WP_Post $post Current post object to retrieve the title for.
* }
- * @return string|null Null on failure or display. String when echo is false.
+ * @return string|void String when echo is false.
*/
function the_title_attribute( $args = '' ) {
$defaults = array( 'before' => '', 'after' => '', 'echo' => true, 'post' => get_post() );
@@ -129,7 +129,7 @@ function get_the_title( $post = 0 ) {
*/
$protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ), $post );
$title = sprintf( $protected_title_format, $title );
- } else if ( isset( $post->post_status ) && 'private' == $post->post_status ) {
+ } elseif ( isset( $post->post_status ) && 'private' == $post->post_status ) {
/**
* Filter the text prepended to the post title of private posts.
@@ -161,18 +161,33 @@ function get_the_title( $post = 0 ) {
/**
* Display the Post Global Unique Identifier (guid).
*
- * The guid will appear to be a link, but should not be used as an link to the
+ * The guid will appear to be a link, but should not be used as a link to the
* post. The reason you should not use it as a link, is because of moving the
* blog across domains.
*
- * Url is escaped to make it xml safe
+ * URL is escaped to make it XML-safe.
*
* @since 1.5.0
*
- * @param int|WP_Post $id Optional. Post ID or post object.
+ * @param int|WP_Post $post Optional. Post ID or post object. Default is global $post.
*/
-function the_guid( $id = 0 ) {
- echo esc_url( get_the_guid( $id ) );
+function the_guid( $post = 0 ) {
+ $post = get_post( $post );
+
+ $guid = isset( $post->guid ) ? get_the_guid( $post ) : '';
+ $id = isset( $post->ID ) ? $post->ID : 0;
+
+ /**
+ * Filter the escaped Global Unique Identifier (guid) of the post.
+ *
+ * @since 4.2.0
+ *
+ * @see get_the_guid()
+ *
+ * @param string $guid Escaped Global Unique Identifier (guid) of the post.
+ * @param int $id The post ID.
+ */
+ echo apply_filters( 'the_guid', $guid, $id );
}
/**
@@ -184,20 +199,24 @@ function the_guid( $id = 0 ) {
*
* @since 1.5.0
*
- * @param int|WP_Post $id Optional. Post ID or post object.
+ * @param int|WP_Post $post Optional. Post ID or post object. Default is global $post.
* @return string
*/
-function get_the_guid( $id = 0 ) {
- $post = get_post($id);
+function get_the_guid( $post = 0 ) {
+ $post = get_post( $post );
+
+ $guid = isset( $post->guid ) ? $post->guid : '';
+ $id = isset( $post->ID ) ? $post->ID : 0;
/**
* Filter the Global Unique Identifier (guid) of the post.
*
* @since 1.5.0
*
- * @param string $post_guid Global Unique Identifier (guid) of the post.
+ * @param string $guid Global Unique Identifier (guid) of the post.
+ * @param int $id The post ID.
*/
- return apply_filters( 'get_the_guid', $post->guid );
+ return apply_filters( 'get_the_guid', $guid, $id );
}
/**
@@ -228,8 +247,14 @@ function the_content( $more_link_text = null, $strip_teaser = false) {
*
* @since 0.71
*
+ * @global int $page
+ * @global int $more
+ * @global bool $preview
+ * @global array $pages
+ * @global int $multipage
+ *
* @param string $more_link_text Optional. Content for when there is more text.
- * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
+ * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
* @return string
*/
function get_the_content( $more_link_text = null, $strip_teaser = false ) {
@@ -301,7 +326,8 @@ function get_the_content( $more_link_text = null, $strip_teaser = false ) {
*
* @since 3.1.0
* @access private
- * @param array $match Match array from preg_replace_callback
+ *
+ * @param array $match Match array from preg_replace_callback.
* @return string
*/
function _convert_urlencoded_to_entities( $match ) {
@@ -328,23 +354,25 @@ function the_excerpt() {
}
/**
- * Retrieve the post excerpt.
+ * Retrieves the post excerpt.
*
* @since 0.71
+ * @since 4.5.0 Introduced the `$post` parameter.
*
- * @param mixed $deprecated Not used.
- * @return string
+ * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
+ * @return string Post excerpt.
*/
-function get_the_excerpt( $deprecated = '' ) {
- if ( !empty( $deprecated ) )
+function get_the_excerpt( $post = null ) {
+ if ( is_bool( $post ) ) {
_deprecated_argument( __FUNCTION__, '2.3' );
+ }
- $post = get_post();
+ $post = get_post( $post );
if ( empty( $post ) ) {
return '';
}
- if ( post_password_required() ) {
+ if ( post_password_required( $post ) ) {
return __( 'There is no excerpt because this is a protected post.' );
}
@@ -352,10 +380,12 @@ function get_the_excerpt( $deprecated = '' ) {
* Filter the retrieved post excerpt.
*
* @since 1.2.0
+ * @since 4.5.0 Introduced the `$post` parameter.
*
* @param string $post_excerpt The post excerpt.
+ * @param WP_Post $post Post object.
*/
- return apply_filters( 'get_the_excerpt', $post->post_excerpt );
+ return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );
}
/**
@@ -376,8 +406,8 @@ function has_excerpt( $id = 0 ) {
*
* @since 2.7.0
*
- * @param string|array $class One or more classes to add to the class list.
- * @param int|WP_Post $post_id Optional. Post ID or post object.
+ * @param string|array $class One or more classes to add to the class list.
+ * @param int|WP_Post $post_id Optional. Post ID or post object. Defaults to the global `$post`.
*/
function post_class( $class = '', $post_id = null ) {
// Separates classes with a single space, collates classes for post DIV
@@ -389,26 +419,38 @@ function post_class( $class = '', $post_id = null ) {
*
* The class names are many. If the post is a sticky, then the 'sticky'
* class name. The class 'hentry' is always added to each post. If the post has a
- * post thumbnail, 'has-post-thumbnail' is added as a class. For each
- * category, the class will be added with 'category-' with category slug is
- * added. The tags are the same way as the categories with 'tag-' before the tag
- * slug. All classes are passed through the filter, 'post_class' with the list
- * of classes, followed by $class parameter value, with the post ID as the last
- * parameter.
+ * post thumbnail, 'has-post-thumbnail' is added as a class. For each taxonomy that
+ * the post belongs to, a class will be added of the format '{$taxonomy}-{$slug}' -
+ * eg 'category-foo' or 'my_custom_taxonomy-bar'. The 'post_tag' taxonomy is a special
+ * case; the class has the 'tag-' prefix instead of 'post_tag-'. All classes are
+ * passed through the filter, 'post_class' with the list of classes, followed by
+ * $class parameter value, with the post ID as the last parameter.
*
* @since 2.7.0
+ * @since 4.2.0 Custom taxonomy classes were added.
*
- * @param string|array $class One or more classes to add to the class list.
- * @param int|WP_Post $post_id Optional. Post ID or post object.
+ * @param string|array $class One or more classes to add to the class list.
+ * @param int|WP_Post $post_id Optional. Post ID or post object.
* @return array Array of classes.
*/
function get_post_class( $class = '', $post_id = null ) {
- $post = get_post($post_id);
+ $post = get_post( $post_id );
$classes = array();
- if ( empty($post) )
+ if ( $class ) {
+ if ( ! is_array( $class ) ) {
+ $class = preg_split( '#\s+#', $class );
+ }
+ $classes = array_map( 'esc_attr', $class );
+ } else {
+ // Ensure that we always coerce class to being an array.
+ $class = array();
+ }
+
+ if ( ! $post ) {
return $classes;
+ }
$classes[] = 'post-' . $post->ID;
if ( ! is_admin() )
@@ -426,11 +468,17 @@ function get_post_class( $class = '', $post_id = null ) {
$classes[] = 'format-standard';
}
- // Post requires password
- if ( post_password_required( $post->ID ) ) {
+ $post_password_required = post_password_required( $post->ID );
+
+ // Post requires password.
+ if ( $post_password_required ) {
$classes[] = 'post-password-required';
- // Post thumbnails
- } elseif ( ! is_attachment( $post ) && current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) ) {
+ } elseif ( ! empty( $post->post_password ) ) {
+ $classes[] = 'post-password-protected';
+ }
+
+ // Post thumbnails.
+ if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) && ! is_attachment( $post ) && ! $post_password_required ) {
$classes[] = 'has-post-thumbnail';
}
@@ -446,40 +494,40 @@ function get_post_class( $class = '', $post_id = null ) {
// hentry for hAtom compliance
$classes[] = 'hentry';
- // Categories
- if ( is_object_in_taxonomy( $post->post_type, 'category' ) ) {
- foreach ( (array) get_the_category($post->ID) as $cat ) {
- if ( empty($cat->slug ) )
- continue;
- $classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->term_id);
- }
- }
+ // All public taxonomies
+ $taxonomies = get_taxonomies( array( 'public' => true ) );
+ foreach ( (array) $taxonomies as $taxonomy ) {
+ if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) {
+ foreach ( (array) get_the_terms( $post->ID, $taxonomy ) as $term ) {
+ if ( empty( $term->slug ) ) {
+ continue;
+ }
- // Tags
- if ( is_object_in_taxonomy( $post->post_type, 'post_tag' ) ) {
- foreach ( (array) get_the_tags($post->ID) as $tag ) {
- if ( empty($tag->slug ) )
- continue;
- $classes[] = 'tag-' . sanitize_html_class($tag->slug, $tag->term_id);
- }
- }
+ $term_class = sanitize_html_class( $term->slug, $term->term_id );
+ if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) {
+ $term_class = $term->term_id;
+ }
- if ( !empty($class) ) {
- if ( !is_array( $class ) )
- $class = preg_split('#\s+#', $class);
- $classes = array_merge($classes, $class);
+ // 'post_tag' uses the 'tag' prefix for backward compatibility.
+ if ( 'post_tag' == $taxonomy ) {
+ $classes[] = 'tag-' . $term_class;
+ } else {
+ $classes[] = sanitize_html_class( $taxonomy . '-' . $term_class, $taxonomy . '-' . $term->term_id );
+ }
+ }
+ }
}
- $classes = array_map('esc_attr', $classes);
+ $classes = array_map( 'esc_attr', $classes );
/**
* Filter the list of CSS classes for the current post.
*
* @since 2.7.0
*
- * @param array $classes An array of post classes.
- * @param string $class A comma-separated list of additional classes added to the post.
- * @param int $post_id The post ID.
+ * @param array $classes An array of post classes.
+ * @param array $class An array of additional classes added to the post.
+ * @param int $post_id The post ID.
*/
$classes = apply_filters( 'post_class', $classes, $class, $post->ID );
@@ -503,11 +551,13 @@ function body_class( $class = '' ) {
*
* @since 2.8.0
*
+ * @global WP_Query $wp_query
+ *
* @param string|array $class One or more classes to add to the class list.
* @return array Array of classes.
*/
function get_body_class( $class = '' ) {
- global $wp_query, $wpdb;
+ global $wp_query;
$classes = array();
@@ -532,6 +582,9 @@ function get_body_class( $class = '' ) {
$classes[] = 'attachment';
if ( is_404() )
$classes[] = 'error404';
+ if ( is_singular() ) {
+ $classes[] = 'singular';
+ }
if ( is_single() ) {
$post_id = $wp_query->get_queried_object_id();
@@ -566,7 +619,7 @@ function get_body_class( $class = '' ) {
if ( is_array( $post_type ) )
$post_type = reset( $post_type );
$classes[] = 'post-type-archive-' . sanitize_html_class( $post_type );
- } else if ( is_author() ) {
+ } elseif ( is_author() ) {
$author = $wp_query->get_queried_object();
$classes[] = 'author';
if ( isset( $author->user_nicename ) ) {
@@ -577,21 +630,36 @@ function get_body_class( $class = '' ) {
$cat = $wp_query->get_queried_object();
$classes[] = 'category';
if ( isset( $cat->term_id ) ) {
- $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id );
+ $cat_class = sanitize_html_class( $cat->slug, $cat->term_id );
+ if ( is_numeric( $cat_class ) || ! trim( $cat_class, '-' ) ) {
+ $cat_class = $cat->term_id;
+ }
+
+ $classes[] = 'category-' . $cat_class;
$classes[] = 'category-' . $cat->term_id;
}
} elseif ( is_tag() ) {
- $tags = $wp_query->get_queried_object();
+ $tag = $wp_query->get_queried_object();
$classes[] = 'tag';
- if ( isset( $tags->term_id ) ) {
- $classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id );
- $classes[] = 'tag-' . $tags->term_id;
+ if ( isset( $tag->term_id ) ) {
+ $tag_class = sanitize_html_class( $tag->slug, $tag->term_id );
+ if ( is_numeric( $tag_class ) || ! trim( $tag_class, '-' ) ) {
+ $tag_class = $tag->term_id;
+ }
+
+ $classes[] = 'tag-' . $tag_class;
+ $classes[] = 'tag-' . $tag->term_id;
}
} elseif ( is_tax() ) {
$term = $wp_query->get_queried_object();
if ( isset( $term->term_id ) ) {
+ $term_class = sanitize_html_class( $term->slug, $term->term_id );
+ if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) {
+ $term_class = $term->term_id;
+ }
+
$classes[] = 'tax-' . sanitize_html_class( $term->taxonomy );
- $classes[] = 'term-' . sanitize_html_class( $term->slug, $term->term_id );
+ $classes[] = 'term-' . $term_class;
$classes[] = 'term-' . $term->term_id;
}
}
@@ -635,9 +703,13 @@ function get_body_class( $class = '' ) {
$classes[] = 'no-customize-support';
}
- if ( get_theme_mod( 'background_color' ) || get_background_image() )
+ if ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() )
$classes[] = 'custom-background';
+ if ( has_custom_logo() ) {
+ $classes[] = 'wp-custom-logo';
+ }
+
$page = $wp_query->get( 'page' );
if ( ! $page || $page < 2 )
@@ -680,8 +752,8 @@ function get_body_class( $class = '' ) {
*
* @since 2.8.0
*
- * @param array $classes An array of body classes.
- * @param string $class A comma-separated list of additional classes added to the body.
+ * @param array $classes An array of body classes.
+ * @param array $class An array of additional classes added to the body.
*/
$classes = apply_filters( 'body_class', $classes, $class );
@@ -693,7 +765,7 @@ function get_body_class( $class = '' ) {
*
* @since 2.7.0
*
- * @param int|WP_Post $post An optional post. Global $post used if not provided.
+ * @param int|WP_Post|null $post An optional post. Global $post used if not provided.
* @return bool false if a password is not required or the correct password cookie is present, true otherwise.
*/
function post_password_required( $post = null ) {
@@ -727,6 +799,11 @@ function post_password_required( $post = null ) {
*
* @since 1.2.0
*
+ * @global int $page
+ * @global int $numpages
+ * @global int $multipage
+ * @global int $more
+ *
* @param string|array $args {
* Optional. Array or string of default arguments.
*
@@ -749,6 +826,8 @@ function post_password_required( $post = null ) {
* @return string Formatted output in HTML.
*/
function wp_link_pages( $args = '' ) {
+ global $page, $numpages, $multipage, $more;
+
$defaults = array(
'before' => '
' . __( 'Pages:' ),
'after' => '
',
@@ -773,8 +852,6 @@ function wp_link_pages( $args = '' ) {
*/
$r = apply_filters( 'wp_link_pages_args', $params );
- global $page, $numpages, $multipage, $more;
-
$output = '';
if ( $multipage ) {
if ( 'number' == $r['next_or_number'] ) {
@@ -802,7 +879,7 @@ function wp_link_pages( $args = '' ) {
} elseif ( $more ) {
$output .= $r['before'];
$prev = $page - 1;
- if ( $prev ) {
+ if ( $prev > 0 ) {
$link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '';
/** This filter is documented in wp-includes/post-template.php */
@@ -844,12 +921,15 @@ function wp_link_pages( $args = '' ) {
* @since 3.1.0
* @access private
*
+ * @global WP_Rewrite $wp_rewrite
+ *
* @param int $i Page number.
* @return string Link.
*/
function _wp_link_page( $i ) {
global $wp_rewrite;
$post = get_post();
+ $query_args = array();
if ( 1 == $i ) {
$url = get_permalink();
@@ -863,16 +943,13 @@ function _wp_link_page( $i ) {
}
if ( is_preview() ) {
- $url = add_query_arg( array(
- 'preview' => 'true'
- ), $url );
if ( ( 'draft' !== $post->post_status ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) {
- $url = add_query_arg( array(
- 'preview_id' => wp_unslash( $_GET['preview_id'] ),
- 'preview_nonce' => wp_unslash( $_GET['preview_nonce'] )
- ), $url );
+ $query_args['preview_id'] = wp_unslash( $_GET['preview_id'] );
+ $query_args['preview_nonce'] = wp_unslash( $_GET['preview_nonce'] );
}
+
+ $url = get_preview_post_link( $post, $query_args, $url );
}
return '';
@@ -888,7 +965,7 @@ function _wp_link_page( $i ) {
* @since 1.5.0
*
* @param string $key Meta data key name.
- * @return bool|string|array Array of values or single value, if only one element exists. False will be returned if key does not exist.
+ * @return false|string|array Array of values or single value, if only one element exists. False will be returned if key does not exist.
*/
function post_custom( $key = '' ) {
$custom = get_post_custom();
@@ -904,8 +981,10 @@ function post_custom( $key = '' ) {
/**
* Display list of post custom fields.
*
- * @internal This will probably change at some point...
* @since 1.2.0
+ *
+ * @internal This will probably change at some point...
+ *
*/
function the_meta() {
if ( $keys = get_post_custom_keys() ) {
@@ -940,8 +1019,28 @@ function the_meta() {
* Retrieve or display list of pages as a dropdown (select list).
*
* @since 2.1.0
+ * @since 4.2.0 The `$value_field` argument was added.
+ * @since 4.3.0 The `$class` argument was added.
*
- * @param array|string $args Optional. Override default arguments.
+ * @param array|string $args {
+ * Optional. Array or string of arguments to generate a pages drop-down element.
+ *
+ * @type int $depth Maximum depth. Default 0.
+ * @type int $child_of Page ID to retrieve child pages of. Default 0.
+ * @type int|string $selected Value of the option that should be selected. Default 0.
+ * @type bool|int $echo Whether to echo or return the generated markup. Accepts 0, 1,
+ * or their bool equivalents. Default 1.
+ * @type string $name Value for the 'name' attribute of the select element.
+ * Default 'page_id'.
+ * @type string $id Value for the 'id' attribute of the select element.
+ * @type string $class Value for the 'class' attribute of the select element. Default: none.
+ * Defaults to the value of `$name`.
+ * @type string $show_option_none Text to display for showing no pages. Default empty (does not display).
+ * @type string $show_option_no_change Text to display for "no change" option. Default empty (does not display).
+ * @type string $option_none_value Value to use when no page is selected. Default empty.
+ * @type string $value_field Post field used to populate the 'value' attribute of the option
+ * elements. Accepts any valid post field. Default 'ID'.
+ * }
* @return string HTML content, if not displaying.
*/
function wp_dropdown_pages( $args = '' ) {
@@ -949,8 +1048,10 @@ function wp_dropdown_pages( $args = '' ) {
'depth' => 0, 'child_of' => 0,
'selected' => 0, 'echo' => 1,
'name' => 'page_id', 'id' => '',
+ 'class' => '',
'show_option_none' => '', 'show_option_no_change' => '',
- 'option_none_value' => ''
+ 'option_none_value' => '',
+ 'value_field' => 'ID',
);
$r = wp_parse_args( $args, $defaults );
@@ -963,7 +1064,12 @@ function wp_dropdown_pages( $args = '' ) {
}
if ( ! empty( $pages ) ) {
- $output = "