wp/wp-includes/class-wp-widget-factory.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
--- a/wp/wp-includes/class-wp-widget-factory.php	Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-includes/class-wp-widget-factory.php	Tue Dec 15 13:49:49 2020 +0100
@@ -36,55 +36,16 @@
 	 * PHP4 constructor.
 	 *
 	 * @since 2.8.0
+	 * @deprecated 4.3.0 Use __construct() instead.
+	 *
+	 * @see WP_Widget_Factory::__construct()
 	 */
 	public function WP_Widget_Factory() {
-		_deprecated_constructor( 'WP_Widget_Factory', '4.2.0' );
+		_deprecated_constructor( 'WP_Widget_Factory', '4.3.0' );
 		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
-	 * @var array
-	 *
-	 * @see WP_Widget_Factory::hash_object()
-	 */
-	private $hashed_class_counts = array();
-
-	/**
-	 * Hashes 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
-	 *
-	 * @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.
 	 *
 	 * @since 2.8.0
@@ -95,7 +56,7 @@
 	 */
 	public function register( $widget ) {
 		if ( $widget instanceof WP_Widget ) {
-			$this->widgets[ $this->hash_object( $widget ) ] = $widget;
+			$this->widgets[ spl_object_hash( $widget ) ] = $widget;
 		} else {
 			$this->widgets[ $widget ] = new $widget();
 		}
@@ -112,7 +73,7 @@
 	 */
 	public function unregister( $widget ) {
 		if ( $widget instanceof WP_Widget ) {
-			unset( $this->widgets[ $this->hash_object( $widget ) ] );
+			unset( $this->widgets[ spl_object_hash( $widget ) ] );
 		} else {
 			unset( $this->widgets[ $widget ] );
 		}
@@ -132,7 +93,7 @@
 		$registered = array_map( '_get_widget_id_base', $registered );
 
 		foreach ( $keys as $key ) {
-			// don't register new widget if old widget with the same id is already registered
+			// Don't register new widget if old widget with the same id is already registered.
 			if ( in_array( $this->widgets[ $key ]->id_base, $registered, true ) ) {
 				unset( $this->widgets[ $key ] );
 				continue;