diff --git a/.github/workflows/version-update.yml b/.github/workflows/version-update.yml
deleted file mode 100644
index 99b5232..0000000
--- a/.github/workflows/version-update.yml
+++ /dev/null
@@ -1,47 +0,0 @@
-name: Update Version on Merge to Main
-
-on:
- push:
- branches:
- - main
-
-jobs:
- update-version:
- runs-on: ubuntu-latest
-
- steps:
- - name: Checkout code
- uses: actions/checkout@v3
-
- - name: Set up Node.js
- uses: actions/setup-node@v3
- with:
- node-version: '20'
-
- - name: Install dependencies
- run: npm install
-
- - name: Run version update script
- run: node updateVersion.js
-
- - name: Configure Git author
- run: |
- git config user.name "github-actions[bot]"
- git config user.email "github-actions[bot]@users.noreply.github.com"
-
- - name: Create a new branch for the version update
- run: |
- BRANCH_NAME="version-update-$(date +%s)"
- git checkout -b $BRANCH_NAME
- git add .env style.css package.json composer.json
- git commit -m "Automated version update after merge to main"
- git push origin $BRANCH_NAME
-
- - name: Create a Pull Request
- uses: peter-evans/create-pull-request@v5
- with:
- token: ${{ secrets.GITHUB_TOKEN }}
- branch: version-update-${{ steps.update-version.outputs.BRANCH_NAME }}
- title: "Automated Version Update"
- body: "This pull request contains the automated version and build updates."
- base: main
diff --git a/README.md b/README.md
index d34925b..e7e877b 100644
--- a/README.md
+++ b/README.md
@@ -542,76 +542,15 @@ WDS BT is equipped with automated workflow actions that ensure code security and
## Automated Versioning Process
-This theme uses an automated versioning system that increments the `BUILD` number automatically upon merges to the `main` branch. The `VERSION` is manually controlled and is reflected in the `composer.json` and `package.json` files. The `BUILD` number is automatically appended to the `VERSION` in `style.css`.
+To handle cache busting for CSS and JS files, this theme automatically appends the file modification time as a version parameter to the URLs of enqueued styles and scripts, ensuring that browsers fetch the most recent version whenever the files are updated.
-
- How It Works
-
- 1. **VERSION**: Manually set in the `.env` file. This is reflected in the `composer.json` and `package.json` files.
- - Format: `X.Y.Z` (Semantic Versioning)
- - This value is manually updated by the developer.
-
- 2. **BUILD**: Automatically increments on merges to the `main` branch. This is appended to the `VERSION` in the `style.css` file.
- - Format: `1.0.0x` where `x` is the build number.
-
-
-
-
- Example
-
- Suppose the `.env` file has the following values:
-
- ```plaintext
- VERSION=1.0.0
- BUILD=4
- ```
-
- After merging a PR into the `main` branch:
-
- - The `BUILD` increments to `5`.
- - The version in `style.css` becomes `Version: 1.0.005`.
- - The `composer.json` and `package.json` will still reflect `1.0.0`.
-
-
-
-
- Modifying the Version
-
- - To update the `VERSION`, manually edit the `.env` file:
- ```plaintext
- VERSION=1.1.0
- BUILD=0
- ```
- - The `BUILD` should not be manually modified except for specific scenarios, such as resetting the build number after a major version change.
-
-
- Workflow
-
- When a PR is merged into the `main` branch, the following occurs automatically:
-
- 1. The `BUILD` number increments.
- 2. The `style.css` is updated to reflect the `VERSION + BUILD`.
- 3. The `composer.json` and `package.json` files are updated with only the `VERSION`.
- 4. The updated files are committed back to the `main` branch.
-
-
-
-
- Manual Execution
-
- You can manually trigger the versioning process locally if necessary by running:
-
- ```bash
- npm run update-version
- ```
-
- This will:
+ How It Works
- - Increment the `BUILD` number.
- - Update the version in `style.css`.
- - Ensure `composer.json` and `package.json` reflect the correct `VERSION`.
+ 1. Hooking into the `style_loader_src` and `script_loader_src` filters, which handle the URLs of enqueued styles and scripts.
+ 2. Using the `filemtime()` function to retrieve the last modified time of the `style.css` file, appending it as the version (`ver`) parameter in the asset URLs.
+ 3. This ensures that browsers always fetch the latest version of your CSS and JS files, preventing them from serving cached versions after updates.
diff --git a/inc/setup/scripts.php b/inc/setup/scripts.php
index 10f6124..a5538db 100644
--- a/inc/setup/scripts.php
+++ b/inc/setup/scripts.php
@@ -14,18 +14,19 @@
*/
function scripts() {
$asset_file_path = get_template_directory() . '/build/js/index.asset.php';
+ $asset_version = wp_get_theme()->get( 'Version' );
if ( is_readable( $asset_file_path ) ) {
$asset_file = include $asset_file_path;
} else {
- $asset_file = [
+ $asset_file = array(
'version' => '0.1.0',
- 'dependencies' => [ 'wp-polyfill' ],
- ];
+ 'dependencies' => array( 'wp-polyfill' ),
+ );
}
// Register styles & scripts.
- wp_enqueue_style( 'wdsbt-styles', get_stylesheet_directory_uri() . '/build/css/style.css', [], $asset_file['version'] );
- wp_enqueue_script( 'wdsbt-scripts', get_stylesheet_directory_uri() . '/build/js/index.js', $asset_file['dependencies'], $asset_file['version'], true );
+ wp_enqueue_style( 'wdsbt-styles', get_stylesheet_directory_uri() . '/build/css/style.css', array(), $asset_version );
+ wp_enqueue_script( 'wdsbt-scripts', get_stylesheet_directory_uri() . '/build/js/index.js', $asset_file['dependencies'], $asset_version, true );
}
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\scripts' );
diff --git a/inc/setup/style-script-version.php b/inc/setup/style-script-version.php
new file mode 100644
index 0000000..ebd39dc
--- /dev/null
+++ b/inc/setup/style-script-version.php
@@ -0,0 +1,42 @@
+