Widgets: Provide PHP 5.2 fallback for `spl_object_hash()` if disabled in logic for registering and unregistering pre-instantiated widgets.
Fixes #28216. Built from https://develop.svn.wordpress.org/trunk@37333 git-svn-id: http://core.svn.wordpress.org/trunk@37299 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
4b51bc18cc
commit
6693acdb24
|
@ -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 ] );
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue