Ticket #17662: validate-body-class-vars.diff

File validate-body-class-vars.diff, 3.0 KB (added by wonderboymusic, 8 months ago)
Line 
1Index: wp-includes/post-template.php
2===================================================================
3--- wp-includes/post-template.php       (revision 21827)
4+++ wp-includes/post-template.php       (working copy)
5@@ -428,17 +428,19 @@
6                $post = $wp_query->get_queried_object();
7 
8                $classes[] = 'single';
9-               $classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id);
10-               $classes[] = 'postid-' . $post_id;
11+               if ( isset( $post->post_type ) ) {
12+                       $classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id);
13+                       $classes[] = 'postid-' . $post_id;
14 
15-               // Post Format
16-               if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
17-                       $post_format = get_post_format( $post->ID );
18+                       // Post Format
19+                       if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
20+                               $post_format = get_post_format( $post->ID );
21 
22-                       if ( $post_format && !is_wp_error($post_format) )
23-                               $classes[] = 'single-format-' . sanitize_html_class( $post_format );
24-                       else
25-                               $classes[] = 'single-format-standard';
26+                               if ( $post_format && !is_wp_error($post_format) )
27+                                       $classes[] = 'single-format-' . sanitize_html_class( $post_format );
28+                               else
29+                                       $classes[] = 'single-format-standard';
30+                       }                       
31                }
32 
33                if ( is_attachment() ) {
34@@ -454,23 +456,31 @@
35                } else if ( is_author() ) {
36                        $author = $wp_query->get_queried_object();
37                        $classes[] = 'author';
38-                       $classes[] = 'author-' . sanitize_html_class( $author->user_nicename , $author->ID );
39-                       $classes[] = 'author-' . $author->ID;
40+                       if ( isset( $author->user_nicename ) ) {
41+                               $classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID );
42+                               $classes[] = 'author-' . $author->ID;                           
43+                       }
44                } elseif ( is_category() ) {
45                        $cat = $wp_query->get_queried_object();
46                        $classes[] = 'category';
47-                       $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id );
48-                       $classes[] = 'category-' . $cat->term_id;
49+                       if ( isset( $cat->term_id ) ) {
50+                               $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id );
51+                               $classes[] = 'category-' . $cat->term_id;                               
52+                       }
53                } elseif ( is_tag() ) {
54                        $tags = $wp_query->get_queried_object();
55                        $classes[] = 'tag';
56-                       $classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id );
57-                       $classes[] = 'tag-' . $tags->term_id;
58+                       if ( isset( $tags->term_id ) ) {
59+                               $classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id );
60+                               $classes[] = 'tag-' . $tags->term_id;                           
61+                       }
62                } elseif ( is_tax() ) {
63                        $term = $wp_query->get_queried_object();
64-                       $classes[] = 'tax-' . sanitize_html_class( $term->taxonomy );
65-                       $classes[] = 'term-' . sanitize_html_class( $term->slug, $term->term_id );
66-                       $classes[] = 'term-' . $term->term_id;
67+                       if ( isset( $term->term_id ) ) {
68+                               $classes[] = 'tax-' . sanitize_html_class( $term->taxonomy );
69+                               $classes[] = 'term-' . sanitize_html_class( $term->slug, $term->term_id );
70+                               $classes[] = 'term-' . $term->term_id;
71+                       }
72                }
73        } elseif ( is_page() ) {
74                $classes[] = 'page';