From 78df528b13c2d7350695070c6062b2212332cfb9 Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Sun, 20 Nov 2022 11:25:42 +0100 Subject: [PATCH 1/5] move dark-mode styling into dashboard.css Dark mode styling has been added inline using the "doing_dark_mode" hook which is no longer called in current plugin versions. Include the CSS definition directly into dashboard.css and deprecate the hook for adding inline styles. --- css/dashboard.css | 4 ++++ inc/class-cachify.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) 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 748ad2f4..8863ff02 100644 --- a/inc/class-cachify.php +++ b/inc/class-cachify.php @@ -155,8 +155,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_action( 'transition_comment_status', array( __CLASS__, 'touch_comment' ), 10, 3 ); add_action( 'edit_comment', array( __CLASS__, 'edit_comment' ) ); @@ -1608,6 +1606,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; }' ); From 3d7190f2b0fe09c8f3fa331921f19641a710f0a5 Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Tue, 22 Nov 2022 16:55:19 +0100 Subject: [PATCH 2/5] remove minified js from sources --- .gitignore | 1 + js/admin-bar-flush.min.js | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 js/admin-bar-flush.min.js diff --git a/.gitignore b/.gitignore index f5833602..47f959ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .idea/ css/*.min.css +js/*.min.js vendor/ node_modules/ composer.lock 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 Date: Fri, 14 Apr 2023 18:19:39 +0200 Subject: [PATCH 3/5] add user-agent definition to robots.txt (#282) The "Disallow" line may be added outside a previous "User-agent" block or behind another customized definition. To ensure that we generate a valid robots.txt, we now generate a complete block. --- CHANGELOG.md | 2 +- inc/class-cachify.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b36210c..061e671e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ Requires PHP 5.6 and WordPress 4.7 or above * 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/inc/class-cachify.php b/inc/class-cachify.php index 78da24ea..1f888985 100644 --- a/inc/class-cachify.php +++ b/inc/class-cachify.php @@ -446,7 +446,7 @@ private static function _get_options() { public static function robots_txt() { /* HDD only */ if ( self::METHOD_HDD === self::$options['use_apc'] ) { - echo 'Disallow: */cache/cachify/'; + echo "User-agent: *\nDisallow: */cache/cachify/\n"; } } From a4f634cd3463baccd2ba53c151b116f187f33cf8 Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Fri, 14 Apr 2023 18:30:10 +0200 Subject: [PATCH 4/5] use robots_txt hook instead of do_robots action --- inc/class-cachify.php | 11 +++++++---- tests/test-cachify.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/inc/class-cachify.php b/inc/class-cachify.php index 1f888985..92eebf01 100644 --- a/inc/class-cachify.php +++ b/inc/class-cachify.php @@ -171,7 +171,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' ) ); } } @@ -439,15 +439,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 "User-agent: *\nDisallow: */cache/cachify/\n"; + $output .= "\nUser-agent: *\nDisallow: */cache/cachify/\n"; } + + return $output; } /** diff --git a/tests/test-cachify.php b/tests/test-cachify.php index f32225eb..052ccf6b 100644 --- a/tests/test-cachify.php +++ b/tests/test-cachify.php @@ -104,4 +104,33 @@ public function test_on_activation() { Cachify::on_activation(); self::assertEquals( array() , get_option( 'cachify' ), 'Cachify option not initialized' ); } + + + /** + * Test hook for robots.txt customization. + */ + public function test_robots_txt() { + // Initial robots.txt content. + $robots_txt = "User-agent: *\nDisallow: /wordpress/wp-admin/\nAllow: /wordpress/wp-admin/admin-ajax.php\n"; + + // DB cache enabled. + update_option( 'cachify' , array( 'use_apc' => 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' + ); + } } From f166ed8d8bfbee563ce7c068e99ba5602336ca57 Mon Sep 17 00:00:00 2001 From: Raffael Date: Mon, 21 Aug 2023 20:29:19 +0200 Subject: [PATCH 5/5] invalidate cache when permalink changes (#286) Migrate the action on "save_post" to "post_updated" and invalidate the page cache, if the permalink was changed, i.e. remove the leftover cache data for a no longer existing page. --- CHANGELOG.md | 1 + inc/class-cachify.php | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b36210c..f7834bf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ 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) diff --git a/inc/class-cachify.php b/inc/class-cachify.php index 78da24ea..a6c73c2e 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' ) ); @@ -1000,14 +1000,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 ) {