From 026de6863848a0e6f06b84cf6b5ce1368331fc58 Mon Sep 17 00:00:00 2001
From: jrfnl <jrfnl@users.noreply.github.com>
Date: Sat, 27 Jul 2019 04:32:51 +0200
Subject: [PATCH] [src] Remove work-arounds for spl_object_hash()
---
src/wp-includes/class-wp-widget-factory.php | 33 ++-------------------
src/wp-includes/plugin.php | 18 +----------
2 files changed, 3 insertions(+), 48 deletions(-)
diff --git a/src/wp-includes/class-wp-widget-factory.php b/src/wp-includes/class-wp-widget-factory.php
index 68f4623098..ec5a96d6a9 100644
|
a
|
b
|
class WP_Widget_Factory { |
| 55 | 55 | */ |
| 56 | 56 | private $hashed_class_counts = array(); |
| 57 | 57 | |
| 58 | | /** |
| 59 | | * Hashes an object, doing fallback of `spl_object_hash()` if not available. |
| 60 | | * |
| 61 | | * This can be eliminated in favor of straight spl_object_hash() when 5.3 |
| 62 | | * is the minimum requirement for PHP. |
| 63 | | * |
| 64 | | * @since 4.6.0 |
| 65 | | * |
| 66 | | * @param WP_Widget $widget Widget. |
| 67 | | * @return string Object hash. |
| 68 | | */ |
| 69 | | private function hash_object( $widget ) { |
| 70 | | if ( function_exists( 'spl_object_hash' ) ) { |
| 71 | | return spl_object_hash( $widget ); |
| 72 | | } else { |
| 73 | | $class_name = get_class( $widget ); |
| 74 | | $hash = $class_name; |
| 75 | | if ( ! isset( $widget->_wp_widget_factory_hash_id ) ) { |
| 76 | | if ( ! isset( $this->hashed_class_counts[ $class_name ] ) ) { |
| 77 | | $this->hashed_class_counts[ $class_name ] = 0; |
| 78 | | } |
| 79 | | $this->hashed_class_counts[ $class_name ] += 1; |
| 80 | | $widget->_wp_widget_factory_hash_id = $this->hashed_class_counts[ $class_name ]; |
| 81 | | } |
| 82 | | $hash .= ':' . $widget->_wp_widget_factory_hash_id; |
| 83 | | return $hash; |
| 84 | | } |
| 85 | | } |
| 86 | | |
| 87 | 58 | /** |
| 88 | 59 | * Registers a widget subclass. |
| 89 | 60 | * |
| … |
… |
class WP_Widget_Factory { |
| 95 | 66 | */ |
| 96 | 67 | public function register( $widget ) { |
| 97 | 68 | if ( $widget instanceof WP_Widget ) { |
| 98 | | $this->widgets[ $this->hash_object( $widget ) ] = $widget; |
| | 69 | $this->widgets[ spl_object_hash( $widget ) ] = $widget; |
| 99 | 70 | } else { |
| 100 | 71 | $this->widgets[ $widget ] = new $widget(); |
| 101 | 72 | } |
| … |
… |
class WP_Widget_Factory { |
| 112 | 83 | */ |
| 113 | 84 | public function unregister( $widget ) { |
| 114 | 85 | if ( $widget instanceof WP_Widget ) { |
| 115 | | unset( $this->widgets[ $this->hash_object( $widget ) ] ); |
| | 86 | unset( $this->widgets[ spl_object_hash( $widget ) ] ); |
| 116 | 87 | } else { |
| 117 | 88 | unset( $this->widgets[ $widget ] ); |
| 118 | 89 | } |
diff --git a/src/wp-includes/plugin.php b/src/wp-includes/plugin.php
index 1f6cacd5b4..c83ebdb81f 100644
|
a
|
b
|
function _wp_filter_build_unique_id( $tag, $function, $priority ) { |
| 925 | 925 | |
| 926 | 926 | if ( is_object( $function[0] ) ) { |
| 927 | 927 | // Object Class Calling |
| 928 | | if ( function_exists( 'spl_object_hash' ) ) { |
| 929 | | return spl_object_hash( $function[0] ) . $function[1]; |
| 930 | | } else { |
| 931 | | $obj_idx = get_class( $function[0] ) . $function[1]; |
| 932 | | if ( ! isset( $function[0]->wp_filter_id ) ) { |
| 933 | | if ( false === $priority ) { |
| 934 | | return false; |
| 935 | | } |
| 936 | | $obj_idx .= isset( $wp_filter[ $tag ][ $priority ] ) ? count( (array) $wp_filter[ $tag ][ $priority ] ) : $filter_id_count; |
| 937 | | $function[0]->wp_filter_id = $filter_id_count; |
| 938 | | ++$filter_id_count; |
| 939 | | } else { |
| 940 | | $obj_idx .= $function[0]->wp_filter_id; |
| 941 | | } |
| 942 | | |
| 943 | | return $obj_idx; |
| 944 | | } |
| | 928 | return spl_object_hash( $function[0] ) . $function[1]; |
| 945 | 929 | } elseif ( is_string( $function[0] ) ) { |
| 946 | 930 | // Static Calling |
| 947 | 931 | return $function[0] . '::' . $function[1]; |