WordPress.org

Make WordPress Core

Changeset 13468


Ignore:
Timestamp:
02/27/10 20:06:35 (4 years ago)
Author:
nacin
Message:

Add some whitespace to get_body_class(). props coffee2code. Clarify fallback parameter in sanitize_html_class(). see #11331

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/formatting.php

    r13382 r13468  
    843843 * 
    844844 * @param string $class The classname to be sanitized 
    845  * @param string $fallback The value to return if the sanitization end's up as an empty string. 
     845 * @param string $fallback Optional. The value to return if the sanitization end's up as an empty string. 
     846 *  Defaults to an empty string. 
    846847 * @return string The sanitized value 
    847848 */ 
    848 function sanitize_html_class($class, $fallback){ 
     849function sanitize_html_class( $class, $fallback = '' ) { 
    849850    //Strip out any % encoded octets 
    850851    $sanitized = preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $class); 
     
    853854    $sanitized = preg_replace('/[^A-Za-z0-9-]/', '', $sanitized); 
    854855 
    855     if ('' == $sanitized) 
     856    if ( '' == $sanitized ) 
    856857        $sanitized = $fallback; 
    857858 
    858     return apply_filters('sanitize_html_class',$sanitized, $class, $fallback); 
     859    return apply_filters( 'sanitize_html_class', $sanitized, $class, $fallback ); 
    859860} 
    860861 
  • trunk/wp-includes/post-template.php

    r13462 r13468  
    373373    $classes = array(); 
    374374 
    375     if ( 'rtl' == get_bloginfo('text_direction') ) 
     375    if ( 'rtl' == get_bloginfo( 'text_direction' ) ) 
    376376        $classes[] = 'rtl'; 
    377377 
     
    405405            $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' ); 
    406406            $classes[] = 'attachmentid-' . $post_id; 
    407             $classes[] = 'attachment-' . str_replace($mime_prefix, '', $mime_type); 
     407            $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type ); 
    408408        } 
    409409    } elseif ( is_archive() ) { 
     
    411411            $author = $wp_query->get_queried_object(); 
    412412            $classes[] = 'author'; 
    413             $classes[] = 'author-' . sanitize_html_class($author->user_nicename , $author->ID); 
     413            $classes[] = 'author-' . sanitize_html_class( $author->user_nicename , $author->ID ); 
    414414        } elseif ( is_category() ) { 
    415415            $cat = $wp_query->get_queried_object(); 
    416416            $classes[] = 'category'; 
    417             $classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->cat_ID); 
     417            $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->cat_ID ); 
    418418        } elseif ( is_tag() ) { 
    419419            $tags = $wp_query->get_queried_object(); 
    420420            $classes[] = 'tag'; 
    421             $classes[] = 'tag-' . sanitize_html_class($tags->slug, $tags->term_id); 
     421            $classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id ); 
    422422        } 
    423423    } elseif ( is_page() ) { 
     
    442442        } 
    443443    } elseif ( is_search() ) { 
    444         if ( !empty($wp_query->posts) ) 
     444        if ( !empty( $wp_query->posts ) ) 
    445445            $classes[] = 'search-results'; 
    446446        else 
     
    451451        $classes[] = 'logged-in'; 
    452452 
    453     $page = $wp_query->get('page'); 
     453    $page = $wp_query->get( 'page' ); 
    454454 
    455455    if ( !$page || $page < 2) 
    456         $page = $wp_query->get('paged'); 
     456        $page = $wp_query->get( 'paged' ); 
    457457 
    458458    if ( $page && $page > 1 ) { 
     
    475475    } 
    476476 
    477     if ( !empty($class) ) { 
     477    if ( !empty( $class ) ) { 
    478478        if ( !is_array( $class ) ) 
    479             $class = preg_split('#\s+#', $class); 
    480         $classes = array_merge($classes, $class); 
    481     } 
    482  
    483     $classes = array_map('esc_attr', $classes); 
    484  
    485     return apply_filters('body_class', $classes, $class); 
     479            $class = preg_split( '#\s+#', $class ); 
     480        $classes = array_merge( $classes, $class ); 
     481    } 
     482 
     483    $classes = array_map( 'esc_attr', $classes ); 
     484 
     485    return apply_filters( 'body_class', $classes, $class ); 
    486486} 
    487487 
Note: See TracChangeset for help on using the changeset viewer.