Commit f124de962f for wordpress.org
commit f124de962f9bcc016b9256a4c8b392799fdd7798
Author: Weston Ruter <weston@xwp.co>
Date: Tue Jan 6 06:08:03 2026 +0000
Code Modernization: Taxonomy, Posts/Post Types, Options/Meta APIs, Query, General: Use null coalescing operator instead of `isset()` ternaries.
Developed as a subset of https://github.com/WordPress/wordpress-develop/pull/10654
Initially developed in https://github.com/WordPress/wordpress-develop/pull/4886
Follow-up to [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@61445
git-svn-id: http://core.svn.wordpress.org/trunk@60757 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-admin/includes/class-wp-posts-list-table.php b/wp-admin/includes/class-wp-posts-list-table.php
index 3d2ecb6887..d2d6eda2cb 100644
--- a/wp-admin/includes/class-wp-posts-list-table.php
+++ b/wp-admin/includes/class-wp-posts-list-table.php
@@ -76,7 +76,7 @@ class WP_Posts_List_Table extends WP_List_Table {
parent::__construct(
array(
'plural' => 'posts',
- 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
+ 'screen' => $args['screen'] ?? null,
)
);
@@ -531,7 +531,7 @@ class WP_Posts_List_Table extends WP_List_Table {
return;
}
- $displayed_post_format = isset( $_GET['post_format'] ) ? $_GET['post_format'] : '';
+ $displayed_post_format = $_GET['post_format'] ?? '';
?>
<label for="filter-by-format" class="screen-reader-text">
<?php
@@ -1264,7 +1264,7 @@ class WP_Posts_List_Table extends WP_List_Table {
?>
<div class="post-com-count-wrapper">
<?php
- $pending_comments = isset( $this->comment_pending_count[ $post->ID ] ) ? $this->comment_pending_count[ $post->ID ] : 0;
+ $pending_comments = $this->comment_pending_count[ $post->ID ] ?? 0;
$this->comments_bubble( $post->ID, $pending_comments );
?>
diff --git a/wp-admin/includes/class-wp-terms-list-table.php b/wp-admin/includes/class-wp-terms-list-table.php
index c624403d60..7537a49997 100644
--- a/wp-admin/includes/class-wp-terms-list-table.php
+++ b/wp-admin/includes/class-wp-terms-list-table.php
@@ -41,7 +41,7 @@ class WP_Terms_List_Table extends WP_List_Table {
array(
'plural' => 'tags',
'singular' => 'tag',
- 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
+ 'screen' => $args['screen'] ?? null,
)
);
diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php
index d5034b3ce0..e241989f5b 100644
--- a/wp-admin/includes/post.php
+++ b/wp-admin/includes/post.php
@@ -429,7 +429,7 @@ function edit_post( $post_data = null ) {
}
}
- $attachment_data = isset( $post_data['attachments'][ $post_id ] ) ? $post_data['attachments'][ $post_id ] : array();
+ $attachment_data = $post_data['attachments'][ $post_id ] ?? array();
/** This filter is documented in wp-admin/includes/media.php */
$translated = apply_filters( 'attachment_fields_to_save', $translated, $attachment_data );
@@ -1014,7 +1014,7 @@ function add_meta( $post_id ) {
$metakeyselect = isset( $_POST['metakeyselect'] ) ? wp_unslash( trim( $_POST['metakeyselect'] ) ) : '';
$metakeyinput = isset( $_POST['metakeyinput'] ) ? wp_unslash( trim( $_POST['metakeyinput'] ) ) : '';
- $metavalue = isset( $_POST['metavalue'] ) ? $_POST['metavalue'] : '';
+ $metavalue = $_POST['metavalue'] ?? '';
if ( is_string( $metavalue ) ) {
$metavalue = trim( $metavalue );
}
@@ -2043,7 +2043,7 @@ function wp_autosave_post_revisioned_meta_fields( $new_autosave ) {
* Ignoring sanitization to avoid altering meta. Ignoring the nonce check because
* this is hooked on inner core hooks where a valid nonce was already checked.
*/
- $posted_data = isset( $_POST['data']['wp_autosave'] ) ? $_POST['data']['wp_autosave'] : $_POST;
+ $posted_data = $_POST['data']['wp_autosave'] ?? $_POST;
$post_type = get_post_type( $new_autosave['post_parent'] );
diff --git a/wp-includes/class-wp-meta-query.php b/wp-includes/class-wp-meta-query.php
index dcfbfee4ef..67e2d3d27e 100644
--- a/wp-includes/class-wp-meta-query.php
+++ b/wp-includes/class-wp-meta-query.php
@@ -619,7 +619,7 @@ class WP_Meta_Query {
$clause['alias'] = $alias;
// Determine the data type.
- $_meta_type = isset( $clause['type'] ) ? $clause['type'] : '';
+ $_meta_type = $clause['type'] ?? '';
$meta_type = $this->get_cast_for_type( $_meta_type );
$clause['cast'] = $meta_type;
diff --git a/wp-includes/class-wp-term.php b/wp-includes/class-wp-term.php
index 0f5631353e..f512936e03 100644
--- a/wp-includes/class-wp-term.php
+++ b/wp-includes/class-wp-term.php
@@ -236,7 +236,7 @@ final class WP_Term {
$data = new stdClass();
$columns = array( 'term_id', 'name', 'slug', 'term_group', 'term_taxonomy_id', 'taxonomy', 'description', 'parent', 'count' );
foreach ( $columns as $column ) {
- $data->{$column} = isset( $this->{$column} ) ? $this->{$column} : null;
+ $data->{$column} = $this->{$column} ?? null;
}
return sanitize_term( $data, $data->taxonomy, 'raw' );
diff --git a/wp-includes/class-wp.php b/wp-includes/class-wp.php
index d584416eac..f1664747d4 100644
--- a/wp-includes/class-wp.php
+++ b/wp-includes/class-wp.php
@@ -167,7 +167,7 @@ class WP {
$error = '404';
$this->did_permalink = true;
- $pathinfo = isset( $_SERVER['PATH_INFO'] ) ? $_SERVER['PATH_INFO'] : '';
+ $pathinfo = $_SERVER['PATH_INFO'] ?? '';
list( $pathinfo ) = explode( '?', $pathinfo );
$pathinfo = str_replace( '%', '%25', $pathinfo );
@@ -539,7 +539,7 @@ class WP {
}
if ( is_singular() ) {
- $post = isset( $wp_query->post ) ? $wp_query->post : null;
+ $post = $wp_query->post ?? null;
// Only set X-Pingback for single posts that allow pings.
if ( $post && pings_open( $post ) ) {
@@ -669,7 +669,7 @@ class WP {
$GLOBALS['query_string'] = $this->query_string;
$GLOBALS['posts'] = & $wp_query->posts;
- $GLOBALS['post'] = isset( $wp_query->post ) ? $wp_query->post : null;
+ $GLOBALS['post'] = $wp_query->post ?? null;
$GLOBALS['request'] = $wp_query->request;
if ( $wp_query->is_single() || $wp_query->is_page() ) {
@@ -755,7 +755,7 @@ class WP {
$content_found = true;
if ( is_singular() ) {
- $post = isset( $wp_query->post ) ? $wp_query->post : null;
+ $post = $wp_query->post ?? null;
$next = '<!--nextpage-->';
// Check for paged content that exceeds the max number of pages.
diff --git a/wp-includes/css/dist/index.php b/wp-includes/css/dist/index.php
index 79fcc9aba9..357fbbb4a7 100644
--- a/wp-includes/css/dist/index.php
+++ b/wp-includes/css/dist/index.php
@@ -22,29 +22,29 @@ return array(
'path' => 'preferences/style',
'dependencies' => array('wp-components'),
),
- array(
- 'handle' => 'wp-commands',
- 'path' => 'commands/style',
- 'dependencies' => array('wp-components'),
- ),
array(
'handle' => 'wp-reusable-blocks',
'path' => 'reusable-blocks/style',
'dependencies' => array('wp-block-editor', 'wp-components'),
),
array(
- 'handle' => 'wp-widgets',
- 'path' => 'widgets/style',
+ 'handle' => 'wp-patterns',
+ 'path' => 'patterns/style',
'dependencies' => array('wp-block-editor', 'wp-components'),
),
+ array(
+ 'handle' => 'wp-commands',
+ 'path' => 'commands/style',
+ 'dependencies' => array('wp-components'),
+ ),
array(
'handle' => 'wp-components',
'path' => 'components/style',
'dependencies' => array(),
),
array(
- 'handle' => 'wp-patterns',
- 'path' => 'patterns/style',
+ 'handle' => 'wp-widgets',
+ 'path' => 'widgets/style',
'dependencies' => array('wp-block-editor', 'wp-components'),
),
array(
@@ -67,16 +67,16 @@ return array(
'path' => 'customize-widgets/style',
'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-components', 'wp-media-utils', 'wp-preferences', 'wp-widgets'),
),
- array(
- 'handle' => 'wp-edit-post',
- 'path' => 'edit-post/style',
- 'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-commands', 'wp-components', 'wp-editor', 'wp-preferences', 'wp-widgets'),
- ),
array(
'handle' => 'wp-edit-widgets',
'path' => 'edit-widgets/style',
'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-components', 'wp-media-utils', 'wp-patterns', 'wp-preferences', 'wp-widgets'),
),
+ array(
+ 'handle' => 'wp-edit-post',
+ 'path' => 'edit-post/style',
+ 'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-commands', 'wp-components', 'wp-editor', 'wp-preferences', 'wp-widgets'),
+ ),
array(
'handle' => 'wp-block-library',
'path' => 'block-library/style',
diff --git a/wp-includes/functions.php b/wp-includes/functions.php
index cfec0b6df6..82a95c265e 100644
--- a/wp-includes/functions.php
+++ b/wp-includes/functions.php
@@ -952,7 +952,7 @@ function do_enclose( $content, $post ) {
$headers = wp_get_http_headers( $url );
if ( $headers ) {
$len = isset( $headers['Content-Length'] ) ? (int) $headers['Content-Length'] : 0;
- $type = isset( $headers['Content-Type'] ) ? $headers['Content-Type'] : '';
+ $type = $headers['Content-Type'] ?? '';
$allowed_types = array( 'video', 'audio' );
// Check to see if we can figure out the mime type from the extension.
@@ -3690,7 +3690,7 @@ function wp_nonce_ays( $action ) {
get_bloginfo( 'name' )
);
- $redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
+ $redirect_to = $_REQUEST['redirect_to'] ?? '';
$html = $title;
$html .= '</p><p>';
@@ -6139,8 +6139,8 @@ function wp_trigger_error( $function_name, $message, $error_level = E_USER_NOTIC
* @return bool Whether the server is running lighttpd < 1.5.0.
*/
function is_lighttpd_before_150() {
- $server_parts = explode( '/', isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '' );
- $server_parts[1] = isset( $server_parts[1] ) ? $server_parts[1] : '';
+ $server_parts = explode( '/', $_SERVER['SERVER_SOFTWARE'] ?? '' );
+ $server_parts[1] = $server_parts[1] ?? '';
return ( 'lighttpd' === $server_parts[0] && -1 === version_compare( $server_parts[1], '1.5.0' ) );
}
@@ -7121,9 +7121,9 @@ function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = ar
while (
$tortoise
&&
- ( $evanescent_hare = isset( $override[ $hare ] ) ? $override[ $hare ] : call_user_func_array( $callback, array_merge( array( $hare ), $callback_args ) ) )
+ ( $evanescent_hare = $override[ $hare ] ?? call_user_func_array( $callback, array_merge( array( $hare ), $callback_args ) ) )
&&
- ( $hare = isset( $override[ $evanescent_hare ] ) ? $override[ $evanescent_hare ] : call_user_func_array( $callback, array_merge( array( $evanescent_hare ), $callback_args ) ) )
+ ( $hare = $override[ $evanescent_hare ] ?? call_user_func_array( $callback, array_merge( array( $evanescent_hare ), $callback_args ) ) )
) {
if ( $_return_loop ) {
$return[ $tortoise ] = true;
@@ -7137,7 +7137,7 @@ function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = ar
}
// Increment tortoise by one step.
- $tortoise = isset( $override[ $tortoise ] ) ? $override[ $tortoise ] : call_user_func_array( $callback, array_merge( array( $tortoise ), $callback_args ) );
+ $tortoise = $override[ $tortoise ] ?? call_user_func_array( $callback, array_merge( array( $tortoise ), $callback_args ) );
}
return false;
@@ -7266,7 +7266,7 @@ function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pr
if ( in_array( $call['function'], array( 'do_action', 'apply_filters', 'do_action_ref_array', 'apply_filters_ref_array' ), true ) ) {
$caller[] = "{$call['function']}('{$call['args'][0]}')";
} elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ), true ) ) {
- $filename = isset( $call['args'][0] ) ? $call['args'][0] : '';
+ $filename = $call['args'][0] ?? '';
$caller[] = $call['function'] . "('" . str_replace( $truncate_paths, '', wp_normalize_path( $filename ) ) . "')";
} else {
$caller[] = $call['function'];
diff --git a/wp-includes/option.php b/wp-includes/option.php
index 735a1c6539..ec6ddd9372 100644
--- a/wp-includes/option.php
+++ b/wp-includes/option.php
@@ -1755,7 +1755,7 @@ function wp_user_settings() {
function get_user_setting( $name, $default_value = false ) {
$all_user_settings = get_all_user_settings();
- return isset( $all_user_settings[ $name ] ) ? $all_user_settings[ $name ] : $default_value;
+ return $all_user_settings[ $name ] ?? $default_value;
}
/**
diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php
index 3d82ba81b6..3b7c6995c3 100644
--- a/wp-includes/post-template.php
+++ b/wp-includes/post-template.php
@@ -118,8 +118,8 @@ function the_title_attribute( $args = '' ) {
function get_the_title( $post = 0 ) {
$post = get_post( $post );
- $post_title = isset( $post->post_title ) ? $post->post_title : '';
- $post_id = isset( $post->ID ) ? $post->ID : 0;
+ $post_title = $post->post_title ?? '';
+ $post_id = $post->ID ?? 0;
if ( ! is_admin() ) {
if ( ! empty( $post->post_password ) ) {
@@ -191,7 +191,7 @@ function the_guid( $post = 0 ) {
$post = get_post( $post );
$post_guid = isset( $post->guid ) ? get_the_guid( $post ) : '';
- $post_id = isset( $post->ID ) ? $post->ID : 0;
+ $post_id = $post->ID ?? 0;
/**
* Filters the escaped Global Unique Identifier (guid) of the post.
@@ -221,8 +221,8 @@ function the_guid( $post = 0 ) {
function get_the_guid( $post = 0 ) {
$post = get_post( $post );
- $post_guid = isset( $post->guid ) ? $post->guid : '';
- $post_id = isset( $post->ID ) ? $post->ID : 0;
+ $post_guid = $post->guid ?? '';
+ $post_id = $post->ID ?? 0;
/**
* Filters the Global Unique Identifier (guid) of the post.
diff --git a/wp-includes/post.php b/wp-includes/post.php
index a88d1afd57..ae9900a704 100644
--- a/wp-includes/post.php
+++ b/wp-includes/post.php
@@ -2201,10 +2201,7 @@ function _get_custom_object_labels( $data_object, $nohier_vs_hier_defaults ) {
}
if ( ! isset( $data_object->labels['name_admin_bar'] ) ) {
- $data_object->labels['name_admin_bar'] =
- isset( $data_object->labels['singular_name'] )
- ? $data_object->labels['singular_name']
- : $data_object->name;
+ $data_object->labels['name_admin_bar'] = $data_object->labels['singular_name'] ?? $data_object->name;
}
if ( ! isset( $data_object->labels['menu_name'] ) && isset( $data_object->labels['name'] ) ) {
@@ -2856,7 +2853,7 @@ function get_post_custom_values( $key = '', $post_id = 0 ) {
$custom = get_post_custom( $post_id );
- return isset( $custom[ $key ] ) ? $custom[ $key ] : null;
+ return $custom[ $key ] ?? null;
}
/**
@@ -4730,11 +4727,11 @@ function wp_insert_post( $postarr, $wp_error = false, $fire_after_hooks = true )
// These variables are needed by compact() later.
$post_content_filtered = $postarr['post_content_filtered'];
- $post_author = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id;
+ $post_author = $postarr['post_author'] ?? $user_id;
$ping_status = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status'];
$to_ping = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : '';
- $pinged = isset( $postarr['pinged'] ) ? $postarr['pinged'] : '';
- $import_id = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0;
+ $pinged = $postarr['pinged'] ?? '';
+ $import_id = $postarr['import_id'] ?? 0;
/*
* The 'wp_insert_post_parent' filter expects all variables to be present.
@@ -4746,7 +4743,7 @@ function wp_insert_post( $postarr, $wp_error = false, $fire_after_hooks = true )
$menu_order = 0;
}
- $post_password = isset( $postarr['post_password'] ) ? $postarr['post_password'] : '';
+ $post_password = $postarr['post_password'] ?? '';
if ( 'private' === $post_status ) {
$post_password = '';
}
@@ -4815,7 +4812,7 @@ function wp_insert_post( $postarr, $wp_error = false, $fire_after_hooks = true )
$post_name = wp_unique_post_slug( $post_name, $post_id, $post_status, $post_type, $post_parent );
// Don't unslash.
- $post_mime_type = isset( $postarr['post_mime_type'] ) ? $postarr['post_mime_type'] : '';
+ $post_mime_type = $postarr['post_mime_type'] ?? '';
// Expected_slashed (everything!).
$data = compact(
diff --git a/wp-includes/revision.php b/wp-includes/revision.php
index 2ae82b0511..d361e0e987 100644
--- a/wp-includes/revision.php
+++ b/wp-includes/revision.php
@@ -89,8 +89,8 @@ function _wp_post_revision_data( $post = array(), $autosave = false ) {
$revision_data['post_status'] = 'inherit';
$revision_data['post_type'] = 'revision';
$revision_data['post_name'] = $autosave ? "$post[ID]-autosave-v1" : "$post[ID]-revision-v1"; // "1" is the revisioning system version.
- $revision_data['post_date'] = isset( $post['post_modified'] ) ? $post['post_modified'] : '';
- $revision_data['post_date_gmt'] = isset( $post['post_modified_gmt'] ) ? $post['post_modified_gmt'] : '';
+ $revision_data['post_date'] = $post['post_modified'] ?? '';
+ $revision_data['post_date_gmt'] = $post['post_modified_gmt'] ?? '';
return $revision_data;
}
diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php
index 003b414f4f..46e6bcce76 100644
--- a/wp-includes/taxonomy.php
+++ b/wp-includes/taxonomy.php
@@ -1723,7 +1723,7 @@ function sanitize_term( $term, $taxonomy, $context = 'display' ) {
$do_object = is_object( $term );
- $term_id = $do_object ? $term->term_id : ( isset( $term['term_id'] ) ? $term['term_id'] : 0 );
+ $term_id = $do_object ? $term->term_id : ( $term['term_id'] ?? 0 );
foreach ( (array) $fields as $field ) {
if ( $do_object ) {
@@ -3280,7 +3280,7 @@ function wp_update_term( $term_id, $taxonomy, $args = array() ) {
$parsed_args['slug'] = $slug;
- $term_group = isset( $parsed_args['term_group'] ) ? $parsed_args['term_group'] : 0;
+ $term_group = $parsed_args['term_group'] ?? 0;
if ( $args['alias_of'] ) {
$alias = get_term_by( 'slug', $args['alias_of'], $taxonomy );
if ( ! empty( $alias->term_group ) ) {
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 54b40ee413..d7d6541c1b 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.0-alpha-61444';
+$wp_version = '7.0-alpha-61445';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.