Code Modernization: Use the null coalescing operator for isset() return checks in WP_Customize_Manager - #13304
Conversation
Replaces the verbose `isset()` guard in `WP_Customize_Manager::get_setting()`, `::get_panel()`, `::get_section()`, and `::get_control()` with the null coalescing operator (`??`). Both forms are functionally identical: `??` uses the same `isset()` semantics and yields the fallback when the key is either missing or `null`. The remaining `return null` statements in the class are not this idiom — they guard on emptiness, on a `false` sentinel, or on a failed `get_userdata()` call — and are left untouched. Occurrences in `SimplePie` and `Requests` are excluded as bundled third-party code. Follow-up to [62870], [62895], [62949].
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
The four object getters on
WP_Customize_Manager:get_setting(),get_panel(),get_section()andget_control(), each spell out anisset()guard followed byreturn null. The null coalescing operator says the same thing in one line.??applies the sameisset()semantics as the guard it replaces, and since the fallback here isnullitself, both forms return the identical value in every case. This covers the complete set of same-shaped getters in the class.Follow-up to [63378]
Trac ticket: https://core.trac.wordpress.org/ticket/65818
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.