Make WordPress Core

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

File 35913-is-conditional-shared-logic.2.diff, 1.3 KB (added by sachinrajcp123, 8 months ago)
  • src/wp-includes/class-wp-query.php

    diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php
    index 7c3f8e1a12..b91d9d9e45 100644
    a b class WP_Query {  
    394394        }
    395395
    396396        /**
     397         * Helper to check current query type against provided condition.
     398         *
     399         * Centralizes logic shared by is_*() conditional methods to reduce
     400         * duplication and ease maintenance.
     401         *
     402         * @since 7.0.0
     403         *
     404         * @param string $type Conditional type (e.g., 'is_home', 'is_single').
     405         * @return bool True if current query matches the given type.
     406         */
     407        protected function is_query_type( $type ) {
     408                return ! empty( $this->$type ) && true === $this->$type;
     409        }
     410
     411        /**
    397412         * Is the query for the blog homepage?
    398413         *
    399414         * @since 1.5.0
    … … class WP_Query {  
    401415         * @return bool
    402416         */
    403417        public function is_home() {
    404                 return (bool) $this->is_home;
     418                return $this->is_query_type( 'is_home' );
    405419        }
    406420
    407421        /**
    … … class WP_Query {  
    409423         * @return bool
    410424         */
    411425        public function is_single() {
    412                 return (bool) $this->is_single;
     426                return $this->is_query_type( 'is_single' );
    413427        }
    414428
    415429        /**
    … … class WP_Query {  
    417431         * @return bool
    418432         */
    419433        public function is_page() {
    420                 return (bool) $this->is_page;
     434                return $this->is_query_type( 'is_page' );
    421435        }