Changeset 37333 for trunk/src/wp-includes/class-wp-widget-factory.php
- Timestamp:
- 04/30/2016 10:35:27 PM (10 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/class-wp-widget-factory.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-widget-factory.php
r37329 r37333 47 47 48 48 /** 49 * Memory for the number of times unique class instances have been hashed. 50 * 51 * This can be eliminated in favor of straight spl_object_hash() when 5.3 52 * is the minimum requirement for PHP. 53 * 54 * @since 4.6.0 55 * @access private 56 * @see WP_Widget_Factory::hash_object() 57 * 58 * @var array 59 */ 60 private $hashed_class_counts = array(); 61 62 /** 63 * Hash an object, doing fallback of `spl_object_hash()` if not available. 64 * 65 * This can be eliminated in favor of straight spl_object_hash() when 5.3 66 * is the minimum requirement for PHP. 67 * 68 * @since 4.6.0 69 * @access private 70 * 71 * @param WP_Widget $widget Widget. 72 * @return string Object hash. 73 */ 74 private function hash_object( $widget ) { 75 if ( function_exists( 'spl_object_hash' ) ) { 76 return spl_object_hash( $widget ); 77 } else { 78 $class_name = get_class( $widget ); 79 $hash = $class_name; 80 if ( ! isset( $widget->_wp_widget_factory_hash_id ) ) { 81 if ( ! isset( $this->hashed_class_counts[ $class_name ] ) ) { 82 $this->hashed_class_counts[ $class_name ] = 0; 83 } 84 $this->hashed_class_counts[ $class_name ] += 1; 85 $widget->_wp_widget_factory_hash_id = $this->hashed_class_counts[ $class_name ]; 86 } 87 $hash .= ':' . $widget->_wp_widget_factory_hash_id; 88 return $hash; 89 } 90 } 91 92 /** 49 93 * Registers a widget subclass. 50 94 * … … 57 101 public function register( $widget ) { 58 102 if ( $widget instanceof WP_Widget ) { 59 $this->widgets[ spl_object_hash( $widget ) ] = $widget;103 $this->widgets[ $this->hash_object( $widget ) ] = $widget; 60 104 } else { 61 105 $this->widgets[ $widget ] = new $widget(); … … 74 118 public function unregister( $widget ) { 75 119 if ( $widget instanceof WP_Widget ) { 76 unset( $this->widgets[ spl_object_hash( $widget ) ] );120 unset( $this->widgets[ $this->hash_object( $widget ) ] ); 77 121 } else { 78 122 unset( $this->widgets[ $widget ] );
Note: See TracChangeset
for help on using the changeset viewer.