WordPress.org

Make WordPress Core

Ticket #11439: 11439.diff

File 11439.diff, 2.5 KB (added by Denis-de-Bernardy, 6 years ago)
  • wp-includes/post-template.php

     
    392392                $classes[] = 'error404'; 
    393393 
    394394        if ( is_single() ) { 
    395                 $wp_query->post = $wp_query->posts[0]; 
    396                 setup_postdata($wp_query->post); 
    397  
    398                 $postID = $wp_query->post->ID; 
     395                $postID = $wp_query->get_queried_object_id(); 
     396                 
    399397                $classes[] = 'single postid-' . $postID; 
    400398 
    401399                if ( is_attachment() ) { 
    402                         $mime_type = get_post_mime_type(); 
     400                        $mime_type = get_post_mime_type($postID); 
    403401                        $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' ); 
    404402                        $classes[] = 'attachmentid-' . $postID; 
    405403                        $classes[] = 'attachment-' . str_replace($mime_prefix, '', $mime_type); 
     
    421419        } elseif ( is_page() ) { 
    422420                $classes[] = 'page'; 
    423421 
    424                 $wp_query->post = $wp_query->posts[0]; 
    425                 setup_postdata($wp_query->post); 
     422                $pageID = $wp_query->get_queried_object_id(); 
    426423 
    427                 $pageID = $wp_query->post->ID; 
     424                $post = get_page($pageID); 
    428425 
    429426                $classes[] = 'page-id-' . $pageID; 
    430427 
    431                 if ( $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' LIMIT 1", $pageID) ) ) 
     428                if ( $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status == 'publish' LIMIT 1", $pageID) ) ) 
    432429                        $classes[] = 'page-parent'; 
    433430 
    434                 if ( $wp_query->post->post_parent ) { 
     431                if ( $post->post_parent ) { 
    435432                        $classes[] = 'page-child'; 
    436                         $classes[] = 'parent-pageid-' . $wp_query->post->post_parent; 
     433                        $classes[] = 'parent-pageid-' . $post->post_parent; 
    437434                } 
    438435                if ( is_page_template() ) { 
    439436                        $classes[] = 'page-template'; 
     
    479476                $classes = array_merge($classes, $class); 
    480477        } 
    481478 
    482         $classes = array_map('esc_attr', $classes); 
     479        $classes = array_map('sanitize_html_class', $classes); 
    483480 
    484481        return apply_filters('body_class', $classes, $class); 
    485482} 
  • wp-includes/formatting.php

     
    839839 * @param string $fallback The value to return if the sanitization end's up as an empty string. 
    840840 * @return string The sanitized value 
    841841 */ 
    842 function sanitize_html_class($class, $fallback){ 
     842function sanitize_html_class($class, $fallback = ''){ 
    843843        //Strip out any % encoded octets 
    844844        $sanitized = preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $class); 
    845845