Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new filter to asset version #33

Merged
merged 4 commits into from
Feb 12, 2025
Merged

Add new filter to asset version #33

merged 4 commits into from
Feb 12, 2025

Conversation

JPry
Copy link
Contributor

@JPry JPry commented Feb 12, 2025

This PR adds a new filter: stellarwp/assets/{$hook_prefix}/version. This allows filtering the asset version string when it does not come from an asset file.

This is particularly useful in development when the asset file has changes but the $version value used when registering the asset hasn't changed. E.g. for an asset jpry-cool-asset, I could filter the version to something like time() in this way:

$prefix = 'jpry';

add_filter(
	"stellarwp/assets/{$prefix}/version",
	function ( $version, $slug ) {
		return 'jpry-cool-asset' === $slug
			? time()
			: $version;
	},
	10,
	2
);

@JPry JPry self-assigned this Feb 12, 2025
Copy link
Member

@borkweb borkweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great addition! We can remove the since line from the docblock for the library, though.

@JPry
Copy link
Contributor Author

JPry commented Feb 12, 2025

@borkweb Thanks! I removed the @since tag.

@JPry JPry merged commit 2ddd437 into main Feb 12, 2025
3 checks passed
@JPry JPry deleted the feature/add_version_filter branch February 12, 2025 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants