mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Introduce sanitise_css_classname() and use it to give categories, tags, users etc meaningful classnames where possible. Falls back to the id if not. Fixes #8446.
git-svn-id: https://develop.svn.wordpress.org/trunk@11433 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -324,16 +324,16 @@ function get_post_class( $class = '', $post_id = null ) {
|
||||
|
||||
// Categories
|
||||
foreach ( (array) get_the_category($post->ID) as $cat ) {
|
||||
if ( empty($cat->cat_ID ) )
|
||||
if ( empty($cat->slug ) )
|
||||
continue;
|
||||
$classes[] = 'category-' . $cat->cat_ID;
|
||||
$classes[] = 'category-' . sanitise_css_classname($cat->slug, $cat->cat_ID);
|
||||
}
|
||||
|
||||
// Tags
|
||||
foreach ( (array) get_the_tags($post->ID) as $tag ) {
|
||||
if ( empty($tag->term_id ) )
|
||||
if ( empty($tag->slug ) )
|
||||
continue;
|
||||
$classes[] = 'tag-' . $tag->term_id;
|
||||
$classes[] = 'tag-' . sanitise_css_classname($tag->slug, $tag->term_id);
|
||||
}
|
||||
|
||||
if ( !empty($class) ) {
|
||||
@@ -407,15 +407,15 @@ function get_body_class( $class = '' ) {
|
||||
if ( is_author() ) {
|
||||
$author = $wp_query->get_queried_object();
|
||||
$classes[] = 'author';
|
||||
$classes[] = 'author-' . $author->user_id;
|
||||
$classes[] = 'author-' . sanitise_css_classname($author->user_nicename , $author->user_id);
|
||||
} elseif ( is_category() ) {
|
||||
$cat = $wp_query->get_queried_object();
|
||||
$classes[] = 'category';
|
||||
$classes[] = 'category-' . $cat->cat_ID;
|
||||
$classes[] = 'category-' . sanitise_css_classname($cat->slug, $cat->cat_ID);
|
||||
} elseif ( is_tag() ) {
|
||||
$tags = $wp_query->get_queried_object();
|
||||
$classes[] = 'tag';
|
||||
$classes[] = 'tag-' . $tags->term_id;
|
||||
$classes[] = 'tag-' . sanitise_css_classname($tags->slug, $tags->term_id);
|
||||
}
|
||||
} elseif ( is_page() ) {
|
||||
$classes[] = 'page';
|
||||
|
||||
Reference in New Issue
Block a user