*/ private static $entries = array(); /** * The value built by `$build`, from the cache while the callbacks on `$tag` * are those it was built with. * * @param string $tag Filter the value is worked out through. * @param callable $build Builds the value; runs the filter itself. * @return mixed */ public static function get( $tag, $build ) { $tag = (string) $tag; $callbacks = self::callbacks( $tag ); if ( isset( self::$entries[ $tag ] ) && self::$entries[ $tag ]['callbacks'] === $callbacks ) { return self::$entries[ $tag ]['value']; } $value = call_user_func( $build ); self::$entries[ $tag ] = array( 'callbacks' => $callbacks, 'value' => $value, ); return $value; } /** * The callbacks on a filter, by priority, as WordPress holds them; empty * when there are none. * * @param string $tag Filter. * @return array */ public static function callbacks( $tag ) { global $wp_filter; return isset( $wp_filter[ $tag ] ) && $wp_filter[ $tag ] instanceof \WP_Hook ? $wp_filter[ $tag ]->callbacks : array(); } /** * Forgets every value, so the next read builds it again. * * @return void */ public static function flush() { self::$entries = array(); } }