Skip to content

Commit 50cb336

Browse files
committed
Code Modernization: Use null coalescing operator instead of ternaries where possible.
Developed in #10911 Follow-up to [61621], [61464]. Props soean, westonruter. See #63430. git-svn-id: https://develop.svn.wordpress.org/trunk@61637 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ed2c275 commit 50cb336

12 files changed

Lines changed: 26 additions & 26 deletions

src/wp-admin/edit-comments.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,13 @@
319319
|| isset( $_REQUEST['unspammed'] )
320320
|| isset( $_REQUEST['same'] )
321321
) {
322-
$approved = isset( $_REQUEST['approved'] ) ? (int) $_REQUEST['approved'] : 0;
323-
$deleted = isset( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0;
324-
$trashed = isset( $_REQUEST['trashed'] ) ? (int) $_REQUEST['trashed'] : 0;
325-
$untrashed = isset( $_REQUEST['untrashed'] ) ? (int) $_REQUEST['untrashed'] : 0;
326-
$spammed = isset( $_REQUEST['spammed'] ) ? (int) $_REQUEST['spammed'] : 0;
327-
$unspammed = isset( $_REQUEST['unspammed'] ) ? (int) $_REQUEST['unspammed'] : 0;
328-
$same = isset( $_REQUEST['same'] ) ? (int) $_REQUEST['same'] : 0;
322+
$approved = (int) ( $_REQUEST['approved'] ?? 0 );
323+
$deleted = (int) ( $_REQUEST['deleted'] ?? 0 );
324+
$trashed = (int) ( $_REQUEST['trashed'] ?? 0 );
325+
$untrashed = (int) ( $_REQUEST['untrashed'] ?? 0 );
326+
$spammed = (int) ( $_REQUEST['spammed'] ?? 0 );
327+
$unspammed = (int) ( $_REQUEST['unspammed'] ?? 0 );
328+
$same = (int) ( $_REQUEST['same'] ?? 0 );
329329

330330
if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 || $same > 0 ) {
331331
if ( $approved > 0 ) {

src/wp-includes/class-wp-block-parser-frame.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __construct( $block, $token_start, $token_length, $prev_offset =
7373
$this->block = $block;
7474
$this->token_start = $token_start;
7575
$this->token_length = $token_length;
76-
$this->prev_offset = isset( $prev_offset ) ? $prev_offset : $token_start + $token_length;
76+
$this->prev_offset = $prev_offset ?? $token_start + $token_length;
7777
$this->leading_html_start = $leading_html_start;
7878
}
7979
}

src/wp-includes/class-wp-locale.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ public function get_word_count_type() {
450450
* enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
451451
* Do not translate into your own language.
452452
*/
453-
$word_count_type = is_null( $this->word_count_type ) ? _x( 'words', 'Word count type. Do not translate!' ) : $this->word_count_type;
453+
$word_count_type = $this->word_count_type ?? _x( 'words', 'Word count type. Do not translate!' );
454454

455455
// Check for valid types.
456456
if ( 'characters_excluding_spaces' !== $word_count_type && 'characters_including_spaces' !== $word_count_type ) {

src/wp-includes/class-wp-theme-json-resolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public static function get_fields_to_translate() {
144144
protected static function translate( $theme_json, $domain = 'default' ) {
145145
if ( null === static::$i18n_schema ) {
146146
$i18n_schema = wp_json_file_decode( __DIR__ . '/theme-i18n.json' );
147-
static::$i18n_schema = null === $i18n_schema ? array() : $i18n_schema;
147+
static::$i18n_schema = $i18n_schema ?? array();
148148
}
149149

150150
return translate_settings_using_i18n_schema( static::$i18n_schema, $theme_json, $domain );

src/wp-includes/customize/class-wp-customize-partial.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ final public function render( $container_context = array() ) {
230230
* Note that the string return takes precedence because the $ob_render may just\
231231
* include PHP warnings or notices.
232232
*/
233-
$rendered = null !== $return_render ? $return_render : $ob_render;
233+
$rendered = $return_render ?? $ob_render;
234234
}
235235

236236
/**

src/wp-includes/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ function do_enclose( $content, $post ) {
951951

952952
$headers = wp_get_http_headers( $url );
953953
if ( $headers ) {
954-
$len = isset( $headers['Content-Length'] ) ? (int) $headers['Content-Length'] : 0;
954+
$len = (int) ( $headers['Content-Length'] ?? 0 );
955955
$type = $headers['Content-Type'] ?? '';
956956
$allowed_types = array( 'video', 'audio' );
957957

src/wp-includes/interactivity-api/class-wp-interactivity-api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ public function process_directives( string $html ): string {
453453
$this->namespace_stack = null;
454454
$this->context_stack = null;
455455

456-
return null === $result ? $html : $result;
456+
return $result ?? $html;
457457
}
458458

459459
/**

src/wp-includes/l10n.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,7 @@ function get_available_languages( $dir = null ) {
14901490

14911491
$languages = array();
14921492

1493-
$path = is_null( $dir ) ? WP_LANG_DIR : $dir;
1493+
$path = $dir ?? WP_LANG_DIR;
14941494
$lang_files = $wp_textdomain_registry->get_language_files_from_path( $path );
14951495

14961496
if ( $lang_files ) {

src/wp-includes/link-template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function wp_force_plain_post_permalink( $post = null, $sample = null ) {
110110
$sample = true;
111111
} else {
112112
$post = get_post( $post );
113-
$sample = null !== $sample ? $sample : false;
113+
$sample = $sample ?? false;
114114
}
115115

116116
if ( ! $post ) {

src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ static function ( $format ) {
483483
remove_filter( 'post_password_required', array( $this, 'check_password_required' ) );
484484
}
485485

486-
$page = isset( $query_args['paged'] ) ? (int) $query_args['paged'] : 0;
486+
$page = (int) ( $query_args['paged'] ?? 0 );
487487
$total_posts = $posts_query->found_posts;
488488

489489
if ( $total_posts < 1 && $page > 1 ) {

0 commit comments

Comments
 (0)