From d07c9d0695db8f0ca9b61de2f71db5a6dff5dd0d Mon Sep 17 00:00:00 2001 From: Ben Marshall Date: Thu, 7 Mar 2024 12:05:00 -0600 Subject: [PATCH] fix(cloudflare): fixing bad calls to some methods --- core/class-access.php | 20 +++++++++----------- modules/comments/class-comments.php | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/core/class-access.php b/core/class-access.php index ea2a56e..7502aa6 100644 --- a/core/class-access.php +++ b/core/class-access.php @@ -24,7 +24,12 @@ public function __construct() { } /** - * Fires after WordPress has finished loading but before any headers are sent. + * Initializes the class by setting up hooks and actions. + * + * This method is called during the WordPress initialization process. It + * registers the 'template_redirect' action to perform access checks and + * adds a filter for 'zerospam_access_checks' to determine if the current + * request should be blocked. */ public function init() { if ( ! is_admin() && is_main_query() && self::process() ) { @@ -48,7 +53,7 @@ public function init() { * @param int $code Optional. The HTTP status code to be sent in the header. * Defaults to 403 to indicate a Forbidden error. */ - public static function die( $title, $message, $code = 403 ) { + public static function terminate_execution( $title, $message, $code = 403 ) { header( 'Cache-Control: no-store, no-cache, must-revalidate, max-age=0' ); header( 'Cache-Control: post-check=0, pre-check=0', false ); header( 'Pragma: no-cache' ); @@ -118,19 +123,12 @@ public function access_check() { if ( ! empty( $settings['block_handler']['value'] ) ) { switch ( $settings['block_handler']['value'] ) { case 403: - add_action( 'send_headers', [ $this, 'prevent_cache_on_error_condition' ] ); - $message = __( 'Your IP address has been blocked due to detected spam/malicious activity.', 'zero-spam' ); if ( ! empty( $settings['blocked_message']['value'] ) ) { $message = $settings['blocked_message']['value']; } - wp_die( - $message, - __( 'Blocked', 'zero-spam' ), - array( - 'response' => 403, - ) - ); + + self::terminate_execution( __( 'Blocked', 'zero-spam' ), $message ); break; case 'redirect': $url = 'https://wordpress.org/plugins/zero-spam/'; diff --git a/modules/comments/class-comments.php b/modules/comments/class-comments.php index be7dd23..7efead5 100644 --- a/modules/comments/class-comments.php +++ b/modules/comments/class-comments.php @@ -171,7 +171,7 @@ public function preprocess_comments( $commentdata ) { } } - \ZeroSpam\Core\Access::die( + \ZeroSpam\Core\Access::terminate_execution( \ZeroSpam\Core\Utilities::detection_title( 'comment_spam_message' ), $error_message );