diff --git a/wp-includes/class-wp-widget-factory.php b/wp-includes/class-wp-widget-factory.php index 9b9214e238..ae721542dd 100644 --- a/wp-includes/class-wp-widget-factory.php +++ b/wp-includes/class-wp-widget-factory.php @@ -45,6 +45,50 @@ class WP_Widget_Factory { self::__construct(); } + /** + * Memory for the number of times unique class instances have been hashed. + * + * This can be eliminated in favor of straight spl_object_hash() when 5.3 + * is the minimum requirement for PHP. + * + * @since 4.6.0 + * @access private + * @see WP_Widget_Factory::hash_object() + * + * @var array + */ + private $hashed_class_counts = array(); + + /** + * Hash an object, doing fallback of `spl_object_hash()` if not available. + * + * This can be eliminated in favor of straight spl_object_hash() when 5.3 + * is the minimum requirement for PHP. + * + * @since 4.6.0 + * @access private + * + * @param WP_Widget $widget Widget. + * @return string Object hash. + */ + private function hash_object( $widget ) { + if ( function_exists( 'spl_object_hash' ) ) { + return spl_object_hash( $widget ); + } else { + $class_name = get_class( $widget ); + $hash = $class_name; + if ( ! isset( $widget->_wp_widget_factory_hash_id ) ) { + if ( ! isset( $this->hashed_class_counts[ $class_name ] ) ) { + $this->hashed_class_counts[ $class_name ] = 0; + } + $this->hashed_class_counts[ $class_name ] += 1; + $widget->_wp_widget_factory_hash_id = $this->hashed_class_counts[ $class_name ]; + } + $hash .= ':' . $widget->_wp_widget_factory_hash_id; + return $hash; + } + } + /** * Registers a widget subclass. * @@ -56,7 +100,7 @@ class WP_Widget_Factory { */ public function register( $widget ) { if ( $widget instanceof WP_Widget ) { - $this->widgets[ spl_object_hash( $widget ) ] = $widget; + $this->widgets[ $this->hash_object( $widget ) ] = $widget; } else { $this->widgets[ $widget ] = new $widget(); } @@ -73,7 +117,7 @@ class WP_Widget_Factory { */ public function unregister( $widget ) { if ( $widget instanceof WP_Widget ) { - unset( $this->widgets[ spl_object_hash( $widget ) ] ); + unset( $this->widgets[ $this->hash_object( $widget ) ] ); } else { unset( $this->widgets[ $widget ] ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 0dd5cc46e4..d44dc5e2e6 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.6-alpha-37332'; +$wp_version = '4.6-alpha-37333'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.