From 5786196a26e59a1af57e2261fac538f71a0a3918 Mon Sep 17 00:00:00 2001 From: Ayesh Karunaratne Date: Mon, 31 Jul 2023 15:29:18 +0800 Subject: [PATCH] Replace `is_a` calls in core with `instanceof` Replaces all `is_a` function calls with `instanceof` keyword, which in theory should be faster, and provides more code clarity. The replacements use extra braces to enhance the clarity although they are technically not necessary. --- src/wp-content/themes/twentyseventeen/inc/template-tags.php | 2 +- src/wp-includes/admin-bar.php | 2 +- src/wp-includes/user.php | 4 ++-- src/wp-login.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/wp-content/themes/twentyseventeen/inc/template-tags.php b/src/wp-content/themes/twentyseventeen/inc/template-tags.php index 437ebd4241cd7..daef4892ba80e 100644 --- a/src/wp-content/themes/twentyseventeen/inc/template-tags.php +++ b/src/wp-content/themes/twentyseventeen/inc/template-tags.php @@ -140,7 +140,7 @@ function twentyseventeen_edit_link() { * @param int $id Front page section to display. */ function twentyseventeen_front_page_section( $partial = null, $id = 0 ) { - if ( is_a( $partial, 'WP_Customize_Partial' ) ) { + if ( $partial instanceof \WP_Customize_Partial ) { // Find out the ID and set it up during a selective refresh. global $twentyseventeencounter; diff --git a/src/wp-includes/admin-bar.php b/src/wp-includes/admin-bar.php index a35051ac8b6c4..73a3de5384080 100644 --- a/src/wp-includes/admin-bar.php +++ b/src/wp-includes/admin-bar.php @@ -897,7 +897,7 @@ function wp_admin_bar_edit_menu( $wp_admin_bar ) { ) ); } - } elseif ( is_a( $current_object, 'WP_User' ) && current_user_can( 'edit_user', $current_object->ID ) ) { + } elseif ( ( $current_object instanceof \WP_User ) && current_user_can( 'edit_user', $current_object->ID ) ) { $edit_user_link = get_edit_user_link( $current_object->ID ); if ( $edit_user_link ) { $wp_admin_bar->add_node( diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index 9b25e49aa9d65..849d884e7b26d 100644 --- a/src/wp-includes/user.php +++ b/src/wp-includes/user.php @@ -4032,7 +4032,7 @@ function _wp_privacy_account_request_confirmed( $request_id ) { function _wp_privacy_send_request_confirmation_notification( $request_id ) { $request = wp_get_user_request( $request_id ); - if ( ! is_a( $request, 'WP_User_Request' ) || 'request-confirmed' !== $request->status ) { + if ( ! ( $request instanceof \WP_User_Request ) || 'request-confirmed' !== $request->status ) { return; } @@ -4244,7 +4244,7 @@ function _wp_privacy_send_request_confirmation_notification( $request_id ) { function _wp_privacy_send_erasure_fulfillment_notification( $request_id ) { $request = wp_get_user_request( $request_id ); - if ( ! is_a( $request, 'WP_User_Request' ) || 'request-completed' !== $request->status ) { + if ( ! ( $request instanceof \WP_User_Request ) || 'request-completed' !== $request->status ) { return; } diff --git a/src/wp-login.php b/src/wp-login.php index 8810f5d0d81e7..813ff3c45d91e 100644 --- a/src/wp-login.php +++ b/src/wp-login.php @@ -1303,7 +1303,7 @@ function wp_login_viewport_meta() { } // Check if it is time to add a redirect to the admin email confirmation screen. - if ( is_a( $user, 'WP_User' ) && $user->exists() && $user->has_cap( 'manage_options' ) ) { + if ( ( $user instanceof \WP_User ) && $user->exists() && $user->has_cap( 'manage_options' ) ) { $admin_email_lifespan = (int) get_option( 'admin_email_lifespan' ); /*