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 Mar 29, 2024
2 parents 429c5b5 + 053b59a commit 228a643
Show file tree
Hide file tree
Showing 19 changed files with 379 additions and 122 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ jobs:
wordpress: '5.9'
- php: '8.0'
wordpress: '6.0'
- php: '8.1'
- php: '8.2'
wordpress: '6.4'
- php: '8.3'
wordpress: 'latest'
- php: '8.1'
- php: '8.3'
wordpress: 'nightly'
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup PHP
Expand All @@ -43,16 +45,16 @@ jobs:
quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.2'
tools: composer
- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '20'
- name: Code style checks for PHP and CSS
run: |
composer install
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/wordpress-plugin-asset-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jobs:
name: Push to stable
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.2'
tools: composer
- name: Build
run: composer install
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/wordpress-plugin-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ jobs:
name: New tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.2'
tools: composer
- name: Build
run: composer install
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ Requires PHP 5.6 and WordPress 4.7 or above
* Fix for the PHP notice "Call to undefined function is_plugin_active_for_network" on WordPress Multisite

## 2.2.0
* Toolbar: Display of the "Flush the cachify cache" button on the frontend
* Toolbar: Controlling the display of the "Flush the cachify cache" button via hook
* Toolbar: Display of the "Flush the Cachify cache" button on the frontend
* Toolbar: Controlling the display of the "Flush the Cachify cache" button via hook

## 2.1.9
* Vervollständigung des Cachify-Pfades in `robots.txt`: `Disallow: /wp-content/cache/cachify/`
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Cachify #
Smart, efficient cache solution for WordPress. Use DB, HDD, APC or Memcached for storing your blog pages. Make WordPress faster!
Smart, efficient cache solution for WordPress. Use DB, HDD, APC, Redis or Memcached for storing your blog pages. Make WordPress faster!

## Description ##
*Cachify* optimizes your page loads by caching posts, pages and custom post types as static content. You can choose between caching via database, on the web server’s hard drive (HDD), Memcached (only on Nginx) or — thanks to APC (Alternative PHP Cache) — directly in the web server’s system cache. Whenever a page or post is loaded, it can be pulled directly from the cache. The amount of database queries and PHP requests will dramatically decrease towards zero, depending on the caching method you chose.
*Cachify* optimizes your page loads by caching posts, pages and custom post types as static content. You can choose between caching via database, on the web server’s hard drive (HDD), Memcached (only on Nginx), Redis or — thanks to APC (Alternative PHP Cache) — directly in the web server’s system cache. Whenever a page or post is loaded, it can be pulled directly from the cache. The amount of database queries and PHP requests will dramatically decrease towards zero, depending on the caching method you chose.

### Features ###
* Works with custom post types.
* Caching methods: DB, HDD, APC and Memcached.
* Caching methods: DB, HDD, APC, Redis and Memcached.
* “Flush Cache” button in the WordPress toolbar.
* Ready for WordPress Multisite.
* Optional compression of HTML markup.
Expand Down Expand Up @@ -43,6 +43,7 @@ Smart, efficient cache solution for WordPress. Use DB, HDD, APC or Memcached for
* WordPress 4.7 or greater
* APC 3.1.4 or greater (optional)
* Memcached in Nginx (optional)
* Redis (optional, via the phpredis module)


## Frequently Asked Questions ##
Expand Down
12 changes: 6 additions & 6 deletions cachify.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Plugin Name: Cachify
* Description: Easy to use WordPress caching plugin. Serving static blog pages from database, disk, Memcached or APC.
* Description: Easy to use WordPress caching plugin. Serving static blog pages from database, disk, Memcached, Redis or APC.
* Author: pluginkollektiv
* Author URI: https://pluginkollektiv.org
* Plugin URI: https://cachify.pluginkollektiv.org
Expand Down Expand Up @@ -38,7 +38,7 @@

/* Constants */
define( 'CACHIFY_FILE', __FILE__ );
define( 'CACHIFY_DIR', dirname( __FILE__ ) );
define( 'CACHIFY_DIR', __DIR__ );
define( 'CACHIFY_BASE', plugin_basename( __FILE__ ) );
define( 'CACHIFY_CACHE_DIR', WP_CONTENT_DIR . '/cache/cachify' );

Expand Down Expand Up @@ -88,14 +88,14 @@
/**
* Autoload the class.
*
* @param string $class the class name.
* @param string $class_name the class name.
*/
function cachify_autoload( $class ) {
if ( in_array( $class, array( 'Cachify', 'Cachify_APC', 'Cachify_DB', 'Cachify_HDD', 'Cachify_MEMCACHED', 'Cachify_CLI' ), true ) ) {
function cachify_autoload( $class_name ) {
if ( in_array( $class_name, array( 'Cachify', 'Cachify_APC', 'Cachify_DB', 'Cachify_HDD', 'Cachify_MEMCACHED', 'Cachify_REDIS', 'Cachify_CLI' ), true ) ) {
require_once sprintf(
'%s/inc/class-%s.php',
CACHIFY_DIR,
strtolower( str_replace( '_', '-', $class ) )
strtolower( str_replace( '_', '-', $class_name ) )
);
}
}
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
"forum": "https://wordpress.org/support/plugin/cachify"
},
"require": {
"php": ">=5.2.0",
"composer/installers": "~1.0"
"php": ">=5.6",
"composer/installers": "^v1|^v2"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^v0.7",
"dealerdirect/phpcodesniffer-composer-installer": "^v1.0",
"matthiasmullie/minify": "^1.3",
"phpunit/phpunit": "^5|^7|^9",
"squizlabs/php_codesniffer": "^3.7",
"squizlabs/php_codesniffer": "^3.9",
"phpcompatibility/phpcompatibility-wp": "^2.1",
"wp-coding-standards/wpcs": "^2.3",
"yoast/phpunit-polyfills": "^1.0"
"wp-coding-standards/wpcs": "^3.1",
"yoast/phpunit-polyfills": "^2.0"
},
"scripts": {
"post-install-cmd": [
Expand Down
2 changes: 1 addition & 1 deletion inc/cachify.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
printf(
/* translators: Placeholder is the trash icon itself as dashicon */
esc_html__( 'Flush the cache by clicking the button below or the %1$s icon in the admin bar.', 'cachify' ),
'<span class="dashicons dashicons-trash" aria-hidden="true"></span><span class="screen-reader-text">"' . esc_html__( 'Flush the cachify cache', 'cachify' ) . '"</span>'
'<span class="dashicons dashicons-trash" aria-hidden="true"></span><span class="screen-reader-text">"' . esc_html__( 'Flush the Cachify cache', 'cachify' ) . '"</span>'
);
?>
</p>
Expand Down
2 changes: 1 addition & 1 deletion inc/class-cachify-apc.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static function clear_cache() {
* @since 2.0
*/
public static function print_cache() {
return;
// Not supported.
}

/**
Expand Down
17 changes: 8 additions & 9 deletions inc/class-cachify-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public static function add_commands() {
'shortdesc' => 'Flush site cache',
'synopsis' => array(
array(
'type' => 'flag',
'name' => 'all-methods',
'description' => 'Flush all caching methods',
'optional' => true,
'type' => 'flag',
'name' => 'all-methods',
'description' => 'Flush all caching methods',
'optional' => true,
),
),
)
Expand All @@ -94,14 +94,13 @@ public static function add_commands() {
'shortdesc' => 'Get the size of the cache in bytes',
'synopsis' => array(
array(
'type' => 'flag',
'name' => 'raw',
'description' => 'Raw size output in bytes',
'optional' => true,
'type' => 'flag',
'name' => 'raw',
'description' => 'Raw size output in bytes',
'optional' => true,
),
),
)
);

}
}
11 changes: 6 additions & 5 deletions inc/class-cachify-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ public static function get_stats() {
global $wpdb;

/* Read */

return $wpdb->get_var(
'SELECT SUM( CHAR_LENGTH(option_value) ) FROM `' . $wpdb->options . "` WHERE `option_name` LIKE ('\_transient%.cachify')"
return intval(
$wpdb->get_var(
'SELECT SUM( CHAR_LENGTH(option_value) ) FROM `' . $wpdb->options . "` WHERE `option_name` LIKE ('\_transient%.cachify')"
)
);
}

Expand All @@ -166,7 +167,7 @@ public static function get_stats() {
private static function _cache_signature( $detail, $meta ) {
/* No array? */
if ( ! is_array( $meta ) ) {
return;
return '';
}

if ( $detail ) {
Expand Down Expand Up @@ -218,7 +219,7 @@ private static function _page_queries() {
/**
* Return execution time
*
* @return int Execution time in seconds
* @return string Execution time in seconds
*
* @since 0.1
*/
Expand Down
31 changes: 14 additions & 17 deletions inc/class-cachify-hdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public static function clear_cache() {
*/
public static function print_cache() {
$filename = self::_file_html();
$size = is_readable( $filename ) ? readfile( $filename ) : false;
$size = is_readable( $filename ) ? readfile( $filename ) : false;

if ( ! empty( $size ) ) {
/* Ok, cache file has been sent to output. */
exit;
Expand Down Expand Up @@ -174,7 +175,7 @@ private static function _create_files( $data ) {

/* Create directory */
if ( ! wp_mkdir_p( $file_path ) ) {
trigger_error( esc_html( __METHOD__ . ": Unable to create directory {$file_path}.", E_USER_WARNING ) );
trigger_error( esc_html( __METHOD__ . ": Unable to create directory {$file_path}." ), E_USER_WARNING );
return;
}
/* Write to file */
Expand Down Expand Up @@ -202,7 +203,7 @@ private static function _create_file( $file, $data ) {
/* Writable? */
$handle = @fopen( $file, 'wb' );
if ( ! $handle ) {
trigger_error( esc_html( __METHOD__ . ": Could not write file {$file}.", E_USER_WARNING ) );
trigger_error( esc_html( __METHOD__ . ": Could not write file {$file}." ), E_USER_WARNING );
return;
}

Expand All @@ -212,7 +213,7 @@ private static function _create_file( $file, $data ) {
clearstatcache();

/* Permissions */
$stat = @stat( dirname( $file ) );
$stat = @stat( dirname( $file ) );
$perms = $stat['mode'] & 0007777;
$perms = $perms & 0000666;
@chmod( $file, $perms );
Expand Down Expand Up @@ -255,18 +256,14 @@ private static function _clear_dir( $dir, $recursive = false ) {
/* Directory or file */
if ( is_dir( $object ) && $recursive ) {
self::_clear_dir( $object, $recursive );
} else {
if ( self::_user_can_delete( $object ) ) {
unlink( $object );
}
} elseif ( self::_user_can_delete( $object ) ) {
unlink( $object );
}
}

/* Remove directory */
if ( $recursive ) {
if ( self::_user_can_delete( $dir ) && 0 === count( glob( trailingslashit( $dir ) . '*' ) ) ) {
@rmdir( $dir );
}
if ( $recursive && self::_user_can_delete( $dir ) && 0 === count( glob( trailingslashit( $dir ) . '*' ) ) ) {
@rmdir( $dir );
}

/* Clean up */
Expand All @@ -278,14 +275,14 @@ private static function _clear_dir( $dir, $recursive = false ) {
*
* @param string $dir Directory path.
*
* @return mixed Directory size
* @return int|false Directory size
*
* @since 2.0
*/
public static function _dir_size( $dir = '.' ) {
/* Is directory? */
if ( ! is_dir( $dir ) ) {
return;
return false;
}

/* Read */
Expand All @@ -296,7 +293,7 @@ public static function _dir_size( $dir = '.' ) {

/* Empty? */
if ( empty( $objects ) ) {
return;
return false;
}

/* Init */
Expand Down Expand Up @@ -402,9 +399,9 @@ private static function _user_can_delete( $file ) {
$file = trailingslashit( $file );
}

$ssl_prefix = is_ssl() ? 'https-' : '';
$ssl_prefix = is_ssl() ? 'https-' : '';
$current_blog = get_blog_details( get_current_blog_id() );
$blog_path = CACHIFY_CACHE_DIR . DIRECTORY_SEPARATOR . $ssl_prefix . $current_blog->domain . $current_blog->path;
$blog_path = CACHIFY_CACHE_DIR . DIRECTORY_SEPARATOR . $ssl_prefix . $current_blog->domain . $current_blog->path;

if ( 0 !== strpos( $file, $blog_path ) ) {
return false;
Expand Down
12 changes: 6 additions & 6 deletions inc/class-cachify-memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ final class Cachify_MEMCACHED {
*/
public static function is_available() {
return class_exists( 'Memcached' )
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
&& isset( $_SERVER['SERVER_SOFTWARE'] ) && strpos( strtolower( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ), 'nginx' ) !== false;
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
&& isset( $_SERVER['SERVER_SOFTWARE'] ) && strpos( strtolower( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ), 'nginx' ) !== false;
}

/**
Expand Down Expand Up @@ -89,7 +89,7 @@ public static function store_item( $hash, $data, $lifetime, $sig_detail ) {
public static function get_item( $hash ) {
/* Server connect */
if ( ! self::_connect_server() ) {
return;
return null;
}

/* Get item */
Expand Down Expand Up @@ -143,7 +143,7 @@ public static function clear_cache() {
* @since 2.0.7
*/
public static function print_cache() {
return;
// Not supported.
}

/**
Expand Down Expand Up @@ -254,8 +254,8 @@ private static function _connect_server() {
} else {
self::$_memcached->setOptions(
array(
Memcached::OPT_COMPRESSION => false,
Memcached::OPT_BUFFER_WRITES => true,
Memcached::OPT_COMPRESSION => false,
Memcached::OPT_BUFFER_WRITES => true,
Memcached::OPT_BINARY_PROTOCOL => true,
)
);
Expand Down
Loading

0 comments on commit 228a643

Please sign in to comment.