diff --git a/.gitignore b/.gitignore
index d2694b1a..bf979cac 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
.idea/
.phpunit.result.cache
css/*.min.css
+js/*.min.js
vendor/
node_modules/
composer.lock
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2b36210c..ca39bf2e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,10 +5,11 @@ All notable changes to this project will be documented in this file. This projec
Requires PHP 5.6 and WordPress 4.7 or above
+* Fix: invalidate cache when permalink changes (#285, #286, props raffaelj)
* Enhance: adjust styling for setup instructions (#215, props timse201)
* Enhance: update hooks for Multisite initialization in WordPress 5.1 and above (#246, props ouun)
* Enhance: rework flush hooks and add some third-party triggers for Autoptimize and WooCommerce (#225, props timse201)
-
+* Fix: correctly add user-agent to robots.txt (#282) (#283)
## 2.3.2
* Fix: enforce WordPress environment for caching modules (#221, props timse201)
diff --git a/css/dashboard.css b/css/dashboard.css
index 6b790189..aad8035a 100644
--- a/css/dashboard.css
+++ b/css/dashboard.css
@@ -5,6 +5,10 @@
fill: #606a73;
}
+html.dark-mode body:not(.block-editor-page) #dashboard_right_now .cachify-icon {
+ fill: #bbc8d4;
+}
+
#dashboard_right_now li a.cachify-glance::before {
content: "";
padding: 0;
diff --git a/inc/class-cachify.php b/inc/class-cachify.php
index 9166a60d..ba5fc792 100644
--- a/inc/class-cachify.php
+++ b/inc/class-cachify.php
@@ -93,7 +93,7 @@ public function __construct() {
/* Flush Hooks */
add_action( 'init', array( __CLASS__, 'register_flush_cache_hooks' ), 10, 0 );
- add_action( 'save_post', array( __CLASS__, 'save_update_trash_post' ) );
+ add_action( 'post_updated', array( __CLASS__, 'save_update_trash_post' ), 10, 3 );
add_action( 'pre_post_update', array( __CLASS__, 'post_update' ), 10, 2 );
add_action( 'cachify_remove_post_cache', array( __CLASS__, 'remove_page_cache_by_post_id' ) );
add_action( 'comment_post', array( __CLASS__, 'new_comment' ), 99, 2 );
@@ -156,8 +156,6 @@ public function __construct() {
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_dashboard_styles' ) );
- add_action( 'doing_dark_mode', array( __CLASS__, 'admin_dashboard_dark_mode_styles' ) );
-
add_filter( 'dashboard_glance_items', array( __CLASS__, 'add_dashboard_count' ) );
add_filter( 'plugin_row_meta', array( __CLASS__, 'row_meta' ), 10, 2 );
@@ -167,7 +165,7 @@ public function __construct() {
} else {
/* Frontend */
add_action( 'template_redirect', array( __CLASS__, 'manage_cache' ), 0 );
- add_action( 'do_robots', array( __CLASS__, 'robots_txt' ) );
+ add_filter( 'robots_txt', array( __CLASS__, 'robots_txt' ) );
}
}
@@ -435,15 +433,18 @@ private static function _get_options() {
/**
* Modify robots.txt
*
+ * @param string $output The robots.txt output.
+ *
* @since 1.0
* @since 2.1.9
- * @since 2.4.0 Removed $data parameter and return value.
*/
- public static function robots_txt() {
+ public static function robots_txt( $output ) {
/* HDD only */
if ( self::METHOD_HDD === self::$options['use_apc'] ) {
- echo 'Disallow: */cache/cachify/';
+ $output .= "\nUser-agent: *\nDisallow: */cache/cachify/\n";
}
+
+ return $output;
}
/**
@@ -1047,14 +1048,16 @@ public static function publish_post_types( $post_id, $post ) {
/**
* Removes the post type cache if saved or updated
*
- * @param int $id Post ID.
+ * @param int $id Post ID.
+ * @param WP_Post $post_after Post object following the update.
+ * @param WP_Post $post_before Post object before the update.
*
* @since 2.0.3
* @since 2.1.7 Make the function public.
- * @since 2.4.0 Renamed to save_update_trash_post with $id parameter.
+ * @since 2.4.0 Renamed to save_update_trash_post and introduced parameters.
*/
- public static function save_update_trash_post( $id ) {
- $status = get_post_status( $id );
+ public static function save_update_trash_post( $id, $post_after, $post_before ) {
+ $status = get_post_status( $post_before );
/* Post type published? */
if ( 'publish' === $status ) {
@@ -1644,6 +1647,8 @@ public static function admin_dashboard_styles() {
* Fixing some admin dashboard styles
*
* @since 2.3.0
+ *
+ * @deprecated included in dashboard.css since 2.4
*/
public static function admin_dashboard_dark_mode_styles() {
wp_add_inline_style( 'cachify-dashboard', '#dashboard_right_now .cachify-icon use { fill: #bbc8d4; }' );
diff --git a/js/admin-bar-flush.min.js b/js/admin-bar-flush.min.js
deleted file mode 100644
index 16d25798..00000000
--- a/js/admin-bar-flush.min.js
+++ /dev/null
@@ -1,6 +0,0 @@
-(function(){var is_flushing=!1,admin_bar_cachify_list_item=document.getElementById('wp-admin-bar-cachify'),flush_link=admin_bar_cachify_list_item.querySelector('a.ab-item'),fallback_url=flush_link.getAttribute('href'),aria_live_area=document.querySelector('.ab-aria-live-area');var button=document.createRange().createContextualFragment('');flush_link.parentNode.replaceChild(button,flush_link);var admin_bar_icon=admin_bar_cachify_list_item.querySelector('#wp-admin-bar-cachify .ab-icon');document.querySelector('#wp-admin-bar-cachify .ab-item').addEventListener('click',flush);admin_bar_icon.addEventListener('animationend',function(){admin_bar_icon.classList.remove('animate-fade')});function flush_icon_remove_classes(){var classes=['animate-fade','animate-pulse','dashicons-trash','dashicons-yes','dashicons-yes-alt','dashicons-dismiss',];for(var i=0;i Cachify::METHOD_DB ) );
+ new Cachify();
+
+ self::assertEquals(
+ $robots_txt,
+ Cachify::robots_txt( $robots_txt ),
+ 'robots.tst should not be modified using DB cache'
+ );
+
+ // HDD cache enabled.
+ update_option( 'cachify' , array( 'use_apc' => Cachify::METHOD_HDD ) );
+ new Cachify();
+
+ self::assertEquals(
+ $robots_txt . "\nUser-agent: *\nDisallow: */cache/cachify/\n",
+ Cachify::robots_txt( $robots_txt ),
+ 'robots.tst should have been modified using HDD cache'
+ );
+ }
}