From 83ea358869af804ef768a9cd110093e56dfe3983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Sat, 5 Nov 2022 16:26:06 -0700 Subject: [PATCH 01/16] remove old rules --- phpstan-baseline.neon | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 77fd0c0b..169c11ba 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,15 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Parameter \\#1 \\$name of class RedisCluster constructor expects string\\|null, array given\\.$#" - count: 1 - path: .php-tools/object-cache.php - - - - message: "#^Call to function is_string\\(\\) with array\\{'tcp\\://127\\.0\\.0\\.1…', 'tcp\\://127\\.0\\.0\\.2…', 'tcp\\://127\\.0\\.0\\.3…'\\} will always evaluate to false\\.$#" - count: 3 - path: .php-tools/object-cache.php - - message: "#^Class RedisCluster constructor invoked with 1 parameter, 2\\-6 required\\.$#" count: 1 From 5b9bcb9b7541c18fd70d6c671c822d252e394e8c Mon Sep 17 00:00:00 2001 From: Pavlo Yatsukhnenko Date: Wed, 18 Sep 2024 14:17:10 +0300 Subject: [PATCH 02/16] Add Plugin check action --- .github/workflows/lint.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 386cc52e..3964b6b4 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -55,3 +55,16 @@ jobs: with: eclint_args: | -exclude=dependencies/**/* + + plugincheck: + name: PluginCheck + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Run plugin check + uses: wordpress/plugin-check-action@v1 + with: + exclude-directories: 'dependencies' From 4e71c897e17fb9f0ce16ebf78e25968fd0b7ccb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Thu, 23 Jan 2025 12:48:51 -0800 Subject: [PATCH 03/16] exclude more paths --- .github/workflows/lint.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b9de9154..9b058a7c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -67,4 +67,5 @@ jobs: - name: Run plugin check uses: wordpress/plugin-check-action@v1 with: - exclude-directories: 'dependencies' + exclude-directories: 'dependencies,tests' + exclude-files: '.editorconfig,.gitattributes,phpunit.xml.dist' From 90d408ac9af1e8b3b31b454814d60471db851841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Thu, 23 Jan 2025 12:52:21 -0800 Subject: [PATCH 04/16] ignore `.github` --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 9b058a7c..50a0e741 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -67,5 +67,5 @@ jobs: - name: Run plugin check uses: wordpress/plugin-check-action@v1 with: - exclude-directories: 'dependencies,tests' + exclude-directories: '.github,dependencies,tests' exclude-files: '.editorconfig,.gitattributes,phpunit.xml.dist' From 96f9e57bf9fb45bcdfcd45121145e925dc2d8b9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Thu, 23 Jan 2025 13:01:44 -0800 Subject: [PATCH 05/16] use `esc_url()` --- .github/workflows/lint.yml | 2 +- CHANGELOG.md | 4 ++++ includes/ui/settings.php | 2 +- includes/ui/widget.php | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 50a0e741..5bb8c801 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -68,4 +68,4 @@ jobs: uses: wordpress/plugin-check-action@v1 with: exclude-directories: '.github,dependencies,tests' - exclude-files: '.editorconfig,.gitattributes,phpunit.xml.dist' + exclude-files: '.editorconfig,.gitattributes,.gitignore,phpunit.xml.dist' diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a288b6e..1ea3a53e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased +- Added `Primary Branch` header +- Fixed rare replication mode issue + ## 2.5.4 - Respect `WP_REDIS_SCHEME` for Cluster connections diff --git a/includes/ui/settings.php b/includes/ui/settings.php index c3d7f843..d9c0a3e1 100644 --- a/includes/ui/settings.php +++ b/includes/ui/settings.php @@ -98,7 +98,7 @@ class="classes() ); ?>"
  • - +

    diff --git a/includes/ui/widget.php b/includes/ui/widget.php index 2d2a25c9..df5728ac 100644 --- a/includes/ui/widget.php +++ b/includes/ui/widget.php @@ -34,7 +34,7 @@
  • - +
  • From 2d4f1d8332fb57ce0ee554d3ba48e6fdec4fef86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Thu, 23 Jan 2025 13:05:32 -0800 Subject: [PATCH 06/16] =?UTF-8?q?escape=20message=20=F0=9F=99=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/class-plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-plugin.php b/includes/class-plugin.php index 0fee1938..f7537bcf 100644 --- a/includes/class-plugin.php +++ b/includes/class-plugin.php @@ -1084,7 +1084,7 @@ public function ajax_flush_cache() { $message = 'Object cache could not be flushed.'; } - wp_die( __( $message , 'redis-cache' ) ); + wp_die( esc_html__( $message , 'redis-cache' ) ); } /** From 4a1edb5482834d94dbbc7884609a75051abac86c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Thu, 23 Jan 2025 13:11:19 -0800 Subject: [PATCH 07/16] exclude check --- .github/workflows/lint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5bb8c801..e7994a30 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -69,3 +69,4 @@ jobs: with: exclude-directories: '.github,dependencies,tests' exclude-files: '.editorconfig,.gitattributes,.gitignore,phpunit.xml.dist' + exclude-checks: 'Squiz.PHP.Heredoc.NotAllowed' From 1cd7c388efa02fa4824a3bc32cc6ee4cd38cc24d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Thu, 23 Jan 2025 13:13:25 -0800 Subject: [PATCH 08/16] appease linter --- includes/class-plugin.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/includes/class-plugin.php b/includes/class-plugin.php index f7537bcf..e5fcfba6 100644 --- a/includes/class-plugin.php +++ b/includes/class-plugin.php @@ -1076,15 +1076,13 @@ public function ajax_dismiss_notice() { * @return void */ public function ajax_flush_cache() { - if ( ! wp_verify_nonce( $_POST['nonce'] ) ) { - $message = 'Invalid Nonce.'; + if ( ! wp_verify_nonce( $_POST['nonce'] ?? '' ) ) { + wp_die( esc_html__( 'Invalid Nonce.', 'redis-cache' ) ); } else if ( wp_cache_flush() ) { - $message = 'Object cache flushed.'; + wp_die( esc_html__( 'Object cache flushed.', 'redis-cache' ) ); } else { - $message = 'Object cache could not be flushed.'; + wp_die( esc_html__( 'Object cache could not be flushed.', 'redis-cache' ) ); } - - wp_die( esc_html__( $message , 'redis-cache' ) ); } /** From 9698074885f604cbb539a26dd45c7e634d1c8317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Thu, 23 Jan 2025 13:17:18 -0800 Subject: [PATCH 09/16] use `wp_unslash()` --- includes/class-plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-plugin.php b/includes/class-plugin.php index e5fcfba6..199b1e57 100644 --- a/includes/class-plugin.php +++ b/includes/class-plugin.php @@ -1076,7 +1076,7 @@ public function ajax_dismiss_notice() { * @return void */ public function ajax_flush_cache() { - if ( ! wp_verify_nonce( $_POST['nonce'] ?? '' ) ) { + if ( ! wp_verify_nonce( wp_unslash( $_POST['nonce'] ?? '' ) ) ) { wp_die( esc_html__( 'Invalid Nonce.', 'redis-cache' ) ); } else if ( wp_cache_flush() ) { wp_die( esc_html__( 'Object cache flushed.', 'redis-cache' ) ); From 5d4c3f1ad37beb0418284f8ecb27cb4ec3d799c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Thu, 23 Jan 2025 13:23:37 -0800 Subject: [PATCH 10/16] more changes --- .github/workflows/lint.yml | 2 +- CHANGELOG.md | 1 + includes/class-metrics.php | 2 +- includes/ui/tabs/diagnostics.php | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e7994a30..d6d637e1 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -69,4 +69,4 @@ jobs: with: exclude-directories: '.github,dependencies,tests' exclude-files: '.editorconfig,.gitattributes,.gitignore,phpunit.xml.dist' - exclude-checks: 'Squiz.PHP.Heredoc.NotAllowed' + # exclude-checks: '' diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ea3a53e..c6e30c4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased - Added `Primary Branch` header +- Adhere to Plugin Check (PCP) - Fixed rare replication mode issue ## 2.5.4 diff --git a/includes/class-metrics.php b/includes/class-metrics.php index 29bdaf37..f4b723df 100644 --- a/includes/class-metrics.php +++ b/includes/class-metrics.php @@ -146,7 +146,7 @@ public function collect() { $info = $wp_object_cache->info(); - $this->id = substr( md5( uniqid( strval( mt_rand() ), true ) ), 12 ); + $this->id = substr( md5( uniqid( strval( wp_rand() ), true ) ), 12 ); $this->hits = $info->hits; $this->misses = $info->misses; $this->ratio = $info->ratio; diff --git a/includes/ui/tabs/diagnostics.php b/includes/ui/tabs/diagnostics.php index 68cacbb7..bacf2ace 100644 --- a/includes/ui/tabs/diagnostics.php +++ b/includes/ui/tabs/diagnostics.php @@ -16,8 +16,8 @@

    - +

    From f276ffdf15ab6c8ae51b6415b89e3bbc0028da72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Thu, 23 Jan 2025 13:31:04 -0800 Subject: [PATCH 11/16] try to disable --- .github/workflows/lint.yml | 2 +- includes/class-plugin.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d6d637e1..5fadbc8b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -57,7 +57,7 @@ jobs: -exclude=dependencies/**/* plugincheck: - name: PluginCheck + name: Plugin Check runs-on: ubuntu-latest steps: diff --git a/includes/class-plugin.php b/includes/class-plugin.php index 199b1e57..4ef3d1f2 100644 --- a/includes/class-plugin.php +++ b/includes/class-plugin.php @@ -1598,6 +1598,7 @@ public function current_user_can_manage_redis() { * @return void */ public function litespeed_disable_objectcache() { + // phpcs:ignore WordPress.Security.NonceVerification.Missing if ( isset( $_POST['LSCWP_CTRL'], $_POST['LSCWP_NONCE'], $_POST['object'] ) ) { $_POST['object'] = '0'; } From 2631760e8c2e96c6508976e1d002d2c873c91aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Thu, 23 Jan 2025 13:34:41 -0800 Subject: [PATCH 12/16] tweaks --- includes/class-plugin.php | 2 +- includes/object-cache.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/class-plugin.php b/includes/class-plugin.php index 4ef3d1f2..5ee7d428 100644 --- a/includes/class-plugin.php +++ b/includes/class-plugin.php @@ -1076,7 +1076,7 @@ public function ajax_dismiss_notice() { * @return void */ public function ajax_flush_cache() { - if ( ! wp_verify_nonce( wp_unslash( $_POST['nonce'] ?? '' ) ) ) { + if ( ! wp_verify_nonce( $_POST['nonce'] ?? '' ) ) { wp_die( esc_html__( 'Invalid Nonce.', 'redis-cache' ) ); } else if ( wp_cache_flush() ) { wp_die( esc_html__( 'Object cache flushed.', 'redis-cache' ) ); diff --git a/includes/object-cache.php b/includes/object-cache.php index b2a631d3..44eb8e8c 100644 --- a/includes/object-cache.php +++ b/includes/object-cache.php @@ -2501,6 +2501,8 @@ public function decr( $key, $offset = 1, $group = 'default' ) { * Used by the Debug bar plugin * * @return void + * + * phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped */ public function stats() { ?> @@ -2522,6 +2524,7 @@ public function stats() {

    Date: Thu, 23 Jan 2025 13:38:33 -0800 Subject: [PATCH 13/16] fixes --- includes/class-predis.php | 1 + includes/object-cache.php | 44 +++++++++++++++++++-------------------- readme.txt | 2 +- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/includes/class-predis.php b/includes/class-predis.php index 9fbe687c..cb4e5099 100644 --- a/includes/class-predis.php +++ b/includes/class-predis.php @@ -206,6 +206,7 @@ protected function build_cluster_connection_array() { $cluster = array_values( WP_REDIS_CLUSTER ); foreach ( $cluster as $key => $server ) { + // phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url $components = parse_url( $server ); if ( ! empty( $components['scheme'] ) ) { diff --git a/includes/object-cache.php b/includes/object-cache.php index 44eb8e8c..33ebef6c 100644 --- a/includes/object-cache.php +++ b/includes/object-cache.php @@ -2501,30 +2501,29 @@ public function decr( $key, $offset = 1, $group = 'default' ) { * Used by the Debug bar plugin * * @return void - * - * phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped */ public function stats() { - ?> -

    - Redis Status: - redis_status() ? 'Connected' : 'Not connected'; ?> -
    - Redis Client: - diagnostics['client'] ?: 'Unknown'; ?> -
    - Cache Hits: - cache_hits; ?> -
    - Cache Misses: - cache_misses; ?> -
    - Cache Size: - cache ) ) / 1024, 2 ); ?> KB -

    - +

    + Redis Status: + redis_status() ? 'Connected' : 'Not connected'; ?> +
    + Redis Client: + diagnostics['client'] ?: 'Unknown'; ?> +
    + Cache Hits: + cache_hits; ?> +
    + Cache Misses: + cache_misses; ?> +
    + Cache Size: + cache ) ) / 1024, 2 ); ?> KB +

    + $server ) { + // phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url $components = parse_url( $server ); if ( ! empty( $components['scheme'] ) ) { diff --git a/readme.txt b/readme.txt index 6f6fc7e8..9b04045f 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: tillkruess Donate link: https://github.com/sponsors/tillkruss Tags: redis, object cache, caching, performance, relay Requires at least: 4.6 -Tested up to: 6.6 +Tested up to: 6.7 Requires PHP: 7.2 Stable tag: 2.5.4 License: GPLv3 From e302d9f7d1a0f472b9406f29ca75315005b56d77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Thu, 23 Jan 2025 13:43:21 -0800 Subject: [PATCH 14/16] ignore two more --- includes/class-plugin.php | 1 + includes/object-cache.php | 1 + 2 files changed, 2 insertions(+) diff --git a/includes/class-plugin.php b/includes/class-plugin.php index 5ee7d428..69cbc360 100644 --- a/includes/class-plugin.php +++ b/includes/class-plugin.php @@ -1076,6 +1076,7 @@ public function ajax_dismiss_notice() { * @return void */ public function ajax_flush_cache() { + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash if ( ! wp_verify_nonce( $_POST['nonce'] ?? '' ) ) { wp_die( esc_html__( 'Invalid Nonce.', 'redis-cache' ) ); } else if ( wp_cache_flush() ) { diff --git a/includes/object-cache.php b/includes/object-cache.php index 33ebef6c..9d778f0e 100644 --- a/includes/object-cache.php +++ b/includes/object-cache.php @@ -3022,6 +3022,7 @@ protected function show_error_and_die( Exception $exception ) { '/wp-content/' ) . "

    \n"; + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped wp_die( $message ); } From 409114293c45065b447ba0a66c81e2bf79b36ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Thu, 23 Jan 2025 13:53:58 -0800 Subject: [PATCH 15/16] ignore sniffs --- includes/class-plugin.php | 3 +-- includes/object-cache.php | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/includes/class-plugin.php b/includes/class-plugin.php index 69cbc360..5578202f 100644 --- a/includes/class-plugin.php +++ b/includes/class-plugin.php @@ -1076,8 +1076,7 @@ public function ajax_dismiss_notice() { * @return void */ public function ajax_flush_cache() { - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash - if ( ! wp_verify_nonce( $_POST['nonce'] ?? '' ) ) { + if ( ! wp_verify_nonce( $_POST['nonce'] ?? '' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput wp_die( esc_html__( 'Invalid Nonce.', 'redis-cache' ) ); } else if ( wp_cache_flush() ) { wp_die( esc_html__( 'Object cache flushed.', 'redis-cache' ) ); diff --git a/includes/object-cache.php b/includes/object-cache.php index ffb5f4f5..b201f040 100644 --- a/includes/object-cache.php +++ b/includes/object-cache.php @@ -3027,8 +3027,7 @@ protected function show_error_and_die( Exception $exception ) { '/wp-content/' ) . "

    \n"; - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - wp_die( $message ); + wp_die( $message ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** From fa74ea923c9816b0a00d2050cc356ef54113d99f Mon Sep 17 00:00:00 2001 From: Pavlo Yatsukhnenko Date: Fri, 24 Jan 2025 18:52:06 +0200 Subject: [PATCH 16/16] Suppress Squiz.PHP.Heredoc.NotAllowed warning (#566) --- includes/class-plugin.php | 6 ++++-- includes/object-cache.php | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/includes/class-plugin.php b/includes/class-plugin.php index 5578202f..9fd537e4 100644 --- a/includes/class-plugin.php +++ b/includes/class-plugin.php @@ -827,6 +827,7 @@ public function render_admin_bar( $wp_admin_bar ) { * @return string */ protected function admin_bar_style() { + // phpcs:disable Squiz.PHP.Heredoc.NotAllowed return << #wpadminbar ul li.redis-cache-error { @@ -838,7 +839,7 @@ protected function admin_bar_style() { color: #fff; } -HTML; +HTML; // phpcs:enable } /** @@ -851,6 +852,7 @@ protected function admin_bar_script() { $ajaxurl = esc_url( admin_url( 'admin-ajax.php' ) ); $flushMessage = __( 'Flushing cache...', 'redis-cache' ); + // phpcs:disable Squiz.PHP.Heredoc.NotAllowed return << (function (element) { @@ -895,7 +897,7 @@ protected function admin_bar_script() { document.querySelector('#wp-admin-bar-redis-cache-flush > a') ); -HTML; +HTML; // phpcs:enable } /** diff --git a/includes/object-cache.php b/includes/object-cache.php index b201f040..86367e6b 100644 --- a/includes/object-cache.php +++ b/includes/object-cache.php @@ -1877,6 +1877,7 @@ protected function lua_flush_closure( $salt, $escape = true ) { $salt = $escape ? $this->glob_quote( $salt ) : $salt; return function () use ( $salt ) { + // phpcs:disable Squiz.PHP.Heredoc.NotAllowed $script = <<redis_version) && version_compare( $this->redis_version, '5', '<' ) && version_compare( $this->redis_version, '3.2', '>=' ) ) { $script = 'redis.replicate_commands()' . "\n" . $script; @@ -1923,6 +1924,7 @@ function ( $group ) { $this->unflushable_groups ); + // phpcs:disable Squiz.PHP.Heredoc.NotAllowed $script = <<redis_version) && version_compare( $this->redis_version, '5', '<' ) && version_compare( $this->redis_version, '3.2', '>=' ) ) { $script = 'redis.replicate_commands()' . "\n" . $script; }