X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/9e77185fafaf4e60e2b73821e0e4b9b1a11fb85f..16e7b37c7914d753890c1a05a9335f3b43751eb8:/wp-includes/post-template.php
diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php
index c736e316..ac886433 100644
--- a/wp-includes/post-template.php
+++ b/wp-includes/post-template.php
@@ -21,9 +21,8 @@ function the_ID() {
* Retrieve the ID of the current item in the WordPress Loop.
*
* @since 2.1.0
- * @uses $post
*
- * @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();
@@ -31,16 +30,16 @@ function get_the_ID() {
}
/**
- * Display or retrieve the current post title with optional content.
+ * Display or retrieve the current post title with optional markup.
*
* @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 $before Optional. Markup to prepend to the title. Default empty.
+ * @param string $after Optional. Markup to append to the title. Default empty.
+ * @param bool $echo Optional. Whether to echo or return the title. Default true for echo.
+ * @return string|void Current post title if $echo is false.
*/
-function the_title($before = '', $after = '', $echo = true) {
+function the_title( $before = '', $after = '', $echo = true ) {
$title = get_the_title();
if ( strlen($title) == 0 )
@@ -57,12 +56,12 @@ function the_title($before = '', $after = '', $echo = true) {
/**
* Sanitize the current title when retrieving or displaying.
*
- * Works like {@link the_title()}, except the parameters can be in a string or
+ * Works like the_title(), except the parameters can be in a string or
* an array. See the function for what can be override in the $args parameter.
*
- * The title before it is displayed will have the tags stripped and {@link
- * esc_attr()} before it is passed to the user or displayed. The default
- * as with {@link the_title()}, is to display the title.
+ * The title before it is displayed will have the tags stripped and esc_attr()
+ * before it is passed to the user or displayed. The default as with the_title(),
+ * is to display the title.
*
* @since 2.3.0
*
@@ -74,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() );
@@ -118,7 +117,7 @@ function get_the_title( $post = 0 ) {
if ( ! empty( $post->post_password ) ) {
/**
- * Filter the text prepended to the post title for protected posts.
+ * Filters the text prepended to the post title for protected posts.
*
* The filter is only applied on the front end.
*
@@ -130,10 +129,10 @@ 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.
+ * Filters the text prepended to the post title of private posts.
*
* The filter is only applied on the front end.
*
@@ -149,7 +148,7 @@ function get_the_title( $post = 0 ) {
}
/**
- * Filter the post title.
+ * Filters the post title.
*
* @since 0.71
*
@@ -162,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;
+
+ /**
+ * Filters 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 );
}
/**
@@ -185,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.
+ * Filters 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 );
}
/**
@@ -207,13 +225,13 @@ function get_the_guid( $id = 0 ) {
* @since 0.71
*
* @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.
*/
function the_content( $more_link_text = null, $strip_teaser = false) {
$content = get_the_content( $more_link_text, $strip_teaser );
/**
- * Filter the post content.
+ * Filters the post content.
*
* @since 0.71
*
@@ -229,8 +247,14 @@ function the_content( $more_link_text = null, $strip_teaser = false) {
*
* @since 0.71
*
+ * @global int $page Page number of a single post/page.
+ * @global int $more Boolean indicator for whether single post/page is being viewed.
+ * @global bool $preview Whether post/page is in preview mode.
+ * @global array $pages Array of all pages in post/page. Each array element contains part of the content separated by the tag.
+ * @global int $multipage Boolean indicator for whether multiple pages are in play.
+ *
* @param string $more_link_text Optional. Content for when there is more text.
- * @param bool $stripteaser 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 ) {
@@ -238,8 +262,17 @@ function get_the_content( $more_link_text = null, $strip_teaser = false ) {
$post = get_post();
- if ( null === $more_link_text )
- $more_link_text = __( '(more…)' );
+ if ( null === $more_link_text ) {
+ $more_link_text = sprintf(
+ '%2$s',
+ sprintf(
+ /* translators: %s: Name of current post */
+ __( 'Continue reading %s' ),
+ the_title_attribute( array( 'echo' => false ) )
+ ),
+ __( '(more…)' )
+ );
+ }
$output = '';
$has_teaser = false;
@@ -279,7 +312,7 @@ function get_the_content( $more_link_text = null, $strip_teaser = false ) {
if ( ! empty( $more_link_text ) )
/**
- * Filter the Read More link text.
+ * Filters the Read More link text.
*
* @since 2.8.0
*
@@ -291,18 +324,19 @@ function get_the_content( $more_link_text = null, $strip_teaser = false ) {
}
}
- if ( $preview ) // preview fix for javascript bug with foreign languages
+ if ( $preview ) // Preview fix for JavaScript bug with foreign languages.
$output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output );
return $output;
}
/**
- * Preview fix for javascript bug with foreign languages
+ * Preview fix for JavaScript bug with foreign languages.
*
* @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 ) {
@@ -317,7 +351,7 @@ function _convert_urlencoded_to_entities( $match ) {
function the_excerpt() {
/**
- * Filter the displayed post excerpt.
+ * Filters the displayed post excerpt.
*
* @since 0.71
*
@@ -329,34 +363,38 @@ 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 ) )
- _deprecated_argument( __FUNCTION__, '2.3' );
+function get_the_excerpt( $post = null ) {
+ if ( is_bool( $post ) ) {
+ _deprecated_argument( __FUNCTION__, '2.3.0' );
+ }
- $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.' );
}
/**
- * Filter the retrieved post excerpt.
+ * Filters 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 );
}
/**
@@ -377,8 +415,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
@@ -386,30 +424,44 @@ function post_class( $class = '', $post_id = null ) {
}
/**
- * Retrieve the classes for the post div as an array.
+ * Retrieves the classes for the post div as an array.
*
* 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, {@see '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() )
@@ -427,11 +479,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';
}
@@ -447,40 +505,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.
+ * Filters 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 );
@@ -504,11 +562,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();
@@ -534,23 +594,40 @@ function get_body_class( $class = '' ) {
if ( is_404() )
$classes[] = 'error404';
- if ( is_single() ) {
+ if ( is_singular() ) {
$post_id = $wp_query->get_queried_object_id();
$post = $wp_query->get_queried_object();
+ $post_type = $post->post_type;
- $classes[] = 'single';
- if ( isset( $post->post_type ) ) {
- $classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id);
- $classes[] = 'postid-' . $post_id;
+ if ( is_page_template() ) {
+ $classes[] = "{$post_type}-template";
- // Post Format
- if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
- $post_format = get_post_format( $post->ID );
+ $template_slug = get_page_template_slug( $post_id );
+ $template_parts = explode( '/', $template_slug );
- if ( $post_format && !is_wp_error($post_format) )
- $classes[] = 'single-format-' . sanitize_html_class( $post_format );
- else
- $classes[] = 'single-format-standard';
+ foreach ( $template_parts as $part ) {
+ $classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) );
+ }
+ $classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( '.', '-', $template_slug ) );
+ } else {
+ $classes[] = "{$post_type}-template-default";
+ }
+
+ if ( is_single() ) {
+ $classes[] = 'single';
+ if ( isset( $post->post_type ) ) {
+ $classes[] = 'single-' . sanitize_html_class( $post->post_type, $post_id );
+ $classes[] = 'postid-' . $post_id;
+
+ // Post Format
+ if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
+ $post_format = get_post_format( $post->ID );
+
+ if ( $post_format && !is_wp_error($post_format) )
+ $classes[] = 'single-format-' . sanitize_html_class( $post_format );
+ else
+ $classes[] = 'single-format-standard';
+ }
}
}
@@ -559,6 +636,23 @@ function get_body_class( $class = '' ) {
$mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
$classes[] = 'attachmentid-' . $post_id;
$classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );
+ } elseif ( is_page() ) {
+ $classes[] = 'page';
+
+ $page_id = $wp_query->get_queried_object_id();
+
+ $post = get_post($page_id);
+
+ $classes[] = 'page-id-' . $page_id;
+
+ if ( get_pages( array( 'parent' => $page_id, 'number' => 1 ) ) ) {
+ $classes[] = 'page-parent';
+ }
+
+ if ( $post->post_parent ) {
+ $classes[] = 'page-child';
+ $classes[] = 'parent-pageid-' . $post->post_parent;
+ }
}
} elseif ( is_archive() ) {
if ( is_post_type_archive() ) {
@@ -567,7 +661,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 ) ) {
@@ -578,47 +672,39 @@ 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;
}
}
- } elseif ( is_page() ) {
- $classes[] = 'page';
-
- $page_id = $wp_query->get_queried_object_id();
-
- $post = get_post($page_id);
-
- $classes[] = 'page-id-' . $page_id;
-
- if ( get_pages( array( 'parent' => $page_id, 'number' => 1 ) ) ) {
- $classes[] = 'page-parent';
- }
-
- if ( $post->post_parent ) {
- $classes[] = 'page-child';
- $classes[] = 'parent-pageid-' . $post->post_parent;
- }
- if ( is_page_template() ) {
- $classes[] = 'page-template';
- $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_page_template_slug( $page_id ) ) );
- } else {
- $classes[] = 'page-template-default';
- }
}
if ( is_user_logged_in() )
@@ -629,9 +715,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 )
@@ -670,12 +760,12 @@ function get_body_class( $class = '' ) {
$classes = array_map( 'esc_attr', $classes );
/**
- * Filter the list of CSS body classes for the current post or page.
+ * Filters the list of CSS body classes for the current post or page.
*
* @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 );
@@ -687,26 +777,41 @@ 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 ) {
$post = get_post($post);
- if ( empty( $post->post_password ) )
- return false;
+ if ( empty( $post->post_password ) ) {
+ /** This filter is documented in wp-includes/post.php */
+ return apply_filters( 'post_password_required', false, $post );
+ }
- if ( ! isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) )
- return true;
+ if ( ! isset( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ) ) {
+ /** This filter is documented in wp-includes/post.php */
+ return apply_filters( 'post_password_required', true, $post );
+ }
- require_once ABSPATH . WPINC . '/class-phpass.php';
$hasher = new PasswordHash( 8, true );
$hash = wp_unslash( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] );
- if ( 0 !== strpos( $hash, '$P$B' ) )
- return true;
+ if ( 0 !== strpos( $hash, '$P$B' ) ) {
+ $required = true;
+ } else {
+ $required = ! $hasher->CheckPassword( $post->post_password, $hash );
+ }
- return ! $hasher->CheckPassword( $post->post_password, $hash );
+ /**
+ * Filters whether a post requires the user to supply a password.
+ *
+ * @since 4.7.0
+ *
+ * @param bool $required Whether the user needs to supply a password. True if password has not been
+ * provided or is incorrect, false if password has been supplied or is not required.
+ * @param WP_Post $post Post data.
+ */
+ return apply_filters( 'post_password_required', $required, $post );
}
//
@@ -721,14 +826,19 @@ 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.
*
- * @type string $before HTML or text to prepend to each link. Default is '
Pages:'.
- * @type string $after HTML or text to append to each link. Default is '