Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
IRV-384: implement review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Reckart committed Jul 27, 2020
1 parent e4e2234 commit be68a7e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
11 changes: 7 additions & 4 deletions inc/endpoints/class-cache-endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ public function get_route_response( $request ) {

// Ensure the action exists prior to firing.
if ( ! empty( $action ) ) {
$response = new \WP_REST_Response( true );
$response = [
'success' => true,
'message' => __( 'Cache purged successfully.', 'wp-irving' ),
];

if ( 'irving_site_cache_purge' === $action ) {
do_action( 'wp_irving_site_cache_purge' );

return $response;
return new \WP_REST_Response( $response );
}

if ( 'irving_page_cache_purge' === $action ) {
Expand All @@ -67,12 +70,12 @@ public function get_route_response( $request ) {
if ( ! empty( $route ) ) {
do_action( 'wp_irving_page_cache_purge', $route );

return $response;
return new \WP_REST_Response( $response );
}
}
}

$response = new \WP_REST_Response( false );
$response = new \WP_Error( 500, __( 'There was an error clearing the cache. Please check the network tab in the developer console for more information.', 'wp-irving' ) );

return $response;
}
Expand Down
15 changes: 4 additions & 11 deletions inc/templates/admin-bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,20 +394,13 @@ function cache_purge_click_listener() {
$rest_endpoint = site_url( '/wp-json/irving/v1/purge-cache' );
?>
<script type="text/javascript">
function formatAlert(response) {
if (response === true) {
return 'Cache purged sucessfully';
}
return 'There was an error clearing the cache.\nPlease check the network tab in the developer console for more information.';
}

jQuery('#wp-admin-bar-irving-cache-one').on('click', function() {
const data = { 'action': 'irving_site_cache_purge' };
jQuery.post(
'<?php echo esc_url( $rest_endpoint ); ?>',
data,
function(response) { alert(formatAlert(response)); }
);
function(response) { alert(response.message); }
).fail(function(error) { alert(error.responseJSON.message); });;
});
jQuery('#wp-admin-bar-irving-cache-two').on('click', function() {
const data = {
Expand All @@ -417,8 +410,8 @@ function(response) { alert(formatAlert(response)); }
jQuery.post(
'<?php echo esc_url( $rest_endpoint ); ?>',
data,
function(response) { alert(formatAlert(response)); }
);
function(response) { alert(response.message); }
).fail(function(error) { alert(error.responseJSON.message); });
});
</script>
<?php
Expand Down

0 comments on commit be68a7e

Please sign in to comment.