rtCamp / nginx-helper

Nginx Helper for WordPress caching, permalinks & efficient file handling in multisite
https://wordpress.org/plugins/nginx-helper/
229 stars 121 forks source link

new filter to give to the user more information about purge object #208

Closed mesaque closed 3 years ago

mesaque commented 5 years ago

Hi Guys!

First of all i would like to say thx because you all are doing an amazing job here!

i have a lot of urls with a different behavior/style based on its query strings; example:

http://example.com/some-nice-news/ http://example.com/some-nice-news/?amp <- this is an amp version of the news

i have to make cache of this link too (?amp) so i have added some filter at the end of the function _purge_by_options to accomplish this because i dont have this power at any moment in the code like having the purge object at my hand to add some logic to purge some things based on this information.

and i have made some small change on function purge_url to not ignore my query string if it exist.

chandrapatel commented 4 years ago

Hi @mesaque My apologies for late response and thanks for sending PR.

In version 2.1.0, we have added many actions and filters. I think you can use rt_nginx_helper_purge_url filter to add * at the end of the URL which will perform whildcard purge.

Please check following link for an example. https://github.com/rtCamp/nginx-helper/blob/master/admin/class-phpredis-purger.php#L124-L140

You can filter URL to http://example.com/some-nice-news/* which purge the amp page cache as well.

add_filter( 'rt_nginx_helper_purge_url', function( $url ) {
    $url = $url . '*';
    return $url;
} );

Please check above filter and let me know if its helpful for you.

Thanks,

chandrapatel commented 3 years ago

@mesaque Please check if the solution I gave in previous comment is working for you or not. This PR having conflicts so I'm closing this PR. Please feel free to open new PR if that solution not working for you.