Skip to content

Commit 825ec4b

Browse files
SoeanSoeanMamaduka
authored
Refactor: Use null coalescing operator for improved readability (WordPress#76777)
Co-authored-by: Soean <soean@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
1 parent 818a44d commit 825ec4b

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

lib/experimental/content-guidelines/class-gutenberg-content-guidelines-post-type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public static function get_guideline_categories_from_meta( $post_id ) {
241241
foreach ( $all_meta as $meta_key => $meta_values ) {
242242
if ( self::is_block_meta_key( $meta_key ) ) {
243243
$block_name = self::meta_key_to_block_name( $meta_key );
244-
$value = isset( $meta_values[0] ) ? $meta_values[0] : '';
244+
$value = $meta_values[0] ?? '';
245245

246246
if ( ! empty( $value ) ) {
247247
$blocks[ $block_name ] = array(

lib/experimental/content-guidelines/class-gutenberg-content-guidelines-rest-controller.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,7 @@ protected function save_guideline_categories_to_meta( $post_id, $categories ) {
391391
foreach ( Gutenberg_Content_Guidelines_Post_Type::CATEGORY_META_KEYS as $category ) {
392392
if ( isset( $categories[ $category ] ) ) {
393393
$meta_key = '_content_guideline_' . $category;
394-
$value = isset( $categories[ $category ]['guidelines'] )
395-
? $categories[ $category ]['guidelines']
396-
: '';
394+
$value = $categories[ $category ]['guidelines'] ?? '';
397395
update_post_meta( $post_id, $meta_key, $value );
398396
}
399397
}
@@ -402,7 +400,7 @@ protected function save_guideline_categories_to_meta( $post_id, $categories ) {
402400
if ( isset( $categories['blocks'] ) && is_array( $categories['blocks'] ) ) {
403401
foreach ( $categories['blocks'] as $block_name => $block_data ) {
404402
$meta_key = Gutenberg_Content_Guidelines_Post_Type::block_name_to_meta_key( $block_name );
405-
$value = isset( $block_data['guidelines'] ) ? $block_data['guidelines'] : '';
403+
$value = $block_data['guidelines'] ?? '';
406404

407405
if ( ! empty( $value ) ) {
408406
update_post_meta( $post_id, $meta_key, $value );

0 commit comments

Comments
 (0)