Skip to content

Commit

Permalink
* Add clear cache function.
Browse files Browse the repository at this point in the history
* Add clear settings function.


git-svn-id: https://plugins.svn.wordpress.org/wp-piwik/trunk@1163603 b8457f37-d9ea-0310-8a92-e5e31aec5664
  • Loading branch information
Braekling authored and Braekling committed May 19, 2015
1 parent fe3a28e commit cefce4f
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 10 deletions.
5 changes: 3 additions & 2 deletions classes/WP_Piwik.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class WP_Piwik {
*
* @var Runtime environment variables
*/
private static $revisionId = 2015051801, $version = '0.10.0.8', $blog_id, $pluginBasename = NULL, $logger, $settings, $request;
private static $revisionId = 2015051901, $version = '0.10.0.9', $blog_id, $pluginBasename = NULL, $logger, $settings, $request;

/**
* Constructor class to configure and register all WP-Piwik components
Expand Down Expand Up @@ -933,7 +933,8 @@ public function request($id, $debug = false) {
* Reset request object
*/
public function resetRequest() {
self::$request->reset();
if (is_object(self::$request))
self::$request->reset();
self::$request = NULL;
}

Expand Down
44 changes: 41 additions & 3 deletions classes/WP_Piwik/Admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,25 @@ public function show() {
new \WP_Piwik\Admin\Sitebrowser(self::$wpPiwik);
return;
}
global $wp_roles;
if (isset($_GET['clear']) && $_GET['clear']) {
$this->clear($_GET['clear'] == 2);
self::$wpPiwik->resetRequest();
self::$wpPiwik->updateTrackingCode();
}
if (isset ( $_POST ) && isset ( $_POST ['wp-piwik'] )) {
$this->showBox ( 'updated', 'yes', __ ( 'Changes saved.' ) );
self::$wpPiwik->resetRequest();
self::$wpPiwik->updateTrackingCode();
}
global $wp_roles;
?>
<div id="plugin-options-wrap" class="widefat">
<?php
echo $this->getHeadline ( 1, 'admin-generic', 'Settings', true );
if (isset($_GET['testscript']) && $_GET['testscript'])
$this->runTestscript();
?>
<form method="post">
<form method="post" action="?page=<?php echo $_GET['page']; ?>">
<input type="hidden" name="wp-piwik[revision]" value="<?php echo self::$settings->getGlobalOption('revision'); ?>" />
<?php wp_nonce_field('wp-piwik_settings'); ?>
<table class="wp-piwik-form">
Expand Down Expand Up @@ -543,7 +548,13 @@ public function showSupport() {
_e('enabled','wp-piwik');
?></strong>.</li>
</ol>
<p><a href="<?php echo admin_url( (self::$settings->checkNetworkActivation () ? 'network/settings' : 'options-general').'.php?page='.$_GET['page'].'&testscript=1' ); ?>">Run testscript</a>. <a href="<?php echo admin_url( (self::$settings->checkNetworkActivation () ? 'network/settings' : 'options-general').'.php?page='.$_GET['page'].'&sitebrowser=1' ); ?>">Sitebrowser</a>.</p>
<p><?php _e('Tools', 'wp-piwik'); ?>:</p>
<ol>
<li><a href="<?php echo admin_url( (self::$settings->checkNetworkActivation () ? 'network/settings' : 'options-general').'.php?page='.$_GET['page'].'&testscript=1' ); ?>"><?php _e('Run testscript', 'wp-piwik'); ?></a></li>
<li><a href="<?php echo admin_url( (self::$settings->checkNetworkActivation () ? 'network/settings' : 'options-general').'.php?page='.$_GET['page'].'&sitebrowser=1' ); ?>"><?php _e('Sitebrowser', 'wp-piwik'); ?></a></li>
<li><a href="<?php echo admin_url( (self::$settings->checkNetworkActivation () ? 'network/settings' : 'options-general').'.php?page='.$_GET['page'].'&clear=1' ); ?>"><?php _e('Clear cache', 'wp-piwik'); ?></a></li>
<li><a onclick="return confirm('<?php _e('Are you sure you want to clear all settings except the connection settings?', 'wp-piwik'); ?>')" href="<?php echo admin_url( (self::$settings->checkNetworkActivation () ? 'network/settings' : 'options-general').'.php?page='.$_GET['page'].'&clear=2' ); ?>"><?php _e('Clear cache and settings except connection settings', 'wp-piwik'); ?></a></li>
</ol>
<h3><?php _e('Latest support threads on WordPress.org', 'wp-piwik'); ?></h3><?php
$supportThreads = $this->readRSSFeed('http://wordpress.org/support/rss/plugin/wp-piwik');
if (!empty($supportThreads)) {
Expand Down Expand Up @@ -587,6 +598,33 @@ private function readRSSFeed($feed, $cnt = 5) {
return $result;
}

/**
* Clear cache and reset settings
*
* @param boolean $clearSettings set to true to reset settings (default: false)
*/
private function clear($clearSettings = false) {
if ($clearSettings) {
self::$settings->resetSettings();
$this->showBox ( 'updated', 'yes', __ ( 'Settings cleared (except connection settings).' ) );
}
global $wpdb;
if (self::$settings->checkNetworkActivation()) {
$aryBlogs = $wpdb->get_results('SELECT blog_id FROM '.$wpdb->blogs.' ORDER BY blog_id');
if (is_array($aryBlogs))
foreach ($aryBlogs as $aryBlog) {
switch_to_blog($aryBlog->blog_id);
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_wp-piwik_%'");
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_wp-piwik_%'");
restore_current_blog();
}
} else {
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_wp-piwik_%'");
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_wp-piwik_%'");
}
$this->showBox ( 'updated', 'yes', __ ( 'Cache cleared.' ) );
}

/**
* Execute test script and display results
*/
Expand Down
5 changes: 3 additions & 2 deletions classes/WP_Piwik/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Settings {
'track_datacfasync' => false,
'track_cdnurl' => '',
'track_cdnurlssl' => '',
'force_protocol' => 'disabled'
'force_protocol' => 'disabled'
), $settings = array (
'name' => '',
'site_id' => NULL,
Expand Down Expand Up @@ -234,7 +234,8 @@ public function resetSettings($resetAll = false) {
'piwik_token' => $this->getGlobalOption ( 'piwik_token' ),
'piwik_url' => $this->getGlobalOption ( 'piwik_url' ),
'piwik_path' => $this->getGlobalOption ( 'piwik_path' ),
'piwik_mode' => $this->getGlobalOption ( 'piwik_mode' )
'piwik_user' => $this->getGlobalOption ( 'piwik_user' ),
'piwik_mode' => $this->getGlobalOption ( 'piwik_mode' )
);
if (is_plugin_active_for_network ( 'wp-piwik/wp-piwik.php' )) {
delete_site_option ( 'wp-piwik_global-settings' );
Expand Down
4 changes: 4 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ This is a full refactored version of WP-Piwik. Please check your settings after

== Changelog ==

= 0.10.0.9 =
* Add clear cache function.
* Add clear settings function.

= 0.10.0.8 =
* Bugfix: Sitebrowser link (settings page, support) fixed
* Bugfix: Use new settings directly after saving (reloading is not necessary anymore)
Expand Down
1 change: 0 additions & 1 deletion uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_wp-piwik_%'");
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_wp-piwik_%'");
restore_current_blog();

}
foreach ($globalSettings as $key)
delete_site_option('wp-piwik_global-'.$key);
Expand Down
2 changes: 1 addition & 1 deletion update/2015051101.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$oldOptions = get_option ( 'wp-piwik_settings', array () );
delete_option('wp-piwik_settings');

if (function_exists('is_multisite') && is_multisite()) {
if (self::$settings->checkNetworkActivation ()) {
global $wpdb;
$aryBlogs = $wpdb->get_results('SELECT blog_id FROM '.$wpdb->blogs.' ORDER BY blog_id');
if (is_array($aryBlogs))
Expand Down
2 changes: 1 addition & 1 deletion wp-piwik.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Description: Adds Piwik stats to your dashboard menu and Piwik code to your wordpress header.
Version: 0.10.0.8
Version: 0.10.0.9
Author: Andr&eacute; Br&auml;kling
Author URI: http://www.braekling.de
Text Domain: wp-piwik
Expand Down

0 comments on commit cefce4f

Please sign in to comment.