Skip to content

Commit b42b13b

Browse files
chore: delete usage option on uninstall
1 parent 284b3e4 commit b42b13b

File tree

2 files changed

+44
-25
lines changed

2 files changed

+44
-25
lines changed

includes/admin/feedzy-rss-feeds-usage.php

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
/**
1313
* Track the usage of the plugin.
1414
*
15+
* Implements Singleton pattern to track usage metrics for analytics.
16+
*
17+
* @since 5.0.7
1518
* @package feedzy-rss-feeds
1619
* @subpackage feedzy-rss-feeds/includes/admin
1720
* @author Themeisle <[email protected]>
@@ -20,20 +23,25 @@ class Feedzy_Rss_Feeds_Usage {
2023

2124
/**
2225
* Option name in wp_options table.
26+
*
27+
* @since 5.0.7
28+
* @var string
2329
*/
2430
const OPTION_NAME = 'feedzy_usage';
2531

2632
/**
27-
* The single instance of the class.
33+
* Singleton instance.
2834
*
29-
* @var Feedzy_Rss_Feeds_Usage|null
35+
* @since 5.0.7
36+
* @var Feedzy_Rss_Feeds_Usage|null
3037
*/
3138
private static $instance = null;
3239

3340
/**
3441
* Default usage data structure.
3542
*
36-
* @var array<string, string|int>
43+
* @since 5.0.7
44+
* @var array<string, string|int|bool>
3745
*/
3846
private $default_data = array(
3947
'first_import_run_datetime' => '',
@@ -43,25 +51,32 @@ class Feedzy_Rss_Feeds_Usage {
4351
);
4452

4553
/**
46-
* Private constructor to prevent direct instantiation.
54+
* Initialize usage tracking.
55+
*
56+
* @since 5.0.7
4757
*/
4858
private function __construct() {
4959
$this->init();
5060
}
5161

5262
/**
53-
* Prevent cloning of the instance.
63+
* Prevent cloning.
64+
*
65+
* @since 5.0.7
5466
*/
5567
public function __clone() {}
5668

5769
/**
58-
* Prevent unserialization of the instance.
70+
* Prevent unserialization.
71+
*
72+
* @since 5.0.7
5973
*/
6074
public function __wakeup() {}
6175

6276
/**
63-
* Get the single instance of the class.
77+
* Get singleton instance.
6478
*
79+
* @since 5.0.7
6580
* @return Feedzy_Rss_Feeds_Usage
6681
*/
6782
public static function get_instance() {
@@ -72,8 +87,9 @@ public static function get_instance() {
7287
}
7388

7489
/**
75-
* Initialize the usage tracking.
76-
* Creates the option if it doesn't exist.
90+
* Initialize usage tracking option.
91+
*
92+
* @since 5.0.7
7793
*/
7894
private function init() {
7995
if ( false === get_option(self::OPTION_NAME) ) {
@@ -82,9 +98,10 @@ private function init() {
8298
}
8399

84100
/**
85-
* Get all usage data.
101+
* Get usage data with defaults merged.
86102
*
87-
* @return array<string, string|int> Usage data array.
103+
* @since 5.0.7
104+
* @return array<string, string|int|bool>
88105
*/
89106
public function get_usage_data() {
90107
$data = get_option( self::OPTION_NAME, array() );
@@ -94,8 +111,9 @@ public function get_usage_data() {
94111
/**
95112
* Update usage data.
96113
*
97-
* @param array<string, string|int> $new_data Data to update.
98-
* @return bool True if the option was updated, false otherwise.
114+
* @since 5.0.7
115+
* @param array<string, string|int|bool> $new_data Data to merge.
116+
* @return bool
99117
*/
100118
public function update_usage_data( $new_data ) {
101119
$current_data = $this->get_usage_data();
@@ -104,10 +122,9 @@ public function update_usage_data( $new_data ) {
104122
}
105123

106124
/**
107-
* Track RSS feed import.
108-
* Sets first import timestamp if it's the first import, always increments counter.
125+
* Track RSS feed import runs.
109126
*
110-
* @return void
127+
* @since 5.0.7
111128
*/
112129
public function track_rss_import() {
113130
$data = $this->get_usage_data();
@@ -128,10 +145,9 @@ public function track_rss_import() {
128145
}
129146

130147
/**
131-
* Track settings page creation.
132-
* Sets first settings page timestamp if it's the first page, always increments counter.
148+
* Track first import creation timestamp.
133149
*
134-
* @return void
150+
* @since 5.0.7
135151
*/
136152
public function track_import_creation() {
137153
$data = $this->get_usage_data();
@@ -144,19 +160,20 @@ public function track_import_creation() {
144160
}
145161

146162
/**
147-
* Delete the usage data option.
148-
* Useful for plugin uninstall.
163+
* Delete usage data option.
149164
*
150-
* @return bool True if the option was deleted, false otherwise.
165+
* @since 5.0.7
166+
* @return bool
151167
*/
152168
public function delete_usage_data() {
153169
return delete_option(self::OPTION_NAME);
154170
}
155171

156172
/**
157-
* Get usage statistics in a formatted array.
173+
* Get formatted usage statistics with calculated fields.
158174
*
159-
* @return array<string, string|int> Formatted usage statistics.
175+
* @since 5.0.7
176+
* @return array<string, string|int>
160177
*/
161178
public function get_usage_stats() {
162179
$data = $this->get_usage_data();
@@ -191,8 +208,9 @@ public function get_usage_stats() {
191208
}
192209

193210
/**
194-
* Check if the user is new to track the first usage.
211+
* Check if user installed plugin within last day.
195212
*
213+
* @since 5.0.7
196214
* @return bool
197215
*/
198216
public function is_new_user() {

uninstall.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@
3131
delete_option( 'feedzy-rss-feeds' );
3232
delete_option( 'feedzy_fresh_install' );
3333
delete_option( 'feedzy_wizard_data' );
34+
delete_option( 'feedzy_usage' );

0 commit comments

Comments
 (0)