Skip to content

Commit

Permalink
Merge branch 'release-3.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
chesio committed Apr 4, 2024
2 parents ae4e043 + 1283ba8 commit 033395c
Show file tree
Hide file tree
Showing 26 changed files with 696 additions and 763 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: "Checkout code"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Check file permissions"
run: |
Expand All @@ -50,15 +50,15 @@ jobs:
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.0"
php-version: "8.1"
extensions: "mbstring"
coverage: "none"

- name: "Checkout code"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Install dependencies"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "highest"

Expand All @@ -74,9 +74,9 @@ jobs:
#fail-fast: false
matrix:
php-version:
- "8.3"
- "8.2"
- "8.1"
- "8.0"
dependencies:
- "lowest"
- "locked"
Expand All @@ -90,16 +90,16 @@ jobs:
extensions: "mbstring"

- name: "Checkout code"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Install dependencies"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "${{ matrix.dependencies }}"

- name: "Raise constraint for antecedent/patchwork"
if: "${{ matrix.dependencies == 'lowest' }}"
run: "composer require --dev --prefer-lowest --update-with-all-dependencies 'antecedent/patchwork:^2.0.8'"
run: "composer require --dev --prefer-lowest --update-with-all-dependencies 'antecedent/patchwork:^2.1.26'"

- name: "Execute unit tests"
run: "composer run-script unit-tests"
Expand All @@ -123,18 +123,18 @@ jobs:
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.0"
php-version: "8.1"
extensions: "mbstring"
coverage: "none"

- name: "Checkout code"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Validate Composer configuration"
run: "composer validate --strict"

- name: "Install dependencies"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "highest"

Expand All @@ -155,12 +155,12 @@ jobs:
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.0"
php-version: "8.1"
extensions: "mbstring"
coverage: "none"

- name: "Checkout code"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Check EditorConfig configuration"
run: "test -f .editorconfig"
Expand All @@ -169,7 +169,7 @@ jobs:
uses: "greut/eclint-action@v0"

- name: "Install dependencies"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "highest"

Expand All @@ -184,7 +184,7 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: "Checkout code"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"

- name: "Check exported files"
run: |
Expand Down
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# BC Cache Changelog

## Version 3.3.0 (2024-04-04)

PHP 8.1 and WordPress 6.2 are now required.

### Added

* Cache is flushed automatically when [Cookie Notice](https://wordpress.org/plugins/cookie-notice/) plugin settings change [#99](https://github.com/chesio/bc-cache/issues/99).
* Plugin has been tested with PHP 8.3 [#100](https://github.com/chesio/bc-cache/issues/100)
* Plugin has been tested with WordPress 6.4 [#101](https://github.com/chesio/bc-cache/issues/101) and 6.5 [#106](https://github.com/chesio/bc-cache/issues/106).

### Changed

* PHP 8.1 or newer is required [#103](https://github.com/chesio/bc-cache/issues/103).
* WordPress 6.2 or newer is required [#102](https://github.com/chesio/bc-cache/issues/102).

## Version 3.2.0 (2023-08-17)

This release only changes required and supported versions of PHP and WordPress (see below).
Expand Down Expand Up @@ -140,7 +155,7 @@ This release also contains some breaking changes:
Other notable changes in this release:

* The `_gl` query string tracking parameter does not interfere with caching [#53](https://github.com/chesio/bc-cache/issues/53). Note that `.htaccess` file should be updated accordingly to make full use of this feature.
* On WordPress 5.8 and newer the plugin cannot be accidentally overriden from WordPress.org Plugins Directory [#51](https://github.com/chesio/bc-cache/issues/51).
* On WordPress 5.8 and newer the plugin cannot be accidentally overridden from WordPress.org Plugins Directory [#51](https://github.com/chesio/bc-cache/issues/51).

Some bugs have been fixed too:

Expand Down
42 changes: 24 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ BC Cache can cache not only HTML pages, but [core XML sitemaps](https://make.wor
## Requirements

* Apache webserver with [mod_rewrite](https://httpd.apache.org/docs/current/mod/mod_rewrite.html) enabled
* [PHP](https://www.php.net/) 8.0 or newer
* [WordPress](https://wordpress.org/) 6.1 or newer with [pretty permalinks](https://codex.wordpress.org/Using_Permalinks) on
* [PHP](https://www.php.net/) 8.1 or newer
* [WordPress](https://wordpress.org/) 6.2 or newer with [pretty permalinks](https://wordpress.org/documentation/article/customize-permalinks/#pretty-permalinks) on

## Limitations

* BC Cache has not been tested on WordPress multisite installation.
* BC Cache has not been tested on Windows servers.
* BC Cache does not support [content negotation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation) via `Accept` header.
* BC Cache does not support [content negotiation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation) via `Accept` header.

## Installation

Expand Down Expand Up @@ -165,7 +165,7 @@ Following filters are necessary to set up [request variants](#request-variants):

Following filters can be used to tweak [warming up of cache](#cache-warm-up):

* `bc-cache/filter:cache-warm-up-initial-url-list` - filters list of initial URLs to be included in warm up. This filter is used to shortcut default processing: if it returns an array (even empty), no URLs are read from core XML sitemap providers.
* `bc-cache/filter:cache-warm-up-initial-url-list` - filters list of initial URLs to be included in warm up. This filter is used to shortcut default processing: if it returns an array (even empty), no URLs are read from XML sitemap(s).
* `bc-cache/filter:cache-warm-up-final-url-list` - filters the final list of URLs to be included in warm up.
* `bc-cache/filter:cache-warm-up-invocation-delay` - filters the time (in seconds) between cache flush and warm up invocation.
* `bc-cache/filter:cache-warm-up-run-timeout` - sets the time (in seconds) warm up crawler is allowed to run within single WP-Cron invocation. The value cannot be larger than value of `WP_CRON_LOCK_TIMEOUT` constant. Note that crawler stops only after this limit is reached. This means for example that even if the timeout is set to `0`, there is one HTTP request sent.
Expand Down Expand Up @@ -241,7 +241,7 @@ A response to HTTP(S) request is **not** cached by BC Cache if **any** of the co
7. `DONOTCACHEPAGE` constant is set and evaluates to true. This constant is for example [automatically set](https://docs.woocommerce.com/document/configuring-caching-plugins/#section-1) by WooCommerce on certain pages.
8. Return value of `bc-cache/filter:skip-cache` filter evaluates to true.

**Important!** Cache exclusion rules are essentialy defined in two places:
**Important!** Cache exclusion rules are essentially defined in two places:
1. In PHP code (including `bc-cache/filter:skip-cache` filter), the rules are used to determine whether current HTTP(S) request should be *written* to cache.
1. In `.htaccess` file, the rules are used to determine whether current HTTP(S) request should be *served* from cache.

Expand Down Expand Up @@ -356,11 +356,28 @@ add_filter('bc-cache/filter:cache-warm-up-request-arguments', function (array $a
}, 10, 3);
```

## Autoptimize integration
## WP-CLI commands

You might use [WP-CLI](https://wp-cli.org/) to delete specific posts/pages form cache, flush entire cache, run cache warm up, get size information or even list all cache entries. BC Cache registers `bc-cache` command with following subcommands:

* `delete <post-id>` - deletes cache data (all request variants) of post/page with given ID
* `remove <url>` - deletes cache data (all request variants) of given URL
* `flush` - flushes entire cache
* `warm-up` - runs cache warm up
* `size [--human-readable]` - retrieves cache directory apparent size, optionally in human readable format
* `list [<column>...] [--format=<format>] [--plain] [--sort-by=<column>]` - list cache entries, optionally in specified format or sorted

## Integration with 3rd-party plugins and tools

### Autoptimize

[Autoptimize](https://wordpress.org/plugins/autoptimize/) is a very popular plugin to optimize script and styles by aggregation, minification, caching etc. BC Cache automatically flushes its cache whenever Autoptimize cache is purged.

## 7G firewall integration
### Cookie Notice

[Cookie Notice](https://wordpress.org/plugins/cookie-notice/) is a popular plugin to display a simple, customizable website banner helpful achieving compliance with certain cookie consent requirements. BC Cache automatically flushes its cache whenever Cookie Notice banner configuration is changed.

### 7G firewall

If you happen to have [7G firewall](https://perishablepress.com/7g-firewall/) by Jeff Starr installed on your website, you may have to alter the rule in `7G:[REQUEST URI]` section that prevents access to `.gz` files (note that the code snippet below has been shortened with `...` for better readability):
```.apacheconf
Expand All @@ -369,17 +386,6 @@ RewriteCond %{REQUEST_URI} (\.)(7z|...|git|gz|hg|...|zlib)$ [NC,OR]

If you see 403 errors instead of cached pages, you have to either remove the `|gz` part from the `RewriteCond` line above or remove the line completely.

## WP-CLI integration

You might use [WP-CLI](https://wp-cli.org/) to delete specific posts/pages form cache, flush entire cache, run cache warm up, get size information or even list all cache entries. BC Cache registers `bc-cache` command with following subcommands:

* `delete <post-id>` - deletes cache data (all request variants) of post/page with given ID
* `remove <url>` - deletes cache data (all request variants) of given URL
* `flush` - flushes entire cache
* `warm-up` - runs cache warm up
* `size [--human-readable]` - retrieves cache directory apparent size, optionally in human readable format
* `list [<column>...] [--format=<format>] [--plain] [--sort-by=<column>]` - list cache entries, optionally in specified format or sorted

## Credits

* Sergej Müller & Plugin Kollektiv for inspiration in form of [Cachify plugin](https://wordpress.org/plugins/cachify/).
Expand Down
12 changes: 6 additions & 6 deletions bc-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* Plugin Name: BC Cache
* Plugin URI: https://github.com/chesio/bc-cache
* Description: Simple full page cache plugin inspired by Cachify.
* Version: 3.2.0
* Version: 3.3.0
* Author: Česlav Przywara <ceslav@przywara.cz>
* Author URI: https://www.chesio.com
* Requires PHP: 8.0
* Requires WP: 6.1
* Tested up to: 6.3
* Requires PHP: 8.1
* Requires at least: 6.2
* Tested up to: 6.5
* Text Domain: bc-cache
* GitHub Plugin URI: https://github.com/chesio/bc-cache
* Update URI: https://github.com/chesio/bc-cache
Expand All @@ -19,7 +19,7 @@
if (
false === \call_user_func(
function () {
$php_version_ok = \version_compare(PHP_VERSION, '8.0', '>=');
$php_version_ok = \version_compare(PHP_VERSION, '8.1', '>=');
$pretty_permalinks_on = (bool) get_option('permalink_structure');

if (!$php_version_ok) {
Expand All @@ -28,7 +28,7 @@ function () {
echo '<div class="error"><p>';
echo esc_html(
\sprintf(
__('BC Cache plugin requires PHP 8.0 to function properly, but you have version %s installed. The plugin has been auto-deactivated.', 'bc-cache'),
__('BC Cache plugin requires PHP 8.1 to function properly, but you have version %s installed. The plugin has been auto-deactivated.', 'bc-cache'),
PHP_VERSION
)
);
Expand Down
27 changes: 17 additions & 10 deletions classes/BlueChip/Cache/AdminNotices.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
*/
abstract class AdminNotices
{
public const ERROR = 'notice-error';
public const WARNING = 'notice-warning';
public const SUCCESS = 'notice-success';
public const INFO = 'notice-info';
public const ERROR = 'error';
public const WARNING = 'warning';
public const SUCCESS = 'success';
public const INFO = 'info';

/**
* Add dismissible admin notice with given $message of given $type.
*
* @link https://make.wordpress.org/core/2023/10/16/introducing-admin-notice-functions-in-wordpress-6-4/
* @link https://make.wordpress.org/core/2015/04/23/spinners-and-dismissible-admin-notices-in-4-2/
*
* @param string $message Message to display in admin notice.
Expand All @@ -26,11 +27,17 @@ abstract class AdminNotices
*/
public static function add(string $message, string $type = self::INFO, bool $is_dismissible = true, bool $escape_html = true): void
{
$classes = \implode(' ', \array_filter(['notice', $type, $is_dismissible ? 'is-dismissible' : '']));
add_action('admin_notices', function () use ($message, $classes, $escape_html) {
echo '<div class="' . $classes . '">';
echo '<p>' . ($escape_html ? esc_html($message) : $message) . '</p>';
echo '</div>';
});
if (is_wp_version_compatible('6.4')) {
add_action('admin_notices', function () use ($message, $type, $is_dismissible) {
wp_admin_notice($message, ['type' => $type, 'dismissible' => $is_dismissible,]);
});
} else {
$classes = \implode(' ', \array_filter(['notice', 'notice-' . $type, $is_dismissible ? 'is-dismissible' : '']));
add_action('admin_notices', function () use ($message, $classes, $escape_html) {
echo '<div class="' . $classes . '">';
echo '<p>' . ($escape_html ? esc_html($message) : $message) . '</p>';
echo '</div>';
});
}
}
}
Loading

0 comments on commit 033395c

Please sign in to comment.