WordPress.org

Make WordPress Core

Ticket #11439: unnecessary_global_tampering.11439.diff

File unnecessary_global_tampering.11439.diff, 1.7 KB (added by filosofo, 4 years ago)

use Denis's approach to the private page issue

  • 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';