Per request: path => version. */ private static $cache = []; /** * @param string $relPath Path relative to the plugin folder, e.g. "assets/js/registry.js". * @return string 20 hex chars of the content's MD5; the plugin version when the file cannot be read. */ public static function of( string $relPath ): string { $path = FEEDNETIC_DIR . ltrim( $relPath, '/' ); if ( ! isset( self::$cache[ $path ] ) ) { $hash = is_readable( $path ) ? md5_file( $path ) : false; self::$cache[ $path ] = false !== $hash ? substr( $hash, 0, 20 ) : FEEDNETIC_VERSION; } return self::$cache[ $path ]; } /** * The file's URL with its version, for places that load a URL directly * (the editor preview iframe) instead of through wp_enqueue_*. * * @param string $relPath Path relative to the plugin folder. */ public static function url( string $relPath ): string { return add_query_arg( 'ver', self::of( $relPath ), FEEDNETIC_URL . ltrim( $relPath, '/' ) ); } }