Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Commit

Permalink
feat(htmlpurifier): add UI button for purge
Browse files Browse the repository at this point in the history
  • Loading branch information
luisherranz committed Sep 11, 2018
1 parent c3d6051 commit 518772e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
22 changes: 22 additions & 0 deletions admin/js/wp-pwa-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,28 @@ jQuery(document).on('ready', function () {
});
});

jQuery('#wp-pwa-purge-htmlpurifier-cache').on('click', function(e) {
jQuery.ajax({
url: ajaxurl,
method: "POST",
data: {
action: 'wp_pwa_purge_htmlpurifier_cache',
},
success: function (response) {
if (response.hasOwnProperty('status') && response.status == 'ok' ) {
alert('HtmlPurifier cache purged successfully.');
} else if( response.hasOwnProperty('status') && response.status == 'error') {
alert('Something went wrong. Please repeat and if it doesn\'t work contact with support@frontity.com.');
console.log(response);
}
},
error: function (response) {
alert('Something went wrong. Please repeat and if it doesn\'t work contact with support@frontity.com.');
console.log(response);
}
});
});

jQuery('#change-advanced-settings').on('click', function(e) {
jQuery('#change-advanced-settings').addClass('is-loading');
e.preventDefault();
Expand Down
10 changes: 10 additions & 0 deletions admin/wp-pwa-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,16 @@
</fieldset>
</td>
</tr>
<tr>
<th scope="row">HtmlPurifier</th>
<td>
<fieldset>
<label>
<input type="button" id="wp-pwa-purge-htmlpurifier-cache" value="Purge cache"/>
</label>
</fieldset>
</td>
</tr>
</table>
<p>
<a href="#" id="change-advanced-settings"class="button button-lg">Save changes</a>
Expand Down
9 changes: 7 additions & 2 deletions wp-pwa.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function __construct()
add_action('wp_ajax_wp_pwa_change_siteid',array($this,'change_siteid_ajax'));
add_action('wp_ajax_wp_pwa_change_advanced_settings',array($this,'change_advanced_settings_ajax'));
add_action('wp_ajax_wp_pwa_save_excludes',array($this,'save_excludes_ajax'));
add_action('wp_ajax_wp_pwa_purge_htmlpurifier_cache', array($this,'purge_htmlpurifier_cache'));

add_action('plugins_loaded', array($this,'wp_rest_api_plugin_is_installed'));
add_action('plugins_loaded', array($this,'wp_rest_api_plugin_is_active'));
Expand Down Expand Up @@ -345,14 +346,18 @@ function rrmdir($dir) {
}
}

function reset_purifier_cache() {
function purge_htmlpurifier_cache() {
$upload = wp_upload_dir();
$upload_base = $upload['basedir'];
$htmlpurifier_dir = $upload_base . DS . 'frontity'. DS . 'htmlpurifier';
$this->rrmdir($htmlpurifier_dir . DS . 'HTML');
$this->rrmdir($htmlpurifier_dir . DS . 'CSS');
$this->rrmdir($htmlpurifier_dir . DS . 'URI');
}
wp_send_json( array(
'status' => 'ok',
));
}


function init()
{
Expand Down

0 comments on commit 518772e

Please sign in to comment.