Skip to content

Commit

Permalink
Merge branch 'develop' into patch-4
Browse files Browse the repository at this point in the history
  • Loading branch information
stklcode committed Oct 31, 2023
2 parents b5fded0 + c41690c commit 429c5b5
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea/
.phpunit.result.cache
css/*.min.css
js/*.min.js
vendor/
node_modules/
composer.lock
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions css/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 16 additions & 11 deletions inc/class-cachify.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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' ) );
}
}

Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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; }' );
Expand Down
6 changes: 0 additions & 6 deletions js/admin-bar-flush.min.js

This file was deleted.

29 changes: 29 additions & 0 deletions tests/test-cachify.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
}
}

0 comments on commit 429c5b5

Please sign in to comment.