Skip to content

Commit

Permalink
Plugin check (#556)
Browse files Browse the repository at this point in the history
Co-authored-by: Pavlo Yatsukhnenko <[email protected]>
  • Loading branch information
tillkruss and yatsukhnenko authored Jan 24, 2025
1 parent b25f391 commit bd95bfb
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 34 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,18 @@ jobs:
with:
eclint_args: |
-exclude=dependencies/**/*
plugincheck:
name: Plugin Check
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: '.github,dependencies,tests'
exclude-files: '.editorconfig,.gitattributes,.gitignore,phpunit.xml.dist'
# exclude-checks: ''
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Unreleased
- Added `Primary Branch` header
- Adhere to Plugin Check (PCP)
- Fixed rare replication mode issue

## 2.5.4

- Respect `WP_REDIS_SCHEME` for Cluster connections
Expand Down
2 changes: 1 addition & 1 deletion includes/class-metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 9 additions & 8 deletions includes/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<<HTML
<style>
#wpadminbar ul li.redis-cache-error {
Expand All @@ -838,7 +839,7 @@ protected function admin_bar_style() {
color: #fff;
}
</style>
HTML;
HTML; // phpcs:enable
}

/**
Expand All @@ -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 <<<HTML
<script>
(function (element) {
Expand Down Expand Up @@ -895,7 +897,7 @@ protected function admin_bar_script() {
document.querySelector('#wp-admin-bar-redis-cache-flush > a')
);
</script>
HTML;
HTML; // phpcs:enable
}

/**
Expand Down Expand Up @@ -1076,15 +1078,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'] ?? '' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
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( __( $message , 'redis-cache' ) );
}

/**
Expand Down Expand Up @@ -1600,6 +1600,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';
}
Expand Down
1 change: 1 addition & 0 deletions includes/class-predis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) ) {
Expand Down
47 changes: 26 additions & 21 deletions includes/object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<<LUA
local cur = 0
local i = 0
Expand All @@ -1892,7 +1893,7 @@ protected function lua_flush_closure( $salt, $escape = true ) {
end
until 0 == cur
return i
LUA;
LUA; // phpcs:enable

if ( isset($this->redis_version) && version_compare( $this->redis_version, '5', '<' ) && version_compare( $this->redis_version, '3.2', '>=' ) ) {
$script = 'redis.replicate_commands()' . "\n" . $script;
Expand Down Expand Up @@ -1923,6 +1924,7 @@ function ( $group ) {
$this->unflushable_groups
);

// phpcs:disable Squiz.PHP.Heredoc.NotAllowed
$script = <<<LUA
local cur = 0
local i = 0
Expand All @@ -1945,7 +1947,7 @@ function ( $group ) {
end
until 0 == cur
return i
LUA;
LUA; // phpcs:enable
if ( isset($this->redis_version) && version_compare( $this->redis_version, '5', '<' ) && version_compare( $this->redis_version, '3.2', '>=' ) ) {
$script = 'redis.replicate_commands()' . "\n" . $script;
}
Expand Down Expand Up @@ -2508,24 +2510,26 @@ public function decr( $key, $offset = 1, $group = 'default' ) {
* @return void
*/
public function stats() {
?>
<p>
<strong>Redis Status:</strong>
<?php echo $this->redis_status() ? 'Connected' : 'Not connected'; ?>
<br />
<strong>Redis Client:</strong>
<?php echo $this->diagnostics['client'] ?: 'Unknown'; ?>
<br />
<strong>Cache Hits:</strong>
<?php echo (int) $this->cache_hits; ?>
<br />
<strong>Cache Misses:</strong>
<?php echo (int) $this->cache_misses; ?>
<br />
<strong>Cache Size:</strong>
<?php echo number_format_i18n( strlen( serialize( $this->cache ) ) / 1024, 2 ); ?> KB
</p>
<?php
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
?>
<p>
<strong>Redis Status:</strong>
<?php echo $this->redis_status() ? 'Connected' : 'Not connected'; ?>
<br />
<strong>Redis Client:</strong>
<?php echo $this->diagnostics['client'] ?: 'Unknown'; ?>
<br />
<strong>Cache Hits:</strong>
<?php echo (int) $this->cache_hits; ?>
<br />
<strong>Cache Misses:</strong>
<?php echo (int) $this->cache_misses; ?>
<br />
<strong>Cache Size:</strong>
<?php echo number_format_i18n( strlen( serialize( $this->cache ) ) / 1024, 2 ); ?> KB
</p>
<?php
// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
}

/**
Expand Down Expand Up @@ -3025,7 +3029,7 @@ protected function show_error_and_die( Exception $exception ) {
'<code>/wp-content/</code>'
) . "</p>\n";

wp_die( $message );
wp_die( $message ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}

/**
Expand All @@ -3037,6 +3041,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'] ) ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/ui/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class="<?php echo esc_attr( $ui_tab->classes() ); ?>"
<li><?php esc_html_e( 'Optimized for WooCommerce, Jetpack & Yoast SEO', 'redis-cache' ); ?></li>
</ul>
<p>
<a class="button button-primary" target="_blank" rel="noopener" href="<?php echo $this->link_to_ocp('settings'); ?>">
<a class="button button-primary" target="_blank" rel="noopener" href="<?php echo esc_url( $this->link_to_ocp( 'settings' ) ); ?>">
<?php esc_html_e( 'Learn more', 'redis-cache' ); ?>
</a>
</p>
Expand Down
4 changes: 2 additions & 2 deletions includes/ui/tabs/diagnostics.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<p id="redis-cache-copy-button">
<span class="copy-button-wrapper">
<button type="button" class="button copy-button" data-clipboard-target="#redis-cache-diagnostics">
<?php _e( 'Copy diagnostics to clipboard', 'redis-cache' ); ?>
<?php esc_html_e( 'Copy diagnostics to clipboard', 'redis-cache' ); ?>
</button>
<span class="success hidden" aria-hidden="true"><?php _e( 'Copied!' ); ?></span>
<span class="success hidden" aria-hidden="true"><?php esc_html_e( 'Copied!', 'redis-cache' ); ?></span>
</span>
</p>
2 changes: 1 addition & 1 deletion includes/ui/widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</a>
</li>
<li style="margin-left: auto;">
<a href="<?php echo network_admin_url( $this->page ); ?>">
<a href="<?php echo esc_url( network_admin_url( $this->page ) ); ?>">
<?php esc_html_e( 'Settings', 'redis-cache' ); ?>
</a>
</li>
Expand Down

0 comments on commit bd95bfb

Please sign in to comment.