Make WordPress Core

Changeset 63411


Ignore:
Timestamp:
08/31/2026 05:22:49 PM (2 weeks ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Use the null coalescing operator in WP_Customize_Manager.

The four object getters in WP_Customize_Manager: get_setting(), get_panel(), get_section(), and get_control(), each spell out an isset() guard followed by return null. The null coalescing operator says the same thing in one line.

?? applies the same isset() semantics as the guard it replaces, and since the fallback here is null itself, both forms return the identical value in every case. This covers the complete set of same-shaped getters in the class.

Developed in https://github.com/WordPress/wordpress-develop/pull/13304.

Follow-up to r63378.

Props Soean, mukesh27.
See #65818.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r63404 r63411  
    38733873         */
    38743874        public function get_setting( $id ) {
    3875                 if ( isset( $this->settings[ $id ] ) ) {
    3876                         return $this->settings[ $id ];
    3877                 }
    3878 
    3879                 return null;
     3875                return $this->settings[ $id ] ?? null;
    38803876        }
    38813877
     
    39273923         */
    39283924        public function get_panel( $id ) {
    3929                 if ( isset( $this->panels[ $id ] ) ) {
    3930                         return $this->panels[ $id ];
    3931                 }
    3932 
    3933                 return null;
     3925                return $this->panels[ $id ] ?? null;
    39343926        }
    39353927
     
    40254017         */
    40264018        public function get_section( $id ) {
    4027                 if ( isset( $this->sections[ $id ] ) ) {
    4028                         return $this->sections[ $id ];
    4029                 }
    4030 
    4031                 return null;
     4019                return $this->sections[ $id ] ?? null;
    40324020        }
    40334021
     
    41064094         */
    41074095        public function get_control( $id ) {
    4108                 if ( isset( $this->controls[ $id ] ) ) {
    4109                         return $this->controls[ $id ];
    4110                 }
    4111 
    4112                 return null;
     4096                return $this->controls[ $id ] ?? null;
    41134097        }
    41144098
Note: See TracChangeset for help on using the changeset viewer.