Make WordPress Core


Ignore:
Timestamp:
05/22/2009 05:44:26 PM (15 years ago)
Author:
westi
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post-template.php

    r11398 r11433  
    325325    // Categories
    326326    foreach ( (array) get_the_category($post->ID) as $cat ) {
    327         if ( empty($cat->cat_ID ) )
     327        if ( empty($cat->slug ) )
    328328            continue;
    329         $classes[] = 'category-' . $cat->cat_ID;
     329        $classes[] = 'category-' . sanitise_css_classname($cat->slug, $cat->cat_ID);
    330330    }
    331331
    332332    // Tags
    333333    foreach ( (array) get_the_tags($post->ID) as $tag ) {
    334         if ( empty($tag->term_id ) )
     334        if ( empty($tag->slug ) )
    335335            continue;
    336         $classes[] = 'tag-' . $tag->term_id;
     336        $classes[] = 'tag-' . sanitise_css_classname($tag->slug, $tag->term_id);
    337337    }
    338338
     
    408408            $author = $wp_query->get_queried_object();
    409409            $classes[] = 'author';
    410             $classes[] = 'author-' . $author->user_id;
     410            $classes[] = 'author-' . sanitise_css_classname($author->user_nicename , $author->user_id);
    411411        } elseif ( is_category() ) {
    412412            $cat = $wp_query->get_queried_object();
    413413            $classes[] = 'category';
    414             $classes[] = 'category-' . $cat->cat_ID;
     414            $classes[] = 'category-' . sanitise_css_classname($cat->slug, $cat->cat_ID);
    415415        } elseif ( is_tag() ) {
    416416            $tags = $wp_query->get_queried_object();
    417417            $classes[] = 'tag';
    418             $classes[] = 'tag-' . $tags->term_id;
     418            $classes[] = 'tag-' . sanitise_css_classname($tags->slug, $tags->term_id);
    419419        }
    420420    } elseif ( is_page() ) {
Note: See TracChangeset for help on using the changeset viewer.