Make WordPress Core

Changeset 22451


Ignore:
Timestamp:
11/07/2012 10:12:44 PM (11 years ago)
Author:
nacin
Message:

Sanity checks in get_body_class() to ensure we are operating on the type of queried object that we expect. props wonderboymusic. fixes #17662.

File:
1 edited

Legend:

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

    r22118 r22451  
    430430
    431431        $classes[] = 'single';
    432         $classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id);
    433         $classes[] = 'postid-' . $post_id;
    434 
    435         // Post Format
    436         if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
    437             $post_format = get_post_format( $post->ID );
    438 
    439             if ( $post_format && !is_wp_error($post_format) )
    440                 $classes[] = 'single-format-' . sanitize_html_class( $post_format );
    441             else
    442                 $classes[] = 'single-format-standard';
     432        if ( isset( $post->post_type ) ) {
     433            $classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id);
     434            $classes[] = 'postid-' . $post_id;
     435
     436            // Post Format
     437            if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
     438                $post_format = get_post_format( $post->ID );
     439
     440                if ( $post_format && !is_wp_error($post_format) )
     441                    $classes[] = 'single-format-' . sanitize_html_class( $post_format );
     442                else
     443                    $classes[] = 'single-format-standard';
     444            }           
    443445        }
    444446
     
    456458            $author = $wp_query->get_queried_object();
    457459            $classes[] = 'author';
    458             $classes[] = 'author-' . sanitize_html_class( $author->user_nicename , $author->ID );
    459             $classes[] = 'author-' . $author->ID;
     460            if ( isset( $author->user_nicename ) ) {
     461                $classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID );
     462                $classes[] = 'author-' . $author->ID;               
     463            }
    460464        } elseif ( is_category() ) {
    461465            $cat = $wp_query->get_queried_object();
    462466            $classes[] = 'category';
    463             $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id );
    464             $classes[] = 'category-' . $cat->term_id;
     467            if ( isset( $cat->term_id ) ) {
     468                $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id );
     469                $classes[] = 'category-' . $cat->term_id;               
     470            }
    465471        } elseif ( is_tag() ) {
    466472            $tags = $wp_query->get_queried_object();
    467473            $classes[] = 'tag';
    468             $classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id );
    469             $classes[] = 'tag-' . $tags->term_id;
     474            if ( isset( $tags->term_id ) ) {
     475                $classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id );
     476                $classes[] = 'tag-' . $tags->term_id;               
     477            }
    470478        } elseif ( is_tax() ) {
    471479            $term = $wp_query->get_queried_object();
    472             $classes[] = 'tax-' . sanitize_html_class( $term->taxonomy );
    473             $classes[] = 'term-' . sanitize_html_class( $term->slug, $term->term_id );
    474             $classes[] = 'term-' . $term->term_id;
     480            if ( isset( $term->term_id ) ) {
     481                $classes[] = 'tax-' . sanitize_html_class( $term->taxonomy );
     482                $classes[] = 'term-' . sanitize_html_class( $term->slug, $term->term_id );
     483                $classes[] = 'term-' . $term->term_id;
     484            }
    475485        }
    476486    } elseif ( is_page() ) {
Note: See TracChangeset for help on using the changeset viewer.