X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/febc815b2c9d85be5717da9e8d164bd2daa97e31..16e7b37c7914d753890c1a05a9335f3b43751eb8:/wp-includes/post-template.php diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index be152523..ac886433 100644 --- a/wp-includes/post-template.php +++ b/wp-includes/post-template.php @@ -30,14 +30,14 @@ 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 string|void 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 ) { $title = get_the_title(); @@ -247,11 +247,11 @@ 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 + * @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 $strip_teaser Optional. Strip teaser content before the more text. Default is false. @@ -594,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'; + } } } @@ -619,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() ) { @@ -671,36 +705,6 @@ function get_body_class( $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'; - - $template_slug = get_page_template_slug( $page_id ); - $template_parts = explode( '/', $template_slug ); - - foreach ( $template_parts as $part ) { - $classes[] = 'page-template-' . sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) ); - } - $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', $template_slug ) ); - } else { - $classes[] = 'page-template-default'; - } } if ( is_user_logged_in() ) @@ -779,20 +783,35 @@ function get_body_class( $class = '' ) { 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 ); } // @@ -1110,6 +1129,7 @@ function wp_dropdown_pages( $args = '' ) { * Retrieve or display list of pages in list (li) format. * * @since 1.5.0 + * @since 4.7.0 Added the `item_spacing` argument. * * @see get_pages() * @@ -1118,43 +1138,57 @@ function wp_dropdown_pages( $args = '' ) { * @param array|string $args { * Array or string of arguments. Optional. * - * @type int $child_of Display only the sub-pages of a single page by ID. Default 0 (all pages). - * @type string $authors Comma-separated list of author IDs. Default empty (all authors). - * @type string $date_format PHP date format to use for the listed pages. Relies on the 'show_date' parameter. - * Default is the value of 'date_format' option. - * @type int $depth Number of levels in the hierarchy of pages to include in the generated list. - * Accepts -1 (any depth), 0 (all pages), 1 (top-level pages only), and n (pages to - * the given n depth). Default 0. - * @type bool $echo Whether or not to echo the list of pages. Default true. - * @type string $exclude Comma-separated list of page IDs to exclude. Default empty. - * @type array $include Comma-separated list of page IDs to include. Default empty. - * @type string $link_after Text or HTML to follow the page link label. Default null. - * @type string $link_before Text or HTML to precede the page link label. Default null. - * @type string $post_type Post type to query for. Default 'page'. - * @type string $post_status Comma-separated list of post statuses to include. Default 'publish'. - * @type string $show_date Whether to display the page publish or modified date for each page. Accepts - * 'modified' or any other value. An empty value hides the date. Default empty. - * @type string $sort_column Comma-separated list of column names to sort the pages by. Accepts 'post_author', - * 'post_date', 'post_title', 'post_name', 'post_modified', 'post_modified_gmt', - * 'menu_order', 'post_parent', 'ID', 'rand', or 'comment_count'. Default 'post_title'. - * @type string $title_li List heading. Passing a null or empty value will result in no heading, and the list - * will not be wrapped with unordered list `