Make WordPress Core

Changeset 56424


Ignore:
Timestamp:
08/22/2023 12:28:52 PM (10 months ago)
Author:
SergeyBiryukov
Message:

Posts, Post Types: Remove redundant function calls in get_body_class().

As part of a previous change to add support for post type templates, the $wp_query->get_queried_object_id() method ended up being called twice, in both the is_singular() and is_page() conditional branches.

The get_post() function call was also unnecessary, as $wp_query->get_queried_object() is already called in the is_singular() branch above, which includes the is_page() branch too.

This commit removes the redundant calls. The first $wp_query->get_queried_object_id() call is removed as well, since the post ID is already available via $wp_query->get_queried_object().

Follow-up to [10485], [10877], [12877], [13032], [21597], [38951].

Props mattkeys, spacedmonkey, oglekler.
Fixes #43661.

File:
1 edited

Legend:

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

    r56192 r56424  
    671671
    672672    if ( is_singular() ) {
    673         $post_id   = $wp_query->get_queried_object_id();
    674673        $post      = $wp_query->get_queried_object();
     674        $post_id   = $post->ID;
    675675        $post_type = $post->post_type;
    676676
     
    715715        } elseif ( is_page() ) {
    716716            $classes[] = 'page';
    717 
    718             $page_id = $wp_query->get_queried_object_id();
    719 
    720             $post = get_post( $page_id );
    721 
    722             $classes[] = 'page-id-' . $page_id;
     717            $classes[] = 'page-id-' . $post_id;
    723718
    724719            if ( get_pages(
    725720                array(
    726                     'parent' => $page_id,
     721                    'parent' => $post_id,
    727722                    'number' => 1,
    728723                )
Note: See TracChangeset for help on using the changeset viewer.