Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added litespeed support #6

Merged
merged 4 commits into from
Jul 18, 2024
Merged

feat: added litespeed support #6

merged 4 commits into from
Jul 18, 2024

Conversation

tareq1988
Copy link
Contributor

@tareq1988 tareq1988 commented Jul 17, 2024

Summary by CodeRabbit

  • New Features

    • Introduced LiteSpeed cache management functionality, allowing users to enable, disable, and clear LiteSpeed cache from the admin interface.
    • Added new UI elements for LiteSpeed Cache status and actions in the admin dashboard.
  • Improvements

    • Enhanced cache management capabilities by distinguishing between Nginx and LiteSpeed servers.
    • Improved flexibility in handling cache settings through the API with separate methods for Fastcgi and LiteSpeed caches.
  • Bug Fixes

    • Corrected CSS class assignments for cache-related notices to improve styling consistency.
  • Chores

    • Updated deployment workflow by removing Slack notification steps.

Copy link

coderabbitai bot commented Jul 17, 2024

Walkthrough

The changes include updates to workflow, cache management, and administrative functionalities. Notably, .distignore was updated, a Slack notification step was removed from the deploy workflow, and several new classes and methods were added to manage LiteSpeed cache and determine server types. Enhancements were also made to the user interface for cache management and WordPress admin settings.

Changes

File Path Change Summary
.distignore Removed .prettierrc.js, added .prettierrc, RELEASE.md, and .php-cs-fixer.dist.php.
.github/workflows/deploy.yml Removed Slack notification step for deployments to WordPress.org.
flywp.php Added LiteSpeed class instance creation and is_nginx method.
includes/Admin.php Made constants public, added $litespeed and $fastcgi properties, updated constructor.
includes/Admin/Litespeed.php New class to handle LiteSpeed cache actions and admin interface updates.
includes/Api.php Changed instantiation of Fastcgi_Cache to Cache in the constructor.
includes/Api/Cache.php New class to manage cache settings via API endpoints for fastcgi and LiteSpeed caches.
includes/FlyApi.php Updated cache_toggle method to accept type parameter for cache type.
includes/Helper.php Added static methods is_nginx() and is_litespeed() to determine server type.
includes/LiteSpeed.php New class to interact with LiteSpeed cache plugin, check status, and manage settings.
views/admin.php Updated to conditionally require different files based on server type.
views/litespeed.php New file for LiteSpeed Cache management section in the admin interface.
views/op-cache.php Modified assignment of $notice variable based on query parameter.
views/page-cache.php Updated CSS classes for a div element related to page cache notice.

Poem

In the garden of code, where changes bloom,
Servers now know their cache by room.
With LiteSpeed's swift and Nginx's might,
Admins rejoice, the future's bright.
Deploys are smooth, no Slack to ping,
Let’s celebrate, for efficiency is king!
🌸🐇🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (2)
includes/Api.php (1)

28-28: Incomplete Transition to Cache Class

The transition from Fastcgi_Cache to Cache is incomplete. The Fastcgi_Cache class is still being instantiated and used in several parts of the codebase. To avoid inconsistencies and potential issues, ensure that all instances of Fastcgi_Cache are replaced with the new Cache class where applicable.

  • flywp.php
  • includes/Fastcgi_Cache.php
  • includes/Admin.php
  • includes/Admin/Fastcgi_Cache.php
Analysis chain

Updated Cache Class Instantiation

The instantiation of the Cache class replaces the previous Fastcgi_Cache. Ensure that the Cache class is fully compatible and that all associated methods and properties accessed in other parts of the code are updated accordingly.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the `Cache` class is used consistently across the codebase.

# Test: Search for the usage of `Cache` and `Fastcgi_Cache` classes. Expect: Only `Cache` class should be used.
rg --type php -A 5 $'Api\\\Cache'
rg --type php -A 5 $'Api\\\Fastcgi_Cache'

Length of output: 277


Script:

#!/bin/bash
# Description: Locate the definition and usage of the `Cache` class to ensure it is correctly implemented and compatible with the rest of the codebase.

# Find the definition of the `Cache` class.
ast-grep --lang php --pattern 'class Cache { $$$ }'

# Find all usages of the `Cache` class.
rg --type php 'Cache'

Length of output: 3261


Script:

#!/bin/bash
# Description: Review the implementation of the `Cache` class and check for any remaining dependencies on `Fastcgi_Cache`.

# Display the implementation of the `Cache` class.
cat includes/Api/Cache.php

# Find all references to `Fastcgi_Cache` to ensure they are being phased out.
rg --type php 'Fastcgi_Cache'

Length of output: 1962

includes/Api/Cache.php (1)

7-71: New Cache Class Implementation

The Cache class is well-structured and includes methods for handling cache settings for both FastCGI and LiteSpeed. Ensure that the API endpoints are secure and that the input validation is robust to prevent potential security vulnerabilities.

Consider adding more detailed logging for the actions performed within these methods to aid in debugging and monitoring.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cddc2ea and abfaebd.

Files selected for processing (8)
  • .distignore (1 hunks)
  • .github/workflows/deploy.yml (1 hunks)
  • flywp.php (2 hunks)
  • includes/Api.php (1 hunks)
  • includes/Api/Cache.php (1 hunks)
  • includes/LiteSpeed.php (1 hunks)
  • views/admin.php (1 hunks)
  • views/litespeed.php (1 hunks)
Files skipped from review due to trivial changes (2)
  • .distignore
  • .github/workflows/deploy.yml
Additional context used
GitHub Check: Run PHPCS inspection
views/litespeed.php

[warning] 37-37:
Found precision alignment of 1 spaces.

includes/LiteSpeed.php

[failure] 16-16:
$_SERVER data not unslashed before sanitization. Use wp_unslash() or similar

flywp.php

[failure] 150-150:
$_SERVER data not unslashed before sanitization. Use wp_unslash() or similar


[failure] 150-150:
Detected usage of a non-sanitized input variable: $_SERVER['SERVER_SOFTWARE']

Additional comments not posted (11)
views/admin.php (1)

29-34: Updated Admin Interface for Cache Handling

The conditional logic to include litespeed.php based on the server type is correctly implemented. Verify that the is_server method in the LiteSpeed class accurately detects the server type to ensure correct functionality.

Verification successful

Verification of is_server Method in LiteSpeed Class

The is_server method in the LiteSpeed class is correctly implemented to detect the server type by checking the $_SERVER['SERVER_SOFTWARE'] variable for the presence of 'LiteSpeed'. This ensures that the conditional logic in views/admin.php will function as expected.

  • includes/LiteSpeed.php:
    public function is_server() {
        return isset( $_SERVER['SERVER_SOFTWARE'] ) && false !== strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' );
    }
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `is_server` method in the `LiteSpeed` class.

# Test: Search for the implementation of `is_server` method. Expect: Proper server detection logic.
ast-grep --lang php --pattern $'class LiteSpeed {
  $$$
  is_server($_) {
    $$$
  }
  $$$  
}'

Length of output: 204


Script:

#!/bin/bash
# Description: Verify the implementation of `is_server` method in the `LiteSpeed` class.

# Test: Search for the implementation of `is_server` method. Expect: Proper server detection logic.
rg -A 10 'function is_server' | rg -B 10 'class LiteSpeed'

Length of output: 60


Script:

#!/bin/bash
# Description: Verify the existence of the `LiteSpeed` class and list its methods.

# Test: Search for the `LiteSpeed` class and list all methods within it.
rg -A 20 'class LiteSpeed' | rg 'function'

Length of output: 163


Script:

#!/bin/bash
# Description: Extract and display the implementation of the `is_server` method in the `LiteSpeed` class.

# Test: Display the implementation of the `is_server` method.
rg -A 20 'function is_server' includes/LiteSpeed.php

Length of output: 670

views/litespeed.php (1)

1-44: New LiteSpeed Cache Admin Interface

The implementation of the LiteSpeed cache settings in the admin interface is well-done. The UI components are correctly implemented, and the conditional rendering based on the cache status is effective. Ensure that the methods like cache_enabled and purge_cache_url are robust and perform as expected.

Verification successful

New LiteSpeed Cache Admin Interface

The implementation of the LiteSpeed cache settings in the admin interface is well-done. The UI components are correctly implemented, and the conditional rendering based on the cache status is effective. The methods cache_enabled and purge_cache_url are robust and perform as expected.

  • cache_enabled is implemented in includes/LiteSpeed.php and correctly checks the cache status.
  • purge_cache_url is implemented in includes/LiteSpeed.php and correctly generates the cache purge URL.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the methods `cache_enabled` and `purge_cache_url` in the `LiteSpeed` class.

# Test: Search for the implementation of these methods. Expect: Robust and accurate functionality.
ast-grep --lang php --pattern $'class LiteSpeed {
  $$$
  cache_enabled($_) {
    $$$
  }
  purge_cache_url($_) {
    $$$
  }
  $$$  
}'

Length of output: 244


Script:

#!/bin/bash
# Description: Verify the methods `cache_enabled` and `purge_cache_url` in the `LiteSpeed` class using ripgrep.

# Search for the implementation of the `cache_enabled` method in PHP files.
rg 'function cache_enabled' --lang php -A 10

# Search for the implementation of the `purge_cache_url` method in PHP files.
rg 'function purge_cache_url' --lang php -A 10

Length of output: 913


Script:

#!/bin/bash
# Description: Verify the methods `cache_enabled` and `purge_cache_url` in the `LiteSpeed` class using ripgrep.

# Search for the implementation of the `cache_enabled` method in PHP files.
rg 'function cache_enabled' -A 10

# Search for the implementation of the `purge_cache_url` method in PHP files.
rg 'function purge_cache_url' -A 10

Length of output: 2210

Tools
GitHub Check: Run PHPCS inspection

[warning] 37-37:
Found precision alignment of 1 spaces.

includes/LiteSpeed.php (8)

3-3: Namespace declaration is correct.

The namespace FlyWP is properly defined, ensuring class scope is maintained correctly within the plugin.


5-88: Class LiteSpeed well-structured for cache management.

The class is designed to encapsulate functionalities specific to LiteSpeed cache management, which aligns with the principles of single responsibility and modularity.

Tools
GitHub Check: Run PHPCS inspection

[failure] 16-16:
$_SERVER data not unslashed before sanitization. Use wp_unslash() or similar


7-8: Constant declarations are appropriate.

Using constants for plugin slug and settings key is a good practice as it avoids hard-coding strings multiple times, which can lead to errors and makes the code easier to maintain.


24-26: Method is_plugin_active correctly checks plugin status.

This method utilizes WordPress's is_plugin_active function, which is the correct approach to check for an active plugin.


28-36: Method is_plugin_installed handles plugin checks robustly.

The method correctly checks if the necessary function get_plugins is available and requires it if not, which is a good practice to ensure compatibility.


43-45: Method cache_enabled uses appropriate WordPress functions.

The use of get_option to check cache settings is correct and follows WordPress best practices.


52-62: Method purge_cache_url correctly handles conditional logic.

The method returns an empty string if the LiteSpeed plugin is not active, which is a safe approach to prevent errors. The URL construction uses proper namespacing and method calls.


64-87: Method settings_url provides dynamic URL based on plugin status.

This method smartly handles different scenarios (settings, activation, installation) with appropriate URLs, which enhances user experience by providing context-specific actions.

flywp.php (1)

105-112: Initialization of new class instances within init_plugin.

The addition of the LiteSpeed instance along with other class instances is appropriate and follows the constructor injection pattern, which is good for dependency management.

Comment on lines 15 to 17
public function is_server() {
return isset( $_SERVER['SERVER_SOFTWARE'] ) && false !== strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' );
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security issue: Unsanitized $_SERVER data.

The method is_server uses $_SERVER['SERVER_SOFTWARE'] directly. According to the static analysis, this data should be unslashed before usage to prevent potential security issues.

- return isset( $_SERVER['SERVER_SOFTWARE'] ) && false !== strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' );
+ return isset( $_SERVER['SERVER_SOFTWARE'] ) && false !== strpos( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ), 'LiteSpeed' );
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public function is_server() {
return isset( $_SERVER['SERVER_SOFTWARE'] ) && false !== strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' );
}
public function is_server() {
return isset( $_SERVER['SERVER_SOFTWARE'] ) && false !== strpos( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ), 'LiteSpeed' );
}
Tools
GitHub Check: Run PHPCS inspection

[failure] 16-16:
$_SERVER data not unslashed before sanitization. Use wp_unslash() or similar

flywp.php Outdated
Comment on lines 149 to 151
public function is_nginx() {
return isset( $_SERVER['SERVER_SOFTWARE'] ) && false !== strpos( $_SERVER['SERVER_SOFTWARE'], 'nginx' );
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security issue: Unsanitized $_SERVER data in is_nginx.

Similar to the issue in LiteSpeed.php, the $_SERVER['SERVER_SOFTWARE'] data should be unslashed before usage to prevent potential security issues.

- return isset( $_SERVER['SERVER_SOFTWARE'] ) && false !== strpos( $_SERVER['SERVER_SOFTWARE'], 'nginx' );
+ return isset( $_SERVER['SERVER_SOFTWARE'] ) && false !== strpos( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ), 'nginx' );
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public function is_nginx() {
return isset( $_SERVER['SERVER_SOFTWARE'] ) && false !== strpos( $_SERVER['SERVER_SOFTWARE'], 'nginx' );
}
public function is_nginx() {
return isset( $_SERVER['SERVER_SOFTWARE'] ) && false !== strpos( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ), 'nginx' );
}
Tools
GitHub Check: Run PHPCS inspection

[failure] 150-150:
$_SERVER data not unslashed before sanitization. Use wp_unslash() or similar


[failure] 150-150:
Detected usage of a non-sanitized input variable: $_SERVER['SERVER_SOFTWARE']

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between abfaebd and 2f16541.

Files selected for processing (10)
  • flywp.php (2 hunks)
  • includes/Admin.php (1 hunks)
  • includes/Admin/Litespeed.php (1 hunks)
  • includes/Api/Cache.php (1 hunks)
  • includes/FlyApi.php (1 hunks)
  • includes/Helper.php (1 hunks)
  • includes/LiteSpeed.php (1 hunks)
  • views/admin.php (2 hunks)
  • views/litespeed.php (1 hunks)
  • views/page-cache.php (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • flywp.php
  • includes/Api/Cache.php
  • includes/LiteSpeed.php
  • views/admin.php
Additional context used
GitHub Check: Run PHPCS inspection
includes/Admin/Litespeed.php

[failure] 50-50:
$_GET data not unslashed before sanitization. Use wp_unslash() or similar


[failure] 50-50:
Detected usage of a non-sanitized input variable: $_GET['_wpnonce']


[failure] 59-59:
Not using strict comparison for in_array; supply true for third argument.


[failure] 59-59:
$_GET data not unslashed before sanitization. Use wp_unslash() or similar


[failure] 59-59:
Detected usage of a non-sanitized input variable: $_GET['type']

views/litespeed.php

[warning] 10-10:
Processing form data without nonce verification.


[warning] 10-10:
Processing form data without nonce verification.


[warning] 11-11:
Processing form data without nonce verification.


[warning] 67-67:
Found precision alignment of 1 spaces.

Additional comments not posted (14)
includes/Helper.php (2)

33-35: Ensure proper sanitization of server software information.

The method correctly checks if the server is running Nginx. Ensure that wp_unslash is used to sanitize $_SERVER['SERVER_SOFTWARE'].


42-44: Ensure proper sanitization of server software information.

The method correctly checks if the server is running LiteSpeed. Ensure that wp_unslash is used to sanitize $_SERVER['SERVER_SOFTWARE'].

includes/Admin/Litespeed.php (2)

16-18: Constructor looks good.

The constructor correctly adds an action hook for handling enable/disable actions.


27-37: URL generation method looks good.

The method correctly generates a URL for enabling or disabling LiteSpeed cache.

includes/FlyApi.php (1)

23-30: Method update looks good.

The method correctly accepts an additional parameter type and sends it in the POST request.

views/litespeed.php (4)

22-33: Status display looks good.

The section correctly displays the LiteSpeed cache status.


36-40: Notice display looks good.

The section correctly displays notices based on the notice variable.


42-45: Description display looks good.

The section correctly displays a description of LiteSpeed cache.


55-71: Action buttons look good.

The section correctly displays action buttons for enabling/disabling and clearing LiteSpeed cache.

Tools
GitHub Check: Run PHPCS inspection

[warning] 67-67:
Found precision alignment of 1 spaces.

includes/Admin.php (4)

10-10: LGTM! Making the constant public.

The constant PAGE_SLUG is now public. Ensure this change is intentional and necessary.


17-17: LGTM! Making the constant public.

The constant SCREEN_NAME is now public. Ensure this change is intentional and necessary.


19-20: LGTM! Adding new property.

The property $litespeed has been added. Ensure this change is intentional and necessary.


28-29: LGTM! Updating property assignments.

The properties $fastcgi and $litespeed are now assigned instances of their respective classes. Ensure these changes are intentional and necessary.

views/page-cache.php (1)

39-39: LGTM! Updating CSS class.

The CSS class for the div element has been updated to include fly-form-notice. Ensure this change is intentional and necessary.

}

$valid_types = [ 'enable', 'disable' ];
$type = isset( $_GET['type'] ) && in_array( $_GET['type'], $valid_types ) ? $_GET['type'] : 'enable';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanitize and unslash $_GET data.

Ensure that $_GET data is unslashed and sanitized before usage.

-        $type        = isset( $_GET['type'] ) && in_array( $_GET['type'], $valid_types ) ? $_GET['type'] : 'enable';
+        $type        = isset( $_GET['type'] ) && in_array( wp_unslash( $_GET['type'] ), $valid_types, true ) ? wp_unslash( $_GET['type'] ) : 'enable';
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$type = isset( $_GET['type'] ) && in_array( $_GET['type'], $valid_types ) ? $_GET['type'] : 'enable';
$type = isset( $_GET['type'] ) && in_array( wp_unslash( $_GET['type'] ), $valid_types, true ) ? wp_unslash( $_GET['type'] ) : 'enable';
Tools
GitHub Check: Run PHPCS inspection

[failure] 59-59:
Not using strict comparison for in_array; supply true for third argument.


[failure] 59-59:
$_GET data not unslashed before sanitization. Use wp_unslash() or similar


[failure] 59-59:
Detected usage of a non-sanitized input variable: $_GET['type']


Use strict comparison for in_array.

Ensure that strict comparison is used for in_array.

-        $type        = isset( $_GET['type'] ) && in_array( $_GET['type'], $valid_types ) ? $_GET['type'] : 'enable';
+        $type        = isset( $_GET['type'] ) && in_array( $_GET['type'], $valid_types, true ) ? $_GET['type'] : 'enable';
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$type = isset( $_GET['type'] ) && in_array( $_GET['type'], $valid_types ) ? $_GET['type'] : 'enable';
$type = isset( $_GET['type'] ) && in_array( $_GET['type'], $valid_types, true ) ? $_GET['type'] : 'enable';
Tools
GitHub Check: Run PHPCS inspection

[failure] 59-59:
Not using strict comparison for in_array; supply true for third argument.


[failure] 59-59:
$_GET data not unslashed before sanitization. Use wp_unslash() or similar


[failure] 59-59:
Detected usage of a non-sanitized input variable: $_GET['type']

Comment on lines 45 to 51
public function handle_enable_disable() {
if ( ! isset( $_GET['flywp-action'] ) || 'toggle-lscache' !== $_GET['flywp-action'] ) {
return;
}

if ( isset( $_GET['_wpnonce'] ) && ! wp_verify_nonce( $_GET['_wpnonce'], 'flywp-litespeed-nonce' ) ) {
return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanitize and unslash $_GET data.

Ensure that $_GET data is unslashed and sanitized before usage.

-        if ( isset( $_GET['_wpnonce'] ) && ! wp_verify_nonce( $_GET['_wpnonce'], 'flywp-litespeed-nonce' ) ) {
+        if ( isset( $_GET['_wpnonce'] ) && ! wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), 'flywp-litespeed-nonce' ) ) {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public function handle_enable_disable() {
if ( ! isset( $_GET['flywp-action'] ) || 'toggle-lscache' !== $_GET['flywp-action'] ) {
return;
}
if ( isset( $_GET['_wpnonce'] ) && ! wp_verify_nonce( $_GET['_wpnonce'], 'flywp-litespeed-nonce' ) ) {
return;
public function handle_enable_disable() {
if ( ! isset( $_GET['flywp-action'] ) || 'toggle-lscache' !== $_GET['flywp-action'] ) {
return;
}
if ( isset( $_GET['_wpnonce'] ) && ! wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), 'flywp-litespeed-nonce' ) ) {
return;
Tools
GitHub Check: Run PHPCS inspection

[failure] 50-50:
$_GET data not unslashed before sanitization. Use wp_unslash() or similar


[failure] 50-50:
Detected usage of a non-sanitized input variable: $_GET['_wpnonce']

Comment on lines 10 to 12
if ( isset( $_GET['fly-notice'] ) && isset( $cache_messages[$_GET['fly-notice']] ) ) {
$notice = $cache_messages[$_GET['fly-notice']];
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanitize $_GET data.

Ensure that $_GET data is sanitized before usage.

- if ( isset( $_GET['fly-notice'] ) && isset( $cache_messages[$_GET['fly-notice']] ) ) {
-    $notice = $cache_messages[$_GET['fly-notice']];
+ if ( isset( $_GET['fly-notice'] ) && isset( $cache_messages[ sanitize_text_field( wp_unslash( $_GET['fly-notice'] ) ) ] ) ) {
+    $notice = $cache_messages[ sanitize_text_field( wp_unslash( $_GET['fly-notice'] ) ) ];
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if ( isset( $_GET['fly-notice'] ) && isset( $cache_messages[$_GET['fly-notice']] ) ) {
$notice = $cache_messages[$_GET['fly-notice']];
}
if ( isset( $_GET['fly-notice'] ) && isset( $cache_messages[ sanitize_text_field( wp_unslash( $_GET['fly-notice'] ) ) ] ) ) {
$notice = $cache_messages[ sanitize_text_field( wp_unslash( $_GET['fly-notice'] ) ) ];
}
Tools
GitHub Check: Run PHPCS inspection

[warning] 10-10:
Processing form data without nonce verification.


[warning] 10-10:
Processing form data without nonce verification.


[warning] 11-11:
Processing form data without nonce verification.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2f16541 and 33ad415.

Files selected for processing (2)
  • includes/Admin/Litespeed.php (1 hunks)
  • views/admin.php (3 hunks)
Additional context used
GitHub Check: Run PHPCS inspection
views/admin.php

[failure] 21-21:
Missing space after array opener.

includes/Admin/Litespeed.php

[failure] 50-50:
Detected usage of a non-sanitized input variable: $_GET['_wpnonce']


[failure] 59-59:
Detected usage of a non-sanitized input variable: $_GET['type']

Additional comments not posted (6)
views/admin.php (1)

32-36: LGTM!

The conditional logic to require different files based on server type is correctly implemented.

includes/Admin/Litespeed.php (5)

16-18: LGTM!

The constructor is correctly implemented and follows WordPress best practices.


27-38: LGTM!

The method is correctly implemented and follows WordPress best practices.


50-50: Sanitize and unslash $_GET data.

Ensure that $_GET data is unslashed and sanitized before usage.

-        if ( isset( $_GET['_wpnonce'] ) && ! wp_verify_nonce( $_GET['_wpnonce'], 'flywp-litespeed-nonce' ) ) {
+        if ( isset( $_GET['_wpnonce'] ) && ! wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), 'flywp-litespeed-nonce' ) ) {
Tools
GitHub Check: Run PHPCS inspection

[failure] 50-50:
Detected usage of a non-sanitized input variable: $_GET['_wpnonce']


59-59: Sanitize and unslash $_GET data.

Ensure that $_GET data is unslashed and sanitized before usage.

-        $type        = isset( $_GET['type'] ) && in_array( $_GET['type'], $valid_types ) ? $_GET['type'] : 'enable';
+        $type        = isset( $_GET['type'] ) && in_array( wp_unslash( $_GET['type'] ), $valid_types, true ) ? wp_unslash( $_GET['type'] ) : 'enable';
Tools
GitHub Check: Run PHPCS inspection

[failure] 59-59:
Detected usage of a non-sanitized input variable: $_GET['type']


45-69: LGTM!

The method is correctly implemented and follows WordPress best practices.

Tools
GitHub Check: Run PHPCS inspection

[failure] 50-50:
Detected usage of a non-sanitized input variable: $_GET['_wpnonce']


[failure] 59-59:
Detected usage of a non-sanitized input variable: $_GET['type']

views/admin.php Outdated
<a href="<?php echo esc_url( add_query_arg( [
'tab' => $key,
], $this->page_url() ) ); ?>" class="fw-block fw-px-4 fw-py-3 fw-text-sm -m fw-text-gray-800 fw-no-underline fw-outline-none focus:fw-outline-none <?php echo $key === $active_tab ? 'fw-border-b-2 fw-border-indigo-500 fw-font-semibold' : ''; ?>"><?php echo $label; ?></a>
<a href="<?php echo esc_url( add_query_arg( ['tab' => $key ], $this->page_url() ) ); ?>" class="fw-block fw-px-4 fw-py-3 fw-text-sm -m fw-text-gray-800 fw-no-underline fw-outline-none focus:fw-outline-none <?php echo $key === $active_tab ? 'fw-border-b-2 fw-border-indigo-500 fw-font-semibold' : ''; ?>"><?php echo $label; ?></a>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix missing space after array opener.

There is a missing space after the array opener in the add_query_arg function call.

-                    <a href="<?php echo esc_url( add_query_arg( ['tab' => $key ], $this->page_url() ) ); ?>" class="fw-block fw-px-4 fw-py-3 fw-text-sm -m fw-text-gray-800 fw-no-underline fw-outline-none focus:fw-outline-none <?php echo $key === $active_tab ? 'fw-border-b-2 fw-border-indigo-500 fw-font-semibold' : ''; ?>"><?php echo $label; ?></a>
+                    <a href="<?php echo esc_url( add_query_arg( [ 'tab' => $key ], $this->page_url() ) ); ?>" class="fw-block fw-px-4 fw-py-3 fw-text-sm -m fw-text-gray-800 fw-no-underline fw-outline-none focus:fw-outline-none <?php echo $key === $active_tab ? 'fw-border-b-2 fw-border-indigo-500 fw-font-semibold' : ''; ?>"><?php echo $label; ?></a>
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<a href="<?php echo esc_url( add_query_arg( ['tab' => $key ], $this->page_url() ) ); ?>" class="fw-block fw-px-4 fw-py-3 fw-text-sm -m fw-text-gray-800 fw-no-underline fw-outline-none focus:fw-outline-none <?php echo $key === $active_tab ? 'fw-border-b-2 fw-border-indigo-500 fw-font-semibold' : ''; ?>"><?php echo $label; ?></a>
<a href="<?php echo esc_url( add_query_arg( [ 'tab' => $key ], $this->page_url() ) ); ?>" class="fw-block fw-px-4 fw-py-3 fw-text-sm -m fw-text-gray-800 fw-no-underline fw-outline-none focus:fw-outline-none <?php echo $key === $active_tab ? 'fw-border-b-2 fw-border-indigo-500 fw-font-semibold' : ''; ?>"><?php echo $label; ?></a>
Tools
GitHub Check: Run PHPCS inspection

[failure] 21-21:
Missing space after array opener.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 33ad415 and 902ac0b.

Files selected for processing (7)
  • includes/Admin.php (2 hunks)
  • includes/Admin/Litespeed.php (1 hunks)
  • includes/Api.php (2 hunks)
  • views/admin.php (3 hunks)
  • views/litespeed.php (1 hunks)
  • views/op-cache.php (1 hunks)
  • views/page-cache.php (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • includes/Admin.php
  • includes/Api.php
  • views/admin.php
Additional context used
GitHub Check: Run PHPCS inspection
includes/Admin/Litespeed.php

[failure] 51-51:
Detected usage of a non-sanitized input variable: $_GET['_wpnonce']


[failure] 62-62:
Detected usage of a non-sanitized input variable: $_GET['type']

views/litespeed.php

[warning] 10-10:
Processing form data without nonce verification.


[warning] 10-10:
Processing form data without nonce verification.


[warning] 11-11:
Processing form data without nonce verification.


[failure] 11-11:
$_GET data not unslashed before sanitization. Use wp_unslash() or similar


[failure] 11-11:
Detected usage of a non-sanitized input variable: $_GET['fly-notice']


[warning] 67-67:
Found precision alignment of 1 spaces.

views/op-cache.php

[warning] 11-11:
Processing form data without nonce verification.


[warning] 11-11:
Processing form data without nonce verification.


[warning] 12-12:
Processing form data without nonce verification.


[failure] 12-12:
$_GET data not unslashed before sanitization. Use wp_unslash() or similar


[failure] 12-12:
Detected usage of a non-sanitized input variable: $_GET['fly-notice']

views/page-cache.php

[warning] 12-12:
Processing form data without nonce verification.


[warning] 12-12:
Processing form data without nonce verification.


[warning] 13-13:
Processing form data without nonce verification.


[failure] 13-13:
$_GET data not unslashed before sanitization. Use wp_unslash() or similar

Additional comments not posted (13)
includes/Admin/Litespeed.php (4)

16-18: LGTM!

The constructor correctly adds an action hook for handling enable/disable actions.


27-37: LGTM!

The method correctly generates a URL with a nonce for enabling/disabling LiteSpeed cache.


51-51: Sanitize and unslash $_GET data.

Ensure that $_GET data is unslashed and sanitized before usage.

-        if ( isset( $_GET['_wpnonce'] ) && ! wp_verify_nonce( $_GET['_wpnonce'], 'flywp-litespeed-nonce' ) ) {
+        if ( isset( $_GET['_wpnonce'] ) && ! wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), 'flywp-litespeed-nonce' ) ) {
Tools
GitHub Check: Run PHPCS inspection

[failure] 51-51:
Detected usage of a non-sanitized input variable: $_GET['_wpnonce']


62-62: Sanitize and unslash $_GET data.

Ensure that $_GET data is unslashed and sanitized before usage.

-        $type        = isset( $_GET['type'] ) && in_array( $_GET['type'], $valid_types ) ? $_GET['type'] : 'enable';
+        $type        = isset( $_GET['type'] ) && in_array( wp_unslash( $_GET['type'] ), $valid_types, true ) ? wp_unslash( $_GET['type'] ) : 'enable';
Tools
GitHub Check: Run PHPCS inspection

[failure] 62-62:
Detected usage of a non-sanitized input variable: $_GET['type']

views/litespeed.php (3)

10-12: Sanitize $_GET data.

Ensure that $_GET data is sanitized before usage.

- if ( isset( $_GET['fly-notice'] ) && isset( $cache_messages[$_GET['fly-notice']] ) ) {
-    $notice = $cache_messages[$_GET['fly-notice']];
+ if ( isset( $_GET['fly-notice'] ) && isset( $cache_messages[ sanitize_text_field( wp_unslash( $_GET['fly-notice'] ) ) ] ) ) {
+    $notice = $cache_messages[ sanitize_text_field( wp_unslash( $_GET['fly-notice'] ) ) ];
Tools
GitHub Check: Run PHPCS inspection

[warning] 10-10:
Processing form data without nonce verification.


[warning] 10-10:
Processing form data without nonce verification.


[warning] 11-11:
Processing form data without nonce verification.


[failure] 11-11:
$_GET data not unslashed before sanitization. Use wp_unslash() or similar


[failure] 11-11:
Detected usage of a non-sanitized input variable: $_GET['fly-notice']


22-33: LGTM!

The segment correctly displays the LiteSpeed cache status.


36-71: LGTM!

The segment correctly displays notices and provides links for cache management and settings.

Tools
GitHub Check: Run PHPCS inspection

[warning] 67-67:
Found precision alignment of 1 spaces.

views/op-cache.php (3)

11-12: Sanitize $_GET data.

Ensure that $_GET data is sanitized before usage.

- if ( isset( $_GET['fly-notice'] ) && isset( $cache_messages[$_GET['fly-notice']] ) ) {
-    $notice = $cache_messages[$_GET['fly-notice']];
+ if ( isset( $_GET['fly-notice'] ) && isset( $cache_messages[ sanitize_text_field( wp_unslash( $_GET['fly-notice'] ) ) ] ) ) {
+    $notice = $cache_messages[ sanitize_text_field( wp_unslash( $_GET['fly-notice'] ) ) ];
Tools
GitHub Check: Run PHPCS inspection

[warning] 11-11:
Processing form data without nonce verification.


[warning] 11-11:
Processing form data without nonce verification.


[warning] 12-12:
Processing form data without nonce verification.


[failure] 12-12:
$_GET data not unslashed before sanitization. Use wp_unslash() or similar


[failure] 12-12:
Detected usage of a non-sanitized input variable: $_GET['fly-notice']


Line range hint 20-33:
LGTM!

The segment correctly displays the OPcache status.

Tools
GitHub Check: Run PHPCS inspection

[warning] 11-11:
Processing form data without nonce verification.


[warning] 11-11:
Processing form data without nonce verification.


[warning] 12-12:
Processing form data without nonce verification.


[failure] 12-12:
$_GET data not unslashed before sanitization. Use wp_unslash() or similar


[failure] 12-12:
Detected usage of a non-sanitized input variable: $_GET['fly-notice']


Line range hint 36-71:
LGTM!

The segment correctly displays notices and provides links for cache management and settings.

Tools
GitHub Check: Run PHPCS inspection

[warning] 11-11:
Processing form data without nonce verification.


[warning] 11-11:
Processing form data without nonce verification.


[warning] 12-12:
Processing form data without nonce verification.


[failure] 12-12:
$_GET data not unslashed before sanitization. Use wp_unslash() or similar


[failure] 12-12:
Detected usage of a non-sanitized input variable: $_GET['fly-notice']

views/page-cache.php (3)

12-13: Sanitize $_GET data.

Ensure that $_GET data is sanitized before usage.

- if ( isset( $_GET['fly-notice'] ) && isset( $cache_messages[$_GET['fly-notice']] ) ) {
-    $notice = $cache_messages[$_GET['fly-notice']];
+ if ( isset( $_GET['fly-notice'] ) && isset( $cache_messages[ sanitize_text_field( wp_unslash( $_GET['fly-notice'] ) ) ] ) ) {
+    $notice = $cache_messages[ sanitize_text_field( wp_unslash( $_GET['fly-notice'] ) ) ];
Tools
GitHub Check: Run PHPCS inspection

[warning] 12-12:
Processing form data without nonce verification.


[warning] 12-12:
Processing form data without nonce verification.


[warning] 13-13:
Processing form data without nonce verification.


[failure] 13-13:
$_GET data not unslashed before sanitization. Use wp_unslash() or similar


Line range hint 20-33:
LGTM!

The segment correctly displays the page cache status.

Tools
GitHub Check: Run PHPCS inspection

[warning] 12-12:
Processing form data without nonce verification.


[warning] 12-12:
Processing form data without nonce verification.


[warning] 13-13:
Processing form data without nonce verification.


[failure] 13-13:
$_GET data not unslashed before sanitization. Use wp_unslash() or similar


Line range hint 36-71:
LGTM!

The segment correctly displays notices and provides links for cache management and settings.

@tareq1988 tareq1988 merged commit 1e79767 into develop Jul 18, 2024
1 check failed
@tareq1988 tareq1988 deleted the litespeed branch July 18, 2024 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant