Make WordPress Core

Ticket #35913: 35913-is-conditional-shared-logic.diff

File 35913-is-conditional-shared-logic.diff, 1.2 KB (added by sachinrajcp123, 14 months ago)
  • wp-includes/query.php

    diff --git a/wp-includes/query.php b/wp-includes/query.php
    index abc1111..def2222 100644
    a b  
    123123 */
    124124class WP_Query {
    125125
     126    /**
     127     * Helper to check current query type against provided condition.
     128     *
     129     * @since 6.9.0
     130     *
     131     * @param string $type Conditional type (e.g., 'home', 'single', 'page').
     132     * @return bool True if current query matches type.
     133     */
     134    private function is_query_type( $type ) {
     135        return ( ! empty( $this->$type ) && true === $this->$type );
     136    }
     137
     138
     139
    126140    /**
    127141     * Is the query for the blog homepage?
    128142     *
    … … class WP_Query {  
    130144     * @return bool
    131145     */
    132146    public function is_home() {
    133         return (bool) $this->is_home;
     147        return $this->is_query_type( 'is_home' );
    134148    }
    135149
    136150    /**
    … … class WP_Query {  
    139153     * @return bool
    140154     */
    141155    public function is_single() {
    142         return (bool) $this->is_single;
     156        return $this->is_query_type( 'is_single' );
    143157    }
    144158
    145159    /**
    … … class WP_Query {  
    148162     * @return bool
    149163     */
    150164    public function is_page() {
    151         return (bool) $this->is_page;
     165        return $this->is_query_type( 'is_page' );
    152166    }