Skip to content

Commit e0147a2

Browse files
committed
Code Modernization: Media: Use null coalescing operator instead of isset() ternaries.
Developed as a subset of WordPress/wordpress-develop#10654 Initially developed in WordPress/wordpress-develop#4886 Follow-up to [61445], [61444], [61443], [61442], [61436], [61435], [61434], [61403], [61433], [61432], [61431], [61430], [61429], [61424], [61404], [61403]. Props costdev, westonruter. See #58874, #63430. Built from https://develop.svn.wordpress.org/trunk@61453 git-svn-id: https://core.svn.wordpress.org/trunk@60765 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent e502d54 commit e0147a2

File tree

10 files changed

+56
-56
lines changed

10 files changed

+56
-56
lines changed

wp-admin/includes/class-custom-image-header.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ final public function create_attachment_object( $cropped, $parent_attachment_id
13511351
* @return int Attachment ID.
13521352
*/
13531353
final public function insert_attachment( $attachment, $cropped ) {
1354-
$parent_id = isset( $attachment['post_parent'] ) ? $attachment['post_parent'] : null;
1354+
$parent_id = $attachment['post_parent'] ?? null;
13551355
unset( $attachment['post_parent'] );
13561356

13571357
$attachment_id = wp_insert_attachment( $attachment, $cropped );
@@ -1584,8 +1584,8 @@ public function get_uploaded_header_images() {
15841584

15851585
foreach ( $header_images as &$header_image ) {
15861586
$header_meta = get_post_meta( $header_image['attachment_id'] );
1587-
$header_image['timestamp'] = isset( $header_meta[ $timestamp_key ] ) ? $header_meta[ $timestamp_key ] : '';
1588-
$header_image['alt_text'] = isset( $header_meta[ $alt_text_key ] ) ? $header_meta[ $alt_text_key ] : '';
1587+
$header_image['timestamp'] = $header_meta[ $timestamp_key ] ?? '';
1588+
$header_image['alt_text'] = $header_meta[ $alt_text_key ] ?? '';
15891589
}
15901590

15911591
return $header_images;

wp-admin/includes/class-wp-media-list-table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct( $args = array() ) {
4747
parent::__construct(
4848
array(
4949
'plural' => 'media',
50-
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
50+
'screen' => $args['screen'] ?? null,
5151
)
5252
);
5353
}

wp-admin/includes/image-edit.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ function wp_image_editor( $post_id, $msg = false ) {
109109
<input type="hidden" id="imgedit-history-<?php echo $post_id; ?>" value="" />
110110
<input type="hidden" id="imgedit-undone-<?php echo $post_id; ?>" value="0" />
111111
<input type="hidden" id="imgedit-selection-<?php echo $post_id; ?>" value="" />
112-
<input type="hidden" id="imgedit-x-<?php echo $post_id; ?>" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />
113-
<input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
112+
<input type="hidden" id="imgedit-x-<?php echo $post_id; ?>" value="<?php echo $meta['width'] ?? 0; ?>" />
113+
<input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo $meta['height'] ?? 0; ?>" />
114114

115115
<div id="imgedit-crop-<?php echo $post_id; ?>" class="imgedit-crop-wrap">
116116
<div class="imgedit-crop-grid"></div>
@@ -154,10 +154,10 @@ function wp_image_editor( $post_id, $msg = false ) {
154154
_e( 'scale height' );
155155
?>
156156
</label>
157-
<input type="number" step="1" min="0" max="<?php echo isset( $meta['width'] ) ? $meta['width'] : ''; ?>" aria-describedby="imgedit-scale-warn-<?php echo $post_id; ?>" id="imgedit-scale-width-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1, this)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1, this)" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />
157+
<input type="number" step="1" min="0" max="<?php echo $meta['width'] ?? ''; ?>" aria-describedby="imgedit-scale-warn-<?php echo $post_id; ?>" id="imgedit-scale-width-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1, this)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1, this)" value="<?php echo $meta['width'] ?? 0; ?>" />
158158
<span class="imgedit-separator" aria-hidden="true">&times;</span>
159159
<label for="imgedit-scale-height-<?php echo $post_id; ?>" class="screen-reader-text"><?php _e( 'scale height' ); ?></label>
160-
<input type="number" step="1" min="0" max="<?php echo isset( $meta['height'] ) ? $meta['height'] : ''; ?>" aria-describedby="imgedit-scale-warn-<?php echo $post_id; ?>" id="imgedit-scale-height-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0, this)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0, this)" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
160+
<input type="number" step="1" min="0" max="<?php echo $meta['height'] ?? ''; ?>" aria-describedby="imgedit-scale-warn-<?php echo $post_id; ?>" id="imgedit-scale-height-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0, this)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0, this)" value="<?php echo $meta['height'] ?? 0; ?>" />
161161
<button id="imgedit-scale-button" type="button" onclick="imageEdit.action(<?php echo "$post_id, '$nonce'"; ?>, 'scale')" class="button button-primary"><?php esc_html_e( 'Scale' ); ?></button>
162162
</div>
163163
<span class="imgedit-scale-warn" id="imgedit-scale-warn-<?php echo $post_id; ?>"><span class="dashicons dashicons-warning" aria-hidden="true"></span><?php esc_html_e( 'Images cannot be scaled to a size larger than the original.' ); ?></span>
@@ -744,10 +744,10 @@ function image_edit_apply_changes( $image, $changes ) {
744744
$w = $size['width'];
745745
$h = $size['height'];
746746

747-
$scale = isset( $sel->r ) ? $sel->r : 1 / _image_get_preview_ratio( $w, $h ); // Discard preview scaling.
747+
$scale = $sel->r ?? 1 / _image_get_preview_ratio( $w, $h ); // Discard preview scaling.
748748
$image->crop( (int) ( $sel->x * $scale ), (int) ( $sel->y * $scale ), (int) ( $sel->w * $scale ), (int) ( $sel->h * $scale ) );
749749
} else {
750-
$scale = isset( $sel->r ) ? $sel->r : 1 / _image_get_preview_ratio( imagesx( $image ), imagesy( $image ) ); // Discard preview scaling.
750+
$scale = $sel->r ?? 1 / _image_get_preview_ratio( imagesx( $image ), imagesy( $image ) ); // Discard preview scaling.
751751
$image = _crop_image_resource( $image, $sel->x * $scale, $sel->y * $scale, $sel->w * $scale, $sel->h * $scale );
752752
}
753753
break;

wp-admin/includes/media.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ function media_upload_form_handler() {
832832

833833
if ( isset( $send_id ) ) {
834834
$attachment = wp_unslash( $_POST['attachments'][ $send_id ] );
835-
$html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
835+
$html = $attachment['post_title'] ?? '';
836836

837837
if ( ! empty( $attachment['url'] ) ) {
838838
$rel = '';
@@ -1558,7 +1558,7 @@ function get_media_items( $post_id, $errors ) {
15581558
continue;
15591559
}
15601560

1561-
$item = get_media_item( $id, array( 'errors' => isset( $errors[ $id ] ) ? $errors[ $id ] : null ) );
1561+
$item = get_media_item( $id, array( 'errors' => $errors[ $id ] ?? null ) );
15621562

15631563
if ( $item ) {
15641564
$output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div class='progress hidden'><div class='bar'></div></div><div id='media-upload-error-$id' class='hidden'></div><div class='filename hidden'></div>$item\n</div>";
@@ -2103,8 +2103,8 @@ function media_upload_form( $errors = null ) {
21032103

21042104
$upload_action_url = admin_url( 'async-upload.php' );
21052105
$post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
2106-
$_type = isset( $type ) ? $type : '';
2107-
$_tab = isset( $tab ) ? $tab : '';
2106+
$_type = $type ?? '';
2107+
$_tab = $tab ?? '';
21082108

21092109
$max_upload_size = wp_max_upload_size();
21102110
if ( ! $max_upload_size ) {
@@ -3656,7 +3656,7 @@ function wp_read_video_metadata( $file ) {
36563656

36573657
wp_add_id3_tag_data( $metadata, $data );
36583658

3659-
$file_format = isset( $metadata['fileformat'] ) ? $metadata['fileformat'] : null;
3659+
$file_format = $metadata['fileformat'] ?? null;
36603660

36613661
/**
36623662
* Filters the array of metadata retrieved from a video.
@@ -3739,7 +3739,7 @@ function wp_read_audio_metadata( $file ) {
37393739

37403740
wp_add_id3_tag_data( $metadata, $data );
37413741

3742-
$file_format = isset( $metadata['fileformat'] ) ? $metadata['fileformat'] : null;
3742+
$file_format = $metadata['fileformat'] ?? null;
37433743

37443744
/**
37453745
* Filters the array of metadata retrieved from an audio file.

wp-admin/upload.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787

8888
$message .= sprintf(
8989
' <a href="%1$s">%2$s</a>',
90-
esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( isset( $_GET['ids'] ) ? $_GET['ids'] : '' ), 'bulk-media' ) ),
90+
esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( $_GET['ids'] ?? '' ), 'bulk-media' ) ),
9191
__( 'Undo' )
9292
);
9393

@@ -117,7 +117,7 @@
117117
$messages[3] = __( 'Error saving media file.' );
118118
$messages[4] = __( 'Media file moved to the Trash.' ) . sprintf(
119119
' <a href="%1$s">%2$s</a>',
120-
esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( isset( $_GET['ids'] ) ? $_GET['ids'] : '' ), 'bulk-media' ) ),
120+
esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( $_GET['ids'] ?? '' ), 'bulk-media' ) ),
121121
__( 'Undo' )
122122
);
123123
$messages[5] = __( 'Media file restored from the Trash.' );

wp-includes/css/dist/index.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
*/
88

99
return array(
10+
array(
11+
'handle' => 'wp-preferences',
12+
'path' => 'preferences/style',
13+
'dependencies' => array('wp-components'),
14+
),
1015
array(
1116
'handle' => 'wp-list-reusable-blocks',
1217
'path' => 'list-reusable-blocks/style',
@@ -17,11 +22,6 @@
1722
'path' => 'nux/style',
1823
'dependencies' => array('wp-components'),
1924
),
20-
array(
21-
'handle' => 'wp-preferences',
22-
'path' => 'preferences/style',
23-
'dependencies' => array('wp-components'),
24-
),
2525
array(
2626
'handle' => 'wp-commands',
2727
'path' => 'commands/style',
@@ -32,11 +32,6 @@
3232
'path' => 'reusable-blocks/style',
3333
'dependencies' => array('wp-block-editor', 'wp-components'),
3434
),
35-
array(
36-
'handle' => 'wp-widgets',
37-
'path' => 'widgets/style',
38-
'dependencies' => array('wp-block-editor', 'wp-components'),
39-
),
4035
array(
4136
'handle' => 'wp-patterns',
4237
'path' => 'patterns/style',
@@ -47,6 +42,11 @@
4742
'path' => 'components/style',
4843
'dependencies' => array(),
4944
),
45+
array(
46+
'handle' => 'wp-widgets',
47+
'path' => 'widgets/style',
48+
'dependencies' => array('wp-block-editor', 'wp-components'),
49+
),
5050
array(
5151
'handle' => 'wp-format-library',
5252
'path' => 'format-library/style',
@@ -67,16 +67,16 @@
6767
'path' => 'customize-widgets/style',
6868
'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-components', 'wp-media-utils', 'wp-preferences', 'wp-widgets'),
6969
),
70-
array(
71-
'handle' => 'wp-edit-widgets',
72-
'path' => 'edit-widgets/style',
73-
'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-components', 'wp-media-utils', 'wp-patterns', 'wp-preferences', 'wp-widgets'),
74-
),
7570
array(
7671
'handle' => 'wp-edit-post',
7772
'path' => 'edit-post/style',
7873
'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-commands', 'wp-components', 'wp-editor', 'wp-preferences', 'wp-widgets'),
7974
),
75+
array(
76+
'handle' => 'wp-edit-widgets',
77+
'path' => 'edit-widgets/style',
78+
'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-components', 'wp-media-utils', 'wp-patterns', 'wp-preferences', 'wp-widgets'),
79+
),
8080
array(
8181
'handle' => 'wp-block-library',
8282
'path' => 'block-library/style',

wp-includes/embed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ function get_oembed_response_data_for_url( $url, $args ) {
693693
return false;
694694
}
695695

696-
$width = isset( $args['width'] ) ? $args['width'] : 0;
696+
$width = $args['width'] ?? 0;
697697

698698
$data = get_oembed_response_data( $post_id, $width );
699699

wp-includes/js/dist/script-modules/index.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
'path' => 'interactivity/index',
1313
'asset' => 'interactivity/index.min.asset.php',
1414
),
15+
array(
16+
'id' => '@wordpress/a11y',
17+
'path' => 'a11y/index',
18+
'asset' => 'a11y/index.min.asset.php',
19+
),
20+
array(
21+
'id' => '@wordpress/core-abilities',
22+
'path' => 'core-abilities/index',
23+
'asset' => 'core-abilities/index.min.asset.php',
24+
),
1525
array(
1626
'id' => '@wordpress/interactivity-router',
1727
'path' => 'interactivity-router/index',
@@ -22,6 +32,11 @@
2232
'path' => 'interactivity-router/full-page',
2333
'asset' => 'interactivity-router/full-page.min.asset.php',
2434
),
35+
array(
36+
'id' => '@wordpress/abilities',
37+
'path' => 'abilities/index',
38+
'asset' => 'abilities/index.min.asset.php',
39+
),
2540
array(
2641
'id' => '@wordpress/latex-to-mathml',
2742
'path' => 'latex-to-mathml/index',
@@ -32,21 +47,6 @@
3247
'path' => 'latex-to-mathml/loader',
3348
'asset' => 'latex-to-mathml/loader.min.asset.php',
3449
),
35-
array(
36-
'id' => '@wordpress/a11y',
37-
'path' => 'a11y/index',
38-
'asset' => 'a11y/index.min.asset.php',
39-
),
40-
array(
41-
'id' => '@wordpress/abilities',
42-
'path' => 'abilities/index',
43-
'asset' => 'abilities/index.min.asset.php',
44-
),
45-
array(
46-
'id' => '@wordpress/core-abilities',
47-
'path' => 'core-abilities/index',
48-
'asset' => 'core-abilities/index.min.asset.php',
49-
),
5050
array(
5151
'id' => '@wordpress/route',
5252
'path' => 'route/index',

wp-includes/media.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = f
12291229
*/
12301230
function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon = false ) {
12311231
$image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
1232-
return isset( $image[0] ) ? $image[0] : false;
1232+
return $image[0] ?? false;
12331233
}
12341234

12351235
/**
@@ -1410,7 +1410,7 @@ function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attac
14101410
* be compared against the image URL using the same port.
14111411
*/
14121412
$parsed = parse_url( $image_baseurl );
1413-
$domain = isset( $parsed['host'] ) ? $parsed['host'] : '';
1413+
$domain = $parsed['host'] ?? '';
14141414

14151415
if ( isset( $parsed['port'] ) ) {
14161416
$domain .= ':' . $parsed['port'];
@@ -2171,7 +2171,7 @@ function wp_img_tag_add_loading_optimization_attrs( $image, $context ) {
21712171
*/
21722172
$filtered_decoding_attr = apply_filters(
21732173
'wp_img_tag_add_decoding_attr',
2174-
isset( $optimization_attrs['decoding'] ) ? $optimization_attrs['decoding'] : false,
2174+
$optimization_attrs['decoding'] ?? false,
21752175
$image,
21762176
$context
21772177
);
@@ -2213,7 +2213,7 @@ function wp_img_tag_add_loading_optimization_attrs( $image, $context ) {
22132213
*/
22142214
$filtered_loading_attr = apply_filters(
22152215
'wp_img_tag_add_loading_attr',
2216-
isset( $optimization_attrs['loading'] ) ? $optimization_attrs['loading'] : false,
2216+
$optimization_attrs['loading'] ?? false,
22172217
$image,
22182218
$context
22192219
);
@@ -2232,7 +2232,7 @@ function wp_img_tag_add_loading_optimization_attrs( $image, $context ) {
22322232
* is only intended for the specific scenario where the above filtered caused the problem.
22332233
*/
22342234
if ( isset( $optimization_attrs['fetchpriority'] ) && 'high' === $optimization_attrs['fetchpriority'] &&
2235-
( isset( $optimization_attrs['loading'] ) ? $optimization_attrs['loading'] : false ) !== $filtered_loading_attr &&
2235+
( $optimization_attrs['loading'] ?? false ) !== $filtered_loading_attr &&
22362236
'lazy' === $filtered_loading_attr
22372237
) {
22382238
_doing_it_wrong(
@@ -2380,7 +2380,7 @@ function wp_iframe_tag_add_loading_attr( $iframe, $context ) {
23802380
return $iframe;
23812381
}
23822382

2383-
$value = isset( $optimization_attrs['loading'] ) ? $optimization_attrs['loading'] : false;
2383+
$value = $optimization_attrs['loading'] ?? false;
23842384

23852385
/**
23862386
* Filters the `loading` attribute value to add to an iframe. Default 'lazy'.

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '7.0-alpha-61452';
19+
$wp_version = '7.0-alpha-61453';
2020

2121
/**
2222
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 commit comments

Comments
 (0)