Skip to content

Commit

Permalink
Replace is_a calls in core with instanceof
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ayesh committed Jul 31, 2023
1 parent 8b819a1 commit 5786196
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/admin-bar.php
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/user.php
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/wp-login.php
Expand Up @@ -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' );

/*
Expand Down

0 comments on commit 5786196

Please sign in to comment.