Ticket #8446: 8446-valid-classnames-for-post-categories-and-tags.patch
File 8446-valid-classnames-for-post-categories-and-tags.patch, 2.2 KB (added by , 16 years ago) |
---|
-
wp-includes/formatting.php
76 76 } 77 77 78 78 /** 79 * clean invalid chars from css class names 80 * 81 * invalid chars will be replaced with '_', if the class 82 * should not be treated as a suffix for an existing class, 83 * then invalid classes will be prefixed with 'a_' to 84 * become valid again. 85 * 86 * @since 2.7.2 87 * 88 * @param array|string $class array or string with class(es) 89 * @param bool $suffix optional wether or not class(es) 90 * are treated as being a suffix 91 * (defaults to true) 92 * @return string classname(es) cleaned 93 */ 94 function clean_css_classnames($class, $suffix = true) 95 { 96 if (is_array($class)) { 97 $return = array(); 98 foreach($class as $single) 99 $return[] = clean_css_classnames($single, $suffix); 100 return $return; 101 } 102 103 $class = preg_replace('|[^_a-z0-9-]|i', '_', $class); 104 105 if (false == $suffix && 0 == preg_match('|^-?[_a-z]+[_a-z0-9-]*$|i', $class)) 106 $class = 'a_' . $class; 107 108 return $class; 109 } 110 111 /** 79 112 * Accepts matches array from preg_replace_callback in wpautop() or a string. 80 113 * 81 114 * Ensures that the contents of a <<pre>>...<</pre>> HTML block are not -
wp-includes/post-template.php
320 320 if ( empty($cat->slug ) ) 321 321 continue; 322 322 $classes[] = 'category-' . $cat->slug; 323 $classes[] = 'categoryid-' . $cat->term_id; 323 324 } 324 325 325 326 // Tags 326 327 foreach ( (array) get_the_tags($post->ID) as $tag ) { 327 328 if ( empty($tag->slug ) ) 328 329 continue; 329 $classes[] = 'tag-' . $tag->slug; 330 $classes[] = 'tag-' . $tag->slug; 331 $classes[] = 'tagid-' . $tag->term_id; 330 332 } 331 333 332 334 if ( !empty($class) ) { … … 334 336 $class = preg_split('#\s+#', $class); 335 337 $classes = array_merge($classes, $class); 336 338 } 339 340 $classes = clean_css_classnames($classes, false); 337 341 338 342 return apply_filters('post_class', $classes, $class, $post_id); 339 343 }