Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions assets/images/cloudflare_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 14 additions & 5 deletions classes/class-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}'
);
Expand Down Expand Up @@ -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' ) ] );
}

/**
Expand Down
5 changes: 4 additions & 1 deletion cloudflare-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<properties>
<property name="prefixes" type="array">
<element value="PP_Cloudflare_Utils"/>
<element value="PP_CF_UTILS"/>
</property>
</properties>
</rule>
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ parameters:
paths:
- ./cloudflare-utils.php
- ./classes
bootstrapFiles:
- ./cloudflare-utils.php
ignoreErrors:
Loading