Skip to content

Commit b92491b

Browse files
Coding Standards: Use instanceof keyword instead of the is_a() function.
This is a micro-optimization that removes a few unnecessary function calls. Follow-up to [31188], [34369], [38986], [41159], [43211], [43230], [44606], [45757]. Props ayeshrajans, jrf, rajinsharwar, costdev, mukesh27, SergeyBiryukov. Fixes #58943. git-svn-id: https://develop.svn.wordpress.org/trunk@56352 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f8b4e2c commit b92491b

7 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/wp-content/themes/twentyseventeen/inc/template-tags.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function twentyseventeen_edit_link() {
140140
* @param int $id Front page section to display.
141141
*/
142142
function twentyseventeen_front_page_section( $partial = null, $id = 0 ) {
143-
if ( is_a( $partial, 'WP_Customize_Partial' ) ) {
143+
if ( $partial instanceof WP_Customize_Partial ) {
144144
// Find out the ID and set it up during a selective refresh.
145145
global $twentyseventeencounter;
146146

src/wp-includes/admin-bar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ function wp_admin_bar_edit_menu( $wp_admin_bar ) {
897897
)
898898
);
899899
}
900-
} elseif ( is_a( $current_object, 'WP_User' ) && current_user_can( 'edit_user', $current_object->ID ) ) {
900+
} elseif ( $current_object instanceof WP_User && current_user_can( 'edit_user', $current_object->ID ) ) {
901901
$edit_user_link = get_edit_user_link( $current_object->ID );
902902
if ( $edit_user_link ) {
903903
$wp_admin_bar->add_node(

src/wp-includes/http.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ function wp_remote_retrieve_cookie( $response, $name ) {
354354
function wp_remote_retrieve_cookie_value( $response, $name ) {
355355
$cookie = wp_remote_retrieve_cookie( $response, $name );
356356

357-
if ( ! is_a( $cookie, 'WP_Http_Cookie' ) ) {
357+
if ( ! ( $cookie instanceof WP_Http_Cookie ) ) {
358358
return '';
359359
}
360360

src/wp-includes/user.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4032,7 +4032,7 @@ function _wp_privacy_account_request_confirmed( $request_id ) {
40324032
function _wp_privacy_send_request_confirmation_notification( $request_id ) {
40334033
$request = wp_get_user_request( $request_id );
40344034

4035-
if ( ! is_a( $request, 'WP_User_Request' ) || 'request-confirmed' !== $request->status ) {
4035+
if ( ! ( $request instanceof WP_User_Request ) || 'request-confirmed' !== $request->status ) {
40364036
return;
40374037
}
40384038

@@ -4244,7 +4244,7 @@ function _wp_privacy_send_request_confirmation_notification( $request_id ) {
42444244
function _wp_privacy_send_erasure_fulfillment_notification( $request_id ) {
42454245
$request = wp_get_user_request( $request_id );
42464246

4247-
if ( ! is_a( $request, 'WP_User_Request' ) || 'request-completed' !== $request->status ) {
4247+
if ( ! ( $request instanceof WP_User_Request ) || 'request-completed' !== $request->status ) {
42484248
return;
42494249
}
42504250

src/wp-login.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ function wp_login_viewport_meta() {
13031303
}
13041304

13051305
// Check if it is time to add a redirect to the admin email confirmation screen.
1306-
if ( is_a( $user, 'WP_User' ) && $user->exists() && $user->has_cap( 'manage_options' ) ) {
1306+
if ( $user instanceof WP_User && $user->exists() && $user->has_cap( 'manage_options' ) ) {
13071307
$admin_email_lifespan = (int) get_option( 'admin_email_lifespan' );
13081308

13091309
/*

tests/phpunit/includes/testcase-rest-api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
abstract class WP_Test_REST_TestCase extends WP_UnitTestCase {
44
protected function assertErrorResponse( $code, $response, $status = null ) {
55

6-
if ( is_a( $response, 'WP_REST_Response' ) ) {
6+
if ( $response instanceof WP_REST_Response ) {
77
$response = $response->as_error();
88
}
99

tests/phpunit/tests/actions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ public function test_remove_anonymous_callback() {
535535
foreach ( $hook as $priority => $filter ) {
536536
foreach ( $filter as $identifier => $function ) {
537537
if ( is_array( $function )
538-
&& is_a( $function['function'][0], 'MockAction' )
538+
&& $function['function'][0] instanceof MockAction
539539
&& 'action' === $function['function'][1]
540540
) {
541541
remove_filter(

0 commit comments

Comments
 (0)