Skip to content

Commit bbd9fc3

Browse files
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 WordPress#13304. Follow-up to r63378. Props Soean, mukesh27. See #65818. git-svn-id: https://develop.svn.wordpress.org/trunk@63411 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ea95d00 commit bbd9fc3

1 file changed

Lines changed: 4 additions & 20 deletions

File tree

‎src/wp-includes/class-wp-customize-manager.php‎

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3872,11 +3872,7 @@ public function add_dynamic_settings( $setting_ids ) {
38723872
* @return WP_Customize_Setting|null The setting, if set.
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

38823878
/**
@@ -3926,11 +3922,7 @@ public function add_panel( $id, $args = array() ) {
39263922
* @return WP_Customize_Panel|null Requested panel instance, if set.
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

39363928
/**
@@ -4024,11 +4016,7 @@ public function add_section( $id, $args = array() ) {
40244016
* @return WP_Customize_Section|null The section, if set.
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

40344022
/**
@@ -4105,11 +4093,7 @@ public function add_control( $id, $args = array() ) {
41054093
* @return WP_Customize_Control|null The control object, if set.
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

41154099
/**

0 commit comments

Comments
 (0)