Skip to content
This repository has been archived by the owner on Feb 23, 2019. It is now read-only.

Commit

Permalink
Reapply Add a dashboard widget for flushing URL's
Browse files Browse the repository at this point in the history
Closes #303
  • Loading branch information
szepeviktor committed Jan 19, 2017
1 parent 44d6737 commit f098003
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 0 deletions.
101 changes: 101 additions & 0 deletions Generic_Plugin_PageCachePurge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
namespace W3TC;
/**
* Purge page caches by URL
*/



/**
* Class Generic_Plugin_PageCachePurge
*/
class Generic_Plugin_PageCachePurge {
/**
* Array of urls
*
* @var array
*/
var $_urls = array();

/**
* Config
*/
private $_config = null;

function __construct() {
$this->_config = Dispatcher::config();
}

/**
* Runs plugin
*/
function run() {
if(! $this->_config->get_boolean( 'pgcache.enabled' )) {
// page cache is not enabled
return;
}

if ( Util_Admin::get_current_wp_page() == 'w3tc_dashboard' )
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );


add_action( 'w3tc_widget_setup', array(
$this,
'wp_dashboard_setup'
) );
add_action( 'w3tc_network_dashboard_setup', array(
$this,
'wp_dashboard_setup'
) );

if ( is_admin() ) {
add_action( 'wp_ajax_w3tc_action_purge_urls', array( $this, 'action_purge_urls' ) );
}

}

/**
* Dashboard setup action
*
* @return void
*/
function wp_dashboard_setup() {

Util_Widget::add( 'w3tc_page_cache_purge',
'<div class="w3tc-widget-text">' .
__( 'Purge Page Caches', 'w3-total-cache' ) .
'</div>',
array( $this, 'widget_form' ),
null, 'normal' );
}

function widget_form() {
include W3TC_INC_WIDGET_DIR . '/pagepurge.php';
}

function action_purge_urls() {


$urls = Util_Request::get_array( 'purge_urls' );
$Flusher = new PgCache_Flush();

$cache = $Flusher->_get_cache();
$mobile_groups = $Flusher->_get_mobile_groups();
$referrer_groups = $Flusher->_get_referrer_groups();
$encryptions = $Flusher->_get_encryptions();
$compressions = $Flusher->_get_compressions();

foreach ( $urls as $url ) {
$Flusher->_flush_url( $url, $cache, $mobile_groups,
$referrer_groups, $encryptions, $compressions );
}
echo 'URL(s) successfully flushed';
wp_die();
}

public function enqueue() {
wp_enqueue_style( 'w3tc-widget' );
wp_enqueue_script( 'w3tc-metadata' );
wp_enqueue_script( 'w3tc-widget' );
}
}
1 change: 1 addition & 0 deletions Root_Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function __construct() {
$plugins[] = new UsageStatistics_Plugin();

if ( is_admin() ) {
$plugins[] = new Generic_Plugin_PageCachePurge();
$plugins[] = new Generic_Plugin_Admin();
$plugins[] = new BrowserCache_Plugin_Admin();
$plugins[] = new DbCache_Plugin_Admin();
Expand Down
14 changes: 14 additions & 0 deletions inc/widget/pagepurge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace W3TC;

if ( !defined( 'W3TC' ) )
die();

?>
<form action="" xmlns="http://www.w3.org/1999/html" method="post">
<textarea id="purge_urls" name="purge_urls"></textarea>
<p> Enter each URL on a new line </p>
<p>
<input id="submit_purge_urls" type="submit" class="button button-primary button-large" value="<?php _e( 'Purge', 'w3-total-cache' ) ?>"/>
</p>
</form>
14 changes: 14 additions & 0 deletions pub/js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,19 @@ jQuery(function() {
jQuery('#buy-w3-service-area').empty();
jQuery('#buy-w3-service').attr("disabled", "disabled");
});

jQuery('#submit_purge_urls').click(function(){
var data = {
'action': 'w3tc_action_purge_urls',
'purge_urls': jQuery('#purge_urls').val()
};

jQuery.post(ajaxurl, data, function(response) {
alert(response);
});
jQuery('#purge_urls').val('')
return false;
})

});
});

0 comments on commit f098003

Please sign in to comment.