Version Description
- September 2018
- Remove query variables from URLs to prevent URLs from being flushed more than once per update
- More selective loading of AMP urls
Download this release
Release Info
Developer | Ipstenu |
Plugin | Varnish HTTP Purge |
Version | 4.6.4 |
Comparing to | |
See all releases |
Code changes from version 4.6.3 to 4.6.4
- changelog.txt +2 -2
- readme.txt +7 -1
- settings.php +41 -1
- varnish-http-purge.php +65 -39
changelog.txt
CHANGED
@@ -6,7 +6,7 @@
|
|
6 |
* Add carrot icon to collapsed (mobile) toolbar
|
7 |
* Better button hiding
|
8 |
* Fixed a stupid argument issue with flushing memcached and I should have known better but oh well
|
9 |
-
* FAQ update re nginx
|
10 |
|
11 |
=== 4.5.0 ===
|
12 |
* May 2018
|
@@ -187,4 +187,4 @@
|
|
187 |
|
188 |
=== 1.2.0 ===
|
189 |
* Moved actual request execution to "shutdown" event
|
190 |
-
* Removed GET request due to bad performance impact
|
6 |
* Add carrot icon to collapsed (mobile) toolbar
|
7 |
* Better button hiding
|
8 |
* Fixed a stupid argument issue with flushing memcached and I should have known better but oh well
|
9 |
+
* FAQ update re nginx
|
10 |
|
11 |
=== 4.5.0 ===
|
12 |
* May 2018
|
187 |
|
188 |
=== 1.2.0 ===
|
189 |
* Moved actual request execution to "shutdown" event
|
190 |
+
* Removed GET request due to bad performance impact
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: Ipstenu, mikeschroder, techpriester, danielbachhuber
|
|
3 |
Tags: varnish, purge, cache
|
4 |
Requires at least: 4.7
|
5 |
Tested up to: 4.9
|
6 |
-
Stable tag: 4.6.
|
7 |
Requires PHP: 5.6
|
8 |
|
9 |
Automatically empty Varnish Cache when content on your site is modified.
|
@@ -188,6 +188,12 @@ This plugin is installed by default for _all_ DreamPress installs on DreamHost,
|
|
188 |
|
189 |
== Changelog ==
|
190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
= 4.6.3 =
|
192 |
|
193 |
* August 2018
|
3 |
Tags: varnish, purge, cache
|
4 |
Requires at least: 4.7
|
5 |
Tested up to: 4.9
|
6 |
+
Stable tag: 4.6.4
|
7 |
Requires PHP: 5.6
|
8 |
|
9 |
Automatically empty Varnish Cache when content on your site is modified.
|
188 |
|
189 |
== Changelog ==
|
190 |
|
191 |
+
= 4.6.4 =
|
192 |
+
|
193 |
+
* September 2018
|
194 |
+
* Remove query variables from URLs to prevent URLs from being flushed more than once per update
|
195 |
+
* More selective loading of AMP urls
|
196 |
+
|
197 |
= 4.6.3 =
|
198 |
|
199 |
* August 2018
|
settings.php
CHANGED
@@ -37,6 +37,7 @@ class VarnishStatus {
|
|
37 |
public function __construct() {
|
38 |
add_action( 'admin_init', array( &$this, 'admin_init' ) );
|
39 |
add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
|
|
|
40 |
}
|
41 |
|
42 |
/**
|
@@ -239,7 +240,7 @@ class VarnishStatus {
|
|
239 |
<p>
|
240 |
<?php
|
241 |
// translators: %s is a link to the readme for the detection service.
|
242 |
-
printf( wp_kses_post( __( '<strong>This check uses <a href="%s">a remote service hosted on DreamObjects</a></strong>. The service used only for providing up to date compatibility checks on plugins and themes that may conflict with running a server based cache (such as Varnish or Nginx). No personally identifying information regarding persons running this check, nor the plugins and themes in use on this site will be transmitted. The bare minimum of usage information is collected, concerning only IPs and domains making requests of the service. If you do not wish to use this service, please do not use this
|
243 |
?>
|
244 |
</p>
|
245 |
<?php
|
@@ -467,6 +468,45 @@ class VarnishStatus {
|
|
467 |
<?php
|
468 |
}
|
469 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
470 |
}
|
471 |
|
472 |
$status = new VarnishStatus();
|
37 |
public function __construct() {
|
38 |
add_action( 'admin_init', array( &$this, 'admin_init' ) );
|
39 |
add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
|
40 |
+
add_filter( 'admin_footer_text', array( &$this, 'admin_footer' ), 1, 2 );
|
41 |
}
|
42 |
|
43 |
/**
|
240 |
<p>
|
241 |
<?php
|
242 |
// translators: %s is a link to the readme for the detection service.
|
243 |
+
printf( wp_kses_post( __( '<strong>This check uses <a href="%s">a remote service hosted on DreamObjects</a></strong>. The service used only for providing up to date compatibility checks on plugins and themes that may conflict with running a server based cache (such as Varnish or Nginx). No personally identifying information regarding persons running this check, nor the plugins and themes in use on this site will be transmitted. The bare minimum of usage information is collected, concerning only IPs and domains making requests of the service. If you do not wish to use this service, please do not use this feature.', 'varnish-http-purge' ) ), 'https://varnish-http-purge.objects-us-east-1.dream.io/readme.txt' );
|
244 |
?>
|
245 |
</p>
|
246 |
<?php
|
468 |
<?php
|
469 |
}
|
470 |
|
471 |
+
/**
|
472 |
+
* When user is on one of our admin pages, display footer text
|
473 |
+
* that graciously asks them to rate us.
|
474 |
+
*
|
475 |
+
* @since 4.6.4
|
476 |
+
*
|
477 |
+
* @param string $text
|
478 |
+
*
|
479 |
+
* @return string
|
480 |
+
*/
|
481 |
+
public function admin_footer( $text ) {
|
482 |
+
|
483 |
+
global $current_screen;
|
484 |
+
|
485 |
+
if ( ! empty( $current_screen->parent_base ) && strpos( $current_screen->parent_base, 'varnish-page' ) !== false ) {
|
486 |
+
$review_url = 'https://wordpress.org/support/plugin/varnish-http-purge/reviews/?filter=5#new-post';
|
487 |
+
$dream_url = 'https://dreamhost.com/dreampress/';
|
488 |
+
$footer_text = sprintf(
|
489 |
+
wp_kses(
|
490 |
+
/* translators: $1$s - DreamHost URL; $2$s - plugin name; $3$s - WP.org review link; $4$s - WP.org review link. */
|
491 |
+
__( 'Brought to you <a href="%1$s" target="_blank" rel="noopener noreferrer">DreamHost</a>. Please rate %2$s <a href="%3$s" target="_blank" rel="noopener noreferrer">★★★★★</a> on <a href="%4$s" target="_blank" rel="noopener">WordPress.org</a> to help us spread the word.', 'varnish-http-purge' ),
|
492 |
+
array(
|
493 |
+
'a' => array(
|
494 |
+
'href' => array(),
|
495 |
+
'target' => array(),
|
496 |
+
'rel' => array(),
|
497 |
+
),
|
498 |
+
)
|
499 |
+
),
|
500 |
+
$dream_url,
|
501 |
+
'<strong>Varnish HTTP Purge</strong>',
|
502 |
+
$review_url,
|
503 |
+
$review_url
|
504 |
+
);
|
505 |
+
}
|
506 |
+
|
507 |
+
return $footer_text;
|
508 |
+
}
|
509 |
+
|
510 |
}
|
511 |
|
512 |
$status = new VarnishStatus();
|
varnish-http-purge.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Varnish HTTP Purge
|
4 |
* Plugin URI: https://halfelf.org/plugins/varnish-http-purge/
|
5 |
* Description: Automatically empty cached pages when content on your site is modified.
|
6 |
-
* Version: 4.6.
|
7 |
* Author: Mika Epstein
|
8 |
* Author URI: https://halfelf.org/
|
9 |
* License: http://www.apache.org/licenses/LICENSE-2.0
|
@@ -31,6 +31,12 @@
|
|
31 |
*/
|
32 |
class VarnishPurger {
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
/**
|
35 |
* List of URLs to be purged
|
36 |
*
|
@@ -274,7 +280,7 @@ class VarnishPurger {
|
|
274 |
*/
|
275 |
public function custom_css() {
|
276 |
if ( is_user_logged_in() ) {
|
277 |
-
wp_register_style( 'varnish_http_purge', plugins_url( 'style.css', __FILE__ ), false,
|
278 |
wp_enqueue_style( 'varnish_http_purge' );
|
279 |
}
|
280 |
}
|
@@ -435,7 +441,11 @@ class VarnishPurger {
|
|
435 |
} else {
|
436 |
$text = $intro . ' ' . $nobutton;
|
437 |
}
|
438 |
-
|
|
|
|
|
|
|
|
|
439 |
}
|
440 |
|
441 |
/**
|
@@ -692,9 +702,11 @@ class VarnishPurger {
|
|
692 |
/**
|
693 |
* Determine the route for the rest API
|
694 |
* This will need to be revisted if WP updates the version.
|
695 |
-
* Future me: Consider an array? 4.7
|
696 |
*/
|
697 |
-
|
|
|
|
|
698 |
|
699 |
// array to collect all our URLs.
|
700 |
$listofurls = array();
|
@@ -710,27 +722,33 @@ class VarnishPurger {
|
|
710 |
* We only want to do this if the rest_base exists
|
711 |
* But we apparently have to force it for posts and pages (seriously?)
|
712 |
*/
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
|
|
|
|
721 |
}
|
722 |
|
723 |
if ( $rest_permalink ) {
|
724 |
array_push( $listofurls, $rest_permalink );
|
725 |
}
|
726 |
|
727 |
-
// Add in AMP permalink
|
|
|
728 |
if ( function_exists( 'amp_get_permalink' ) ) {
|
729 |
array_push( $listofurls, amp_get_permalink( $post_id ) );
|
730 |
}
|
731 |
|
732 |
-
// Regular AMP url for posts
|
733 |
-
|
|
|
|
|
|
|
734 |
|
735 |
// Also clean URL for trashed post.
|
736 |
if ( 'trash' === $this_post_status ) {
|
@@ -743,16 +761,13 @@ class VarnishPurger {
|
|
743 |
$categories = get_the_category( $post_id );
|
744 |
if ( $categories ) {
|
745 |
foreach ( $categories as $cat ) {
|
746 |
-
$category_base = get_site_option( 'category_base' );
|
747 |
-
if ( '' === $category_base ) {
|
748 |
-
$category_base = '/category/';
|
749 |
-
}
|
750 |
array_push( $listofurls,
|
751 |
get_category_link( $cat->term_id ),
|
752 |
get_rest_url() . $rest_api_route . '/categories/' . $cat->term_id . '/'
|
753 |
);
|
754 |
}
|
755 |
}
|
|
|
756 |
// Tag purge based on Donnacha's work in WP Super Cache.
|
757 |
$tags = get_the_tags( $post_id );
|
758 |
if ( $tags ) {
|
@@ -784,13 +799,27 @@ class VarnishPurger {
|
|
784 |
}
|
785 |
}
|
786 |
|
787 |
-
//
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
794 |
|
795 |
// Archives and their feeds.
|
796 |
if ( $this_post_type && ! in_array( $this_post_type, $noarchive_post_type, true ) ) {
|
@@ -801,16 +830,6 @@ class VarnishPurger {
|
|
801 |
);
|
802 |
}
|
803 |
|
804 |
-
// More feeds.
|
805 |
-
array_push( $listofurls,
|
806 |
-
get_bloginfo_rss( 'rdf_url' ),
|
807 |
-
get_bloginfo_rss( 'rss_url' ),
|
808 |
-
get_bloginfo_rss( 'rss2_url' ),
|
809 |
-
get_bloginfo_rss( 'atom_url' ),
|
810 |
-
get_bloginfo_rss( 'comments_rss2_url' ),
|
811 |
-
get_post_comments_feed_link( $post_id )
|
812 |
-
);
|
813 |
-
|
814 |
// Home Pages and (if used) posts page.
|
815 |
array_push( $listofurls,
|
816 |
get_rest_url(),
|
@@ -827,10 +846,17 @@ class VarnishPurger {
|
|
827 |
return;
|
828 |
}
|
829 |
|
830 |
-
//
|
831 |
-
// And make sure each URL only gets purged once, eh?
|
832 |
if ( ! empty( $listofurls ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
833 |
$purgeurls = array_unique( $listofurls, SORT_REGULAR );
|
|
|
|
|
834 |
foreach ( $purgeurls as $url ) {
|
835 |
array_push( $this->purge_urls, $url );
|
836 |
}
|
3 |
* Plugin Name: Varnish HTTP Purge
|
4 |
* Plugin URI: https://halfelf.org/plugins/varnish-http-purge/
|
5 |
* Description: Automatically empty cached pages when content on your site is modified.
|
6 |
+
* Version: 4.6.4
|
7 |
* Author: Mika Epstein
|
8 |
* Author URI: https://halfelf.org/
|
9 |
* License: http://www.apache.org/licenses/LICENSE-2.0
|
31 |
*/
|
32 |
class VarnishPurger {
|
33 |
|
34 |
+
/**
|
35 |
+
* Version Number
|
36 |
+
* @var string
|
37 |
+
*/
|
38 |
+
public static $version = '4.6.4';
|
39 |
+
|
40 |
/**
|
41 |
* List of URLs to be purged
|
42 |
*
|
280 |
*/
|
281 |
public function custom_css() {
|
282 |
if ( is_user_logged_in() ) {
|
283 |
+
wp_register_style( 'varnish_http_purge', plugins_url( 'style.css', __FILE__ ), false, self::$version );
|
284 |
wp_enqueue_style( 'varnish_http_purge' );
|
285 |
}
|
286 |
}
|
441 |
} else {
|
442 |
$text = $intro . ' ' . $nobutton;
|
443 |
}
|
444 |
+
// @codingStandardsIgnoreStart
|
445 |
+
// This is safe to echo as it's controlled and secured above.
|
446 |
+
// Using wp_kses will delete the icon.
|
447 |
+
echo '<p class="varnish-rightnow">' . $text . '</p>';
|
448 |
+
// @codingStandardsIgnoreEnd
|
449 |
}
|
450 |
|
451 |
/**
|
702 |
/**
|
703 |
* Determine the route for the rest API
|
704 |
* This will need to be revisted if WP updates the version.
|
705 |
+
* Future me: Consider an array? 4.7-?? use v2, and then adapt from there?
|
706 |
*/
|
707 |
+
if ( version_compare( get_bloginfo( 'version' ), '4.7', '>=' ) ) {
|
708 |
+
$rest_api_route = 'wp/v2';
|
709 |
+
}
|
710 |
|
711 |
// array to collect all our URLs.
|
712 |
$listofurls = array();
|
722 |
* We only want to do this if the rest_base exists
|
723 |
* But we apparently have to force it for posts and pages (seriously?)
|
724 |
*/
|
725 |
+
if ( isset( $rest_api_route ) ) {
|
726 |
+
$post_type_object = get_post_type_object( $post_id );
|
727 |
+
$rest_permalink = false;
|
728 |
+
if ( isset( $post_type_object->rest_base ) ) {
|
729 |
+
$rest_permalink = get_rest_url() . $rest_api_route . '/' . $post_type_object->rest_base . '/' . $post_id . '/';
|
730 |
+
} elseif ( 'post' === $this_post_type ) {
|
731 |
+
$rest_permalink = get_rest_url() . $rest_api_route . '/posts/' . $post_id . '/';
|
732 |
+
} elseif ( 'page' === $this_post_type ) {
|
733 |
+
$rest_permalink = get_rest_url() . $rest_api_route . '/pages/' . $post_id . '/';
|
734 |
+
}
|
735 |
}
|
736 |
|
737 |
if ( $rest_permalink ) {
|
738 |
array_push( $listofurls, $rest_permalink );
|
739 |
}
|
740 |
|
741 |
+
// Add in AMP permalink for offical WP AMP plugin:
|
742 |
+
// https://wordpress.org/plugins/amp/
|
743 |
if ( function_exists( 'amp_get_permalink' ) ) {
|
744 |
array_push( $listofurls, amp_get_permalink( $post_id ) );
|
745 |
}
|
746 |
|
747 |
+
// Regular AMP url for posts if ant of the following are active:
|
748 |
+
// https://wordpress.org/plugins/accelerated-mobile-pages/
|
749 |
+
if ( defined( 'AMPFORWP_AMP_QUERY_VAR' ) ) {
|
750 |
+
array_push( $listofurls, get_permalink( $post_id ) . 'amp/' );
|
751 |
+
}
|
752 |
|
753 |
// Also clean URL for trashed post.
|
754 |
if ( 'trash' === $this_post_status ) {
|
761 |
$categories = get_the_category( $post_id );
|
762 |
if ( $categories ) {
|
763 |
foreach ( $categories as $cat ) {
|
|
|
|
|
|
|
|
|
764 |
array_push( $listofurls,
|
765 |
get_category_link( $cat->term_id ),
|
766 |
get_rest_url() . $rest_api_route . '/categories/' . $cat->term_id . '/'
|
767 |
);
|
768 |
}
|
769 |
}
|
770 |
+
|
771 |
// Tag purge based on Donnacha's work in WP Super Cache.
|
772 |
$tags = get_the_tags( $post_id );
|
773 |
if ( $tags ) {
|
799 |
}
|
800 |
}
|
801 |
|
802 |
+
// If the post is a post, we have more things to flush
|
803 |
+
// Pages and Woo Things don't need all this.
|
804 |
+
if ( $this_post_type && 'post' === $this_post_type ) {
|
805 |
+
// Author URLs:
|
806 |
+
$author_id = get_post_field( 'post_author', $post_id );
|
807 |
+
array_push( $listofurls,
|
808 |
+
get_author_posts_url( $author_id ),
|
809 |
+
get_author_feed_link( $author_id ),
|
810 |
+
get_rest_url() . $rest_api_route . '/users/' . $author_id . '/'
|
811 |
+
);
|
812 |
+
|
813 |
+
// Feeds:
|
814 |
+
array_push( $listofurls,
|
815 |
+
get_bloginfo_rss( 'rdf_url' ),
|
816 |
+
get_bloginfo_rss( 'rss_url' ),
|
817 |
+
get_bloginfo_rss( 'rss2_url' ),
|
818 |
+
get_bloginfo_rss( 'atom_url' ),
|
819 |
+
get_bloginfo_rss( 'comments_rss2_url' ),
|
820 |
+
get_post_comments_feed_link( $post_id )
|
821 |
+
);
|
822 |
+
}
|
823 |
|
824 |
// Archives and their feeds.
|
825 |
if ( $this_post_type && ! in_array( $this_post_type, $noarchive_post_type, true ) ) {
|
830 |
);
|
831 |
}
|
832 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
833 |
// Home Pages and (if used) posts page.
|
834 |
array_push( $listofurls,
|
835 |
get_rest_url(),
|
846 |
return;
|
847 |
}
|
848 |
|
849 |
+
// If the array isn't empty, proceed.
|
|
|
850 |
if ( ! empty( $listofurls ) ) {
|
851 |
+
// Strip off query variables
|
852 |
+
foreach ( $listofurls as $url ) {
|
853 |
+
$url = strtok( $url, '?' );
|
854 |
+
}
|
855 |
+
|
856 |
+
// Make sure each URL only gets purged once, eh?
|
857 |
$purgeurls = array_unique( $listofurls, SORT_REGULAR );
|
858 |
+
|
859 |
+
// Flush all the URLs
|
860 |
foreach ( $purgeurls as $url ) {
|
861 |
array_push( $this->purge_urls, $url );
|
862 |
}
|