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..942e5cc 100644 --- a/cloudflare-utils.php +++ b/cloudflare-utils.php @@ -14,8 +14,11 @@ exit; } +define( 'PP_CF_UTILS_DIR', __DIR__ ); +define( 'PP_CF_UTILS_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) ); + /** * 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/phpcs.xml.dist b/phpcs.xml.dist index 759a087..f92a63d 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -107,6 +107,7 @@ + diff --git a/phpstan.neon.dist b/phpstan.neon.dist index fb7c8cb..5346d96 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