X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/9e77185fafaf4e60e2b73821e0e4b9b1a11fb85f..53f4633144ed68c8b8fb5861f992b5489894a940:/wp-includes/post-template.php diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index c736e316..1b4901cc 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(); @@ -36,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 ) @@ -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() ); @@ -130,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. @@ -173,7 +172,16 @@ function get_the_title( $post = 0 ) { * @param int|WP_Post $id Optional. Post ID or post object. */ function the_guid( $id = 0 ) { - echo esc_url( get_the_guid( $id ) ); + /** + * Filter the escaped Global Unique Identifier (guid) of the post. + * + * @since 4.2.0 + * + * @see get_the_guid() + * + * @param string $post_guid Escaped Global Unique Identifier (guid) of the post. + */ + echo apply_filters( 'the_guid', get_the_guid( $id ) ); } /** @@ -207,7 +215,7 @@ 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 ); @@ -229,8 +237,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 $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 ) { @@ -291,14 +305,14 @@ 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 @@ -390,26 +404,35 @@ 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 ); + } + + if ( ! $post ) { return $classes; + } $classes[] = 'post-' . $post->ID; if ( ! is_admin() ) @@ -447,31 +470,31 @@ 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. @@ -504,6 +527,9 @@ function body_class( $class = '' ) { * * @since 2.8.0 * + * @global WP_Query $wp_query + * @global wpdb $wpdb + * * @param string|array $class One or more classes to add to the class list. * @return array Array of classes. */ @@ -567,7 +593,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,21 +604,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; } } @@ -615,7 +656,14 @@ function get_body_class( $class = '' ) { } if ( is_page_template() ) { $classes[] = 'page-template'; - $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_page_template_slug( $page_id ) ) ); + + $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'; } @@ -629,7 +677,7 @@ 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'; $page = $wp_query->get( 'page' ); @@ -687,7 +735,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 ) { @@ -721,14 +769,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 '

'. - * @type string $link_before HTML or text to prepend to each link, inside the tag. + * @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 `

`. + * @type string $link_before HTML or text to prepend to each link, inside the `
` tag. * Also prepended to the current item, which is not linked. Default empty. - * @type string $link_after HTML or text to append to each Pages link inside the tag. + * @type string $link_after HTML or text to append to each Pages link inside the `` tag. * Also appended to the current item, which is not linked. Default empty. * @type string $next_or_number Indicates whether page numbers should be used. Valid values are number * and next. Default is 'number'. @@ -743,6 +796,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' => '

', @@ -767,8 +822,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'] ) { @@ -787,7 +840,10 @@ function wp_link_pages( $args = '' ) { * @param int $i Page number for paginated posts' page links. */ $link = apply_filters( 'wp_link_pages_link', $link, $i ); - $output .= $r['separator'] . $link; + + // Use the custom links separator beginning with the second link. + $output .= ( 1 === $i ) ? ' ' : $r['separator']; + $output .= $link; } $output .= $r['after']; } elseif ( $more ) { @@ -797,16 +853,17 @@ function wp_link_pages( $args = '' ) { $link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '
'; /** This filter is documented in wp-includes/post-template.php */ - $link = apply_filters( 'wp_link_pages_link', $link, $prev ); - $output .= $r['separator'] . $link; + $output .= apply_filters( 'wp_link_pages_link', $link, $prev ); } $next = $page + 1; if ( $next <= $numpages ) { + if ( $prev ) { + $output .= $r['separator']; + } $link = _wp_link_page( $next ) . $r['link_before'] . $r['nextpagelink'] . $r['link_after'] . ''; /** This filter is documented in wp-includes/post-template.php */ - $link = apply_filters( 'wp_link_pages_link', $link, $next ); - $output .= $r['separator'] . $link; + $output .= apply_filters( 'wp_link_pages_link', $link, $next ); } $output .= $r['after']; } @@ -834,6 +891,8 @@ function wp_link_pages( $args = '' ) { * @since 3.1.0 * @access private * + * @global WP_Rewrite $wp_rewrite + * * @param int $i Page number. * @return string Link. */ @@ -878,7 +937,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(); @@ -896,7 +955,6 @@ function post_custom( $key = '' ) { * * @internal This will probably change at some point... * @since 1.2.0 - * @uses apply_filters() Calls 'the_meta_key' on list item HTML content, with key and value as separate parameters. */ function the_meta() { if ( $keys = get_post_custom_keys() ) { @@ -931,8 +989,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 = '' ) { @@ -940,8 +1018,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 ); @@ -954,7 +1034,12 @@ function wp_dropdown_pages( $args = '' ) { } if ( ! empty( $pages ) ) { - $output = "\n"; if ( $r['show_option_no_change'] ) { $output .= "\t\n"; } @@ -987,6 +1072,8 @@ function wp_dropdown_pages( $args = '' ) { * * @see get_pages() * + * @global WP_Query $wp_query + * * @param array|string $args { * Array or string of arguments. Optional. * @@ -1013,7 +1100,7 @@ function wp_dropdown_pages( $args = '' ) { * will not be wrapped with unordered list `