From 11b53fcbbb586afa2738c03446d7253ee8d4f15e Mon Sep 17 00:00:00 2001 From: Filip Ilic Date: Thu, 10 Apr 2025 13:31:03 +0200 Subject: [PATCH 1/4] minor bugfixes & improvements --- assets/images/cloudflare_icon.svg | 6 ++++++ classes/class-base.php | 19 ++++++++++++++----- cloudflare-utils.php | 3 +++ 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 assets/images/cloudflare_icon.svg diff --git a/assets/images/cloudflare_icon.svg b/assets/images/cloudflare_icon.svg new file mode 100644 index 0000000..fd43c59 --- /dev/null +++ b/assets/images/cloudflare_icon.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/classes/class-base.php b/classes/class-base.php index 4f76862..22399d7 100644 --- a/classes/class-base.php +++ b/classes/class-base.php @@ -445,7 +445,7 @@ public function add_toolbar_button( $wp_admin_bar ) { 'id' => 'set_cloudflare_zone_id', 'title' => \esc_html__( 'Set Cloudflare zone settings', 'pp-cf-utils' ), 'parent' => 'cloudflare', - 'href' => \admin_url( 'options-general.php?page=pp-cf-utils' ), + 'href' => \admin_url( 'options-general.php?page=pp-cloudflare-utils' ), ] ); return; @@ -496,7 +496,7 @@ public function toolbar_icon_styles() { height: 20px; padding: 4px; display: inline-block; - background-image: url(' . \esc_url( \plugin_dir_url( __FILE__ ) . 'cloudflare_icon.svg' ) . ') !important; + background-image: url(' . \esc_url( PP_CF_UTILS_URL . '/assets/images/cloudflare_icon.svg' ) . ') !important; background-size: contain; }' ); @@ -552,11 +552,20 @@ public function ajax_clear_cloudflare_cache() { \check_ajax_referer( 'clear_cloudflare_cache_nonce', 'nonce' ); if ( isset( $_POST['url'] ) && ! empty( $_POST['url'] ) ) { - $this->clear_cloudflare_cache( \sanitize_text_field( \wp_unslash( $_POST['url'] ) ) ); + $result = $this->clear_cloudflare_cache( \sanitize_text_field( \wp_unslash( $_POST['url'] ) ) ); } else { - $this->clear_cloudflare_cache(); + $result = $this->clear_cloudflare_cache(); + } + + // $result is: + // $wp_error->get_message() if request failed or + // response code if request was successfuly made. + + if ( $result === 200 ) { + \wp_send_json_success( [ 'message' => \esc_html__( 'Cloudflare cache cleared successfully.', 'pp-cf-utils' ) ] ); + } else { + \wp_send_json_error( [ 'message' => \esc_html__( 'Cloudflare cache clear failed, check error log for more details.', 'pp-cf-utils' ) ] ); } - \wp_send_json_success( [ 'message' => \esc_html__( 'Cloudflare cache cleared successfully.', 'pp-cf-utils' ) ] ); } /** diff --git a/cloudflare-utils.php b/cloudflare-utils.php index 955729b..3257b07 100644 --- a/cloudflare-utils.php +++ b/cloudflare-utils.php @@ -14,6 +14,9 @@ exit; } +define( 'PP_CF_UTILS_DIR', __DIR__ ); +define( 'PP_CF_UTILS_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) ); + /** * Load the plugin. */ From 2e090363802a70cd1d3c6a0eee1dec9e1a15cf18 Mon Sep 17 00:00:00 2001 From: Filip Ilic Date: Thu, 10 Apr 2025 13:42:00 +0200 Subject: [PATCH 2/4] define prefix --- phpcs.xml.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 759a087..f92a63d 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -107,6 +107,7 @@ + From 01d6931da4023d009e3d280279773f06b277c340 Mon Sep 17 00:00:00 2001 From: Filip Ilic Date: Thu, 10 Apr 2025 13:59:42 +0200 Subject: [PATCH 3/4] recognize constants? --- cloudflare-utils.php | 2 +- phpstan.neon.dist | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cloudflare-utils.php b/cloudflare-utils.php index 3257b07..942e5cc 100644 --- a/cloudflare-utils.php +++ b/cloudflare-utils.php @@ -20,5 +20,5 @@ /** * Load the plugin. */ -require_once __DIR__ . '/classes/class-base.php'; +require_once PP_CF_UTILS_DIR . '/classes/class-base.php'; new PP_Cloudflare_Utils\Base(); diff --git a/phpstan.neon.dist b/phpstan.neon.dist index fb7c8cb..f63f1d6 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -4,4 +4,6 @@ parameters: paths: - ./cloudflare-utils.php - ./classes + bootstrapFiles: + - ./cloudflare-utils.php ignoreErrors: \ No newline at end of file From 989249e5648dbb83d6b1a9f0361baedb37891089 Mon Sep 17 00:00:00 2001 From: Filip Ilic Date: Thu, 10 Apr 2025 14:05:05 +0200 Subject: [PATCH 4/4] dont mix tabs & spaces --- phpstan.neon.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index f63f1d6..5346d96 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -4,6 +4,6 @@ parameters: paths: - ./cloudflare-utils.php - ./classes - bootstrapFiles: + bootstrapFiles: - ./cloudflare-utils.php ignoreErrors: \ No newline at end of file