wp/wp-includes/class-wp-widget-factory.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    69 	private function hash_object( $widget ) {
    69 	private function hash_object( $widget ) {
    70 		if ( function_exists( 'spl_object_hash' ) ) {
    70 		if ( function_exists( 'spl_object_hash' ) ) {
    71 			return spl_object_hash( $widget );
    71 			return spl_object_hash( $widget );
    72 		} else {
    72 		} else {
    73 			$class_name = get_class( $widget );
    73 			$class_name = get_class( $widget );
    74 			$hash = $class_name;
    74 			$hash       = $class_name;
    75 			if ( ! isset( $widget->_wp_widget_factory_hash_id ) ) {
    75 			if ( ! isset( $widget->_wp_widget_factory_hash_id ) ) {
    76 				if ( ! isset( $this->hashed_class_counts[ $class_name ] ) ) {
    76 				if ( ! isset( $this->hashed_class_counts[ $class_name ] ) ) {
    77 					$this->hashed_class_counts[ $class_name ] = 0;
    77 					$this->hashed_class_counts[ $class_name ] = 0;
    78 				}
    78 				}
    79 				$this->hashed_class_counts[ $class_name ] += 1;
    79 				$this->hashed_class_counts[ $class_name ] += 1;
    80 				$widget->_wp_widget_factory_hash_id = $this->hashed_class_counts[ $class_name ];
    80 				$widget->_wp_widget_factory_hash_id        = $this->hashed_class_counts[ $class_name ];
    81 			}
    81 			}
    82 			$hash .= ':' . $widget->_wp_widget_factory_hash_id;
    82 			$hash .= ':' . $widget->_wp_widget_factory_hash_id;
    83 			return $hash;
    83 			return $hash;
    84 		}
    84 		}
    85 	}
    85 	}
   125 	 *
   125 	 *
   126 	 * @global array $wp_registered_widgets
   126 	 * @global array $wp_registered_widgets
   127 	 */
   127 	 */
   128 	public function _register_widgets() {
   128 	public function _register_widgets() {
   129 		global $wp_registered_widgets;
   129 		global $wp_registered_widgets;
   130 		$keys = array_keys($this->widgets);
   130 		$keys       = array_keys( $this->widgets );
   131 		$registered = array_keys($wp_registered_widgets);
   131 		$registered = array_keys( $wp_registered_widgets );
   132 		$registered = array_map('_get_widget_id_base', $registered);
   132 		$registered = array_map( '_get_widget_id_base', $registered );
   133 
   133 
   134 		foreach ( $keys as $key ) {
   134 		foreach ( $keys as $key ) {
   135 			// don't register new widget if old widget with the same id is already registered
   135 			// don't register new widget if old widget with the same id is already registered
   136 			if ( in_array($this->widgets[$key]->id_base, $registered, true) ) {
   136 			if ( in_array( $this->widgets[ $key ]->id_base, $registered, true ) ) {
   137 				unset($this->widgets[$key]);
   137 				unset( $this->widgets[ $key ] );
   138 				continue;
   138 				continue;
   139 			}
   139 			}
   140 
   140 
   141 			$this->widgets[$key]->_register();
   141 			$this->widgets[ $key ]->_register();
   142 		}
   142 		}
   143 	}
   143 	}
   144 }
   144 }