Sanity checks in get_body_class() to ensure we are operating on the type of queried object that we expect. props wonderboymusic. fixes #17662.
git-svn-id: http://core.svn.wordpress.org/trunk@22451 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
f85592021d
commit
9beec00613
|
@ -429,17 +429,19 @@ function get_body_class( $class = '' ) {
|
||||||
$post = $wp_query->get_queried_object();
|
$post = $wp_query->get_queried_object();
|
||||||
|
|
||||||
$classes[] = 'single';
|
$classes[] = 'single';
|
||||||
$classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id);
|
if ( isset( $post->post_type ) ) {
|
||||||
$classes[] = 'postid-' . $post_id;
|
$classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id);
|
||||||
|
$classes[] = 'postid-' . $post_id;
|
||||||
|
|
||||||
// Post Format
|
// Post Format
|
||||||
if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
|
if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
|
||||||
$post_format = get_post_format( $post->ID );
|
$post_format = get_post_format( $post->ID );
|
||||||
|
|
||||||
if ( $post_format && !is_wp_error($post_format) )
|
if ( $post_format && !is_wp_error($post_format) )
|
||||||
$classes[] = 'single-format-' . sanitize_html_class( $post_format );
|
$classes[] = 'single-format-' . sanitize_html_class( $post_format );
|
||||||
else
|
else
|
||||||
$classes[] = 'single-format-standard';
|
$classes[] = 'single-format-standard';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is_attachment() ) {
|
if ( is_attachment() ) {
|
||||||
|
@ -455,23 +457,31 @@ function get_body_class( $class = '' ) {
|
||||||
} else if ( is_author() ) {
|
} else if ( is_author() ) {
|
||||||
$author = $wp_query->get_queried_object();
|
$author = $wp_query->get_queried_object();
|
||||||
$classes[] = 'author';
|
$classes[] = 'author';
|
||||||
$classes[] = 'author-' . sanitize_html_class( $author->user_nicename , $author->ID );
|
if ( isset( $author->user_nicename ) ) {
|
||||||
$classes[] = 'author-' . $author->ID;
|
$classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID );
|
||||||
|
$classes[] = 'author-' . $author->ID;
|
||||||
|
}
|
||||||
} elseif ( is_category() ) {
|
} elseif ( is_category() ) {
|
||||||
$cat = $wp_query->get_queried_object();
|
$cat = $wp_query->get_queried_object();
|
||||||
$classes[] = 'category';
|
$classes[] = 'category';
|
||||||
$classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id );
|
if ( isset( $cat->term_id ) ) {
|
||||||
$classes[] = 'category-' . $cat->term_id;
|
$classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id );
|
||||||
|
$classes[] = 'category-' . $cat->term_id;
|
||||||
|
}
|
||||||
} elseif ( is_tag() ) {
|
} elseif ( is_tag() ) {
|
||||||
$tags = $wp_query->get_queried_object();
|
$tags = $wp_query->get_queried_object();
|
||||||
$classes[] = 'tag';
|
$classes[] = 'tag';
|
||||||
$classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id );
|
if ( isset( $tags->term_id ) ) {
|
||||||
$classes[] = 'tag-' . $tags->term_id;
|
$classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id );
|
||||||
|
$classes[] = 'tag-' . $tags->term_id;
|
||||||
|
}
|
||||||
} elseif ( is_tax() ) {
|
} elseif ( is_tax() ) {
|
||||||
$term = $wp_query->get_queried_object();
|
$term = $wp_query->get_queried_object();
|
||||||
$classes[] = 'tax-' . sanitize_html_class( $term->taxonomy );
|
if ( isset( $term->term_id ) ) {
|
||||||
$classes[] = 'term-' . sanitize_html_class( $term->slug, $term->term_id );
|
$classes[] = 'tax-' . sanitize_html_class( $term->taxonomy );
|
||||||
$classes[] = 'term-' . $term->term_id;
|
$classes[] = 'term-' . sanitize_html_class( $term->slug, $term->term_id );
|
||||||
|
$classes[] = 'term-' . $term->term_id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} elseif ( is_page() ) {
|
} elseif ( is_page() ) {
|
||||||
$classes[] = 'page';
|
$classes[] = 'page';
|
||||||
|
|
Loading…
Reference in New Issue