diff --git a/functions.php b/functions.php index 1d8f4a8..cc9e131 100644 --- a/functions.php +++ b/functions.php @@ -137,7 +137,7 @@ function radiate_widgets_init() { /** * Assign the Radiate version to a variable. */ -$radiate_theme = wp_get_theme( 'radiate' ); +$radiate_theme = wp_get_theme( get_template() ); define( 'RADIATE_THEME_VERSION', $radiate_theme->get( 'Version' ) ); @@ -146,7 +146,7 @@ function radiate_widgets_init() { */ function radiate_scripts() { // Load our main stylesheet. - wp_enqueue_style( 'radiate-style', get_stylesheet_uri() ); + wp_enqueue_style( 'radiate-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) ); wp_enqueue_style( 'radiate-google-fonts', '//fonts.googleapis.com/css?family=Roboto|Merriweather:400,300&display=swap' ); @@ -157,7 +157,7 @@ function radiate_scripts() { wp_enqueue_script( 'radiate-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true ); - wp_enqueue_script( 'radiate-custom-js', get_template_directory_uri() . '/js/custom.js', array( 'jquery' ), false, true ); + wp_enqueue_script( 'radiate-custom-js', get_template_directory_uri() . '/js/custom.js', array( 'jquery' ), RADIATE_THEME_VERSION, true ); $radiate_header_image_link = get_header_image(); wp_localize_script( 'radiate-custom-js', 'radiateScriptParam', array( 'radiate_image_link' => $radiate_header_image_link ) ); diff --git a/tests/e2e/specs/homepage/asset-versions.spec.ts b/tests/e2e/specs/homepage/asset-versions.spec.ts new file mode 100644 index 0000000..5f1d228 --- /dev/null +++ b/tests/e2e/specs/homepage/asset-versions.spec.ts @@ -0,0 +1,35 @@ +import { test, expect } from "../../fixtures"; +/** + * @area homepage + * @tier fresh + * @guards radiate-pro#33 + * @source fix/33-asset-versions 2026-09-30; functions.php + * @why The main stylesheet and custom.js were enqueued without a version, so + * WordPress stamped them with the WP core version and a theme update + * shipping new CSS/JS kept the old ?ver= (browsers and CDNs served stale + * files). Guards that they carry the theme's own Version header. Reads the + * Version from the theme's style.css, so it does not go stale on a release. + */ +test("the theme's own stylesheet and script are versioned with the theme version @fresh @homepage", async ({ + page, + request, +}) => { + await page.goto("/"); + + const styleHref = await page + .locator("link#radiate-style-css") + .getAttribute("href"); + const scriptSrc = await page + .locator("script#radiate-custom-js-js") + .getAttribute("src"); + expect(styleHref, "radiate-style-css href").toBeTruthy(); + expect(scriptSrc, "radiate-custom-js src").toBeTruthy(); + + const css = await (await request.get(styleHref!.split("?")[0])).text(); + const themeVersion = css.match(/^\s*Version:\s*(\S+)/m)?.[1]; + expect(themeVersion, "Version header in style.css").toBeTruthy(); + + const ver = (url: string) => new URL(url, "http://x").searchParams.get("ver"); + expect(ver(styleHref!)).toBe(themeVersion); + expect(ver(scriptSrc!)).toBe(themeVersion); +});