From a1716dc9bead3c205890339986e4090ae22f72bd Mon Sep 17 00:00:00 2001
From: jrfnl <jrfnl@users.noreply.github.com>
Date: Sun, 18 Oct 2020 08:27:46 +0200
Subject: [PATCH] Modernize: use `instanceof` instead of a comparison with
`get_class()`
Includes adjusting external libraries which are no longer maintained externally.
---
src/wp-admin/includes/class-pclzip.php | 4 ++--
src/wp-includes/Text/Diff.php | 2 +-
src/wp-includes/class-json.php | 2 +-
src/wp-includes/rest-api.php | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/wp-admin/includes/class-pclzip.php b/src/wp-admin/includes/class-pclzip.php
index 47f2a344a2..3757497d6c 100644
|
a
|
b
|
|
| 1171 | 1171 | $this->privErrorReset(); |
| 1172 | 1172 | |
| 1173 | 1173 | // ----- Look if the $p_archive is a PclZip object |
| 1174 | | if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip')) |
| | 1174 | if ((is_object($p_archive)) && $p_archive instanceof pclzip) |
| 1175 | 1175 | { |
| 1176 | 1176 | |
| 1177 | 1177 | // ----- Duplicate the archive |
| … |
… |
|
| 1235 | 1235 | } |
| 1236 | 1236 | |
| 1237 | 1237 | // ----- Look if the $p_archive_to_add is a PclZip object |
| 1238 | | if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip')) |
| | 1238 | if ((is_object($p_archive_to_add)) && $p_archive_to_add instanceof pclzip) |
| 1239 | 1239 | { |
| 1240 | 1240 | |
| 1241 | 1241 | // ----- Merge the archive |
diff --git a/src/wp-includes/Text/Diff.php b/src/wp-includes/Text/Diff.php
index ab1c9a26dd..61a9320a0e 100644
|
a
|
b
|
class Text_Diff {
|
| 276 | 276 | |
| 277 | 277 | $prevtype = null; |
| 278 | 278 | foreach ($this->_edits as $edit) { |
| 279 | | if ($prevtype == get_class($edit)) { |
| | 279 | if ($edit instanceof $prevtype) { |
| 280 | 280 | trigger_error("Edit sequence is non-optimal", E_USER_ERROR); |
| 281 | 281 | } |
| 282 | 282 | $prevtype = get_class($edit); |
diff --git a/src/wp-includes/class-json.php b/src/wp-includes/class-json.php
index 66443e1068..036150f1d8 100644
|
a
|
b
|
class Services_JSON
|
| 918 | 918 | |
| 919 | 919 | if (class_exists('pear')) { |
| 920 | 920 | return PEAR::isError($data, $code); |
| 921 | | } elseif (is_object($data) && (get_class($data) == 'services_json_error' || |
| | 921 | } elseif (is_object($data) && ($data instanceof services_json_error || |
| 922 | 922 | is_subclass_of($data, 'services_json_error'))) { |
| 923 | 923 | return true; |
| 924 | 924 | } |
diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php
index bbbeae3532..ed62943309 100644
|
a
|
b
|
function rest_get_route_for_term( $term ) {
|
| 2390 | 2390 | $route = ''; |
| 2391 | 2391 | |
| 2392 | 2392 | // The only controller that works is the Terms controller. |
| 2393 | | if ( 'WP_REST_Terms_Controller' === get_class( $controller ) ) { |
| | 2393 | if ( $controller instanceof WP_REST_Terms_Controller ) { |
| 2394 | 2394 | $namespace = 'wp/v2'; |
| 2395 | 2395 | $rest_base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; |
| 2396 | 2396 | $route = sprintf( '/%s/%s/%d', $namespace, $rest_base, $term->term_id ); |