mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Add some whitespace to get_body_class(). props coffee2code. Clarify fallback parameter in sanitize_html_class(). see #11331
git-svn-id: http://svn.automattic.com/wordpress/trunk@13468 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9ee57d58a4
commit
56c3658154
@ -842,20 +842,21 @@ function sanitize_sql_orderby( $orderby ){
|
||||
* @since 2.8.0
|
||||
*
|
||||
* @param string $class The classname to be sanitized
|
||||
* @param string $fallback The value to return if the sanitization end's up as an empty string.
|
||||
* @param string $fallback Optional. The value to return if the sanitization end's up as an empty string.
|
||||
* Defaults to an empty string.
|
||||
* @return string The sanitized value
|
||||
*/
|
||||
function sanitize_html_class($class, $fallback){
|
||||
function sanitize_html_class( $class, $fallback = '' ) {
|
||||
//Strip out any % encoded octets
|
||||
$sanitized = preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $class);
|
||||
|
||||
//Limit to A-Z,a-z,0-9,'-'
|
||||
$sanitized = preg_replace('/[^A-Za-z0-9-]/', '', $sanitized);
|
||||
|
||||
if ('' == $sanitized)
|
||||
if ( '' == $sanitized )
|
||||
$sanitized = $fallback;
|
||||
|
||||
return apply_filters('sanitize_html_class',$sanitized, $class, $fallback);
|
||||
return apply_filters( 'sanitize_html_class', $sanitized, $class, $fallback );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -372,7 +372,7 @@ function get_body_class( $class = '' ) {
|
||||
|
||||
$classes = array();
|
||||
|
||||
if ( 'rtl' == get_bloginfo('text_direction') )
|
||||
if ( 'rtl' == get_bloginfo( 'text_direction' ) )
|
||||
$classes[] = 'rtl';
|
||||
|
||||
if ( is_front_page() )
|
||||
@ -404,21 +404,21 @@ function get_body_class( $class = '' ) {
|
||||
$mime_type = get_post_mime_type($post_id);
|
||||
$mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
|
||||
$classes[] = 'attachmentid-' . $post_id;
|
||||
$classes[] = 'attachment-' . str_replace($mime_prefix, '', $mime_type);
|
||||
$classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );
|
||||
}
|
||||
} elseif ( is_archive() ) {
|
||||
if ( is_author() ) {
|
||||
$author = $wp_query->get_queried_object();
|
||||
$classes[] = 'author';
|
||||
$classes[] = 'author-' . sanitize_html_class($author->user_nicename , $author->ID);
|
||||
$classes[] = 'author-' . sanitize_html_class( $author->user_nicename , $author->ID );
|
||||
} elseif ( is_category() ) {
|
||||
$cat = $wp_query->get_queried_object();
|
||||
$classes[] = 'category';
|
||||
$classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->cat_ID);
|
||||
$classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->cat_ID );
|
||||
} elseif ( is_tag() ) {
|
||||
$tags = $wp_query->get_queried_object();
|
||||
$classes[] = 'tag';
|
||||
$classes[] = 'tag-' . sanitize_html_class($tags->slug, $tags->term_id);
|
||||
$classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id );
|
||||
}
|
||||
} elseif ( is_page() ) {
|
||||
$classes[] = 'page';
|
||||
@ -441,7 +441,7 @@ function get_body_class( $class = '' ) {
|
||||
$classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_post_meta( $page_id, '_wp_page_template', true ) ), '' );
|
||||
}
|
||||
} elseif ( is_search() ) {
|
||||
if ( !empty($wp_query->posts) )
|
||||
if ( !empty( $wp_query->posts ) )
|
||||
$classes[] = 'search-results';
|
||||
else
|
||||
$classes[] = 'search-no-results';
|
||||
@ -450,10 +450,10 @@ function get_body_class( $class = '' ) {
|
||||
if ( is_user_logged_in() )
|
||||
$classes[] = 'logged-in';
|
||||
|
||||
$page = $wp_query->get('page');
|
||||
$page = $wp_query->get( 'page' );
|
||||
|
||||
if ( !$page || $page < 2)
|
||||
$page = $wp_query->get('paged');
|
||||
$page = $wp_query->get( 'paged' );
|
||||
|
||||
if ( $page && $page > 1 ) {
|
||||
$classes[] = 'paged-' . $page;
|
||||
@ -474,15 +474,15 @@ function get_body_class( $class = '' ) {
|
||||
$classes[] = 'search-paged-' . $page;
|
||||
}
|
||||
|
||||
if ( !empty($class) ) {
|
||||
if ( !empty( $class ) ) {
|
||||
if ( !is_array( $class ) )
|
||||
$class = preg_split('#\s+#', $class);
|
||||
$classes = array_merge($classes, $class);
|
||||
$class = preg_split( '#\s+#', $class );
|
||||
$classes = array_merge( $classes, $class );
|
||||
}
|
||||
|
||||
$classes = array_map('esc_attr', $classes);
|
||||
$classes = array_map( 'esc_attr', $classes );
|
||||
|
||||
return apply_filters('body_class', $classes, $class);
|
||||
return apply_filters( 'body_class', $classes, $class );
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user