generator-chisel icon indicating copy to clipboard operation
generator-chisel copied to clipboard

Fix filter for removing the version number

Open marcinkrzeminski opened this issue 6 years ago • 6 comments

Hey,

After adding a Google Font using

add_action( 'wp_enqueue_scripts', function () {
			wp_enqueue_style( 'google-fonts',
				'https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,300i,400,400i,600,600i,700,700i' );
		} );

I have noticed that the security function that should remove the ver query string is not working. After some changes I came up with a simpler function which seems to work in my case:

public function removeSrcVersion( $src ) {
		if (strpos($src, 'ver=')) {
			$src = remove_query_arg('ver', $src);
		}
		return $src;
	}

Let me know if we could replace our current solution with the one above.

marcinkrzeminski avatar Jun 11 '18 13:06 marcinkrzeminski

@marcinkrzeminski I believe you can even go a step further and skip the conditional part ;) So just remove_query_arg without checking if arg exists should be enough.

JakubSzajna avatar Jun 11 '18 13:06 JakubSzajna

yeah, this seems to work as well:

public function removeSrcVersion( $src ) {
    return remove_query_arg('ver', $src);
}

You think it's OK to replace what we have with this one?

marcinkrzeminski avatar Jun 11 '18 13:06 marcinkrzeminski

Looks good. I'd consider renaming this method to something like removeVersionFromQuery($query), but if you think yours is better, than I'm ok with that :)

JakubSzajna avatar Jun 11 '18 15:06 JakubSzajna

@marcinkrzeminski thanks for the report. Would you mind submitting a PR for this? Thanks

luboskmetko avatar Jun 12 '18 06:06 luboskmetko

Yeah, I'll send a PR soon ;).

marcinkrzeminski avatar Jun 12 '18 10:06 marcinkrzeminski

Hey, I need more time to do this because I'm a bit busy lately + short vacation ahead.

marcinkrzeminski avatar Jun 24 '18 13:06 marcinkrzeminski