12
12
/**
13
13
* Track the usage of the plugin.
14
14
*
15
+ * Implements Singleton pattern to track usage metrics for analytics.
16
+ *
17
+ * @since 5.0.7
15
18
* @package feedzy-rss-feeds
16
19
* @subpackage feedzy-rss-feeds/includes/admin
17
20
* @author Themeisle <[email protected] >
@@ -20,20 +23,25 @@ class Feedzy_Rss_Feeds_Usage {
20
23
21
24
/**
22
25
* Option name in wp_options table.
26
+ *
27
+ * @since 5.0.7
28
+ * @var string
23
29
*/
24
30
const OPTION_NAME = 'feedzy_usage ' ;
25
31
26
32
/**
27
- * The single instance of the class .
33
+ * Singleton instance.
28
34
*
29
- * @var Feedzy_Rss_Feeds_Usage|null
35
+ * @since 5.0.7
36
+ * @var Feedzy_Rss_Feeds_Usage|null
30
37
*/
31
38
private static $ instance = null ;
32
39
33
40
/**
34
41
* Default usage data structure.
35
42
*
36
- * @var array<string, string|int>
43
+ * @since 5.0.7
44
+ * @var array<string, string|int|bool>
37
45
*/
38
46
private $ default_data = array (
39
47
'first_import_run_datetime ' => '' ,
@@ -43,25 +51,32 @@ class Feedzy_Rss_Feeds_Usage {
43
51
);
44
52
45
53
/**
46
- * Private constructor to prevent direct instantiation.
54
+ * Initialize usage tracking.
55
+ *
56
+ * @since 5.0.7
47
57
*/
48
58
private function __construct () {
49
59
$ this ->init ();
50
60
}
51
61
52
62
/**
53
- * Prevent cloning of the instance.
63
+ * Prevent cloning.
64
+ *
65
+ * @since 5.0.7
54
66
*/
55
67
public function __clone () {}
56
68
57
69
/**
58
- * Prevent unserialization of the instance.
70
+ * Prevent unserialization.
71
+ *
72
+ * @since 5.0.7
59
73
*/
60
74
public function __wakeup () {}
61
75
62
76
/**
63
- * Get the single instance of the class .
77
+ * Get singleton instance.
64
78
*
79
+ * @since 5.0.7
65
80
* @return Feedzy_Rss_Feeds_Usage
66
81
*/
67
82
public static function get_instance () {
@@ -72,8 +87,9 @@ public static function get_instance() {
72
87
}
73
88
74
89
/**
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
77
93
*/
78
94
private function init () {
79
95
if ( false === get_option (self ::OPTION_NAME ) ) {
@@ -82,9 +98,10 @@ private function init() {
82
98
}
83
99
84
100
/**
85
- * Get all usage data.
101
+ * Get usage data with defaults merged .
86
102
*
87
- * @return array<string, string|int> Usage data array.
103
+ * @since 5.0.7
104
+ * @return array<string, string|int|bool>
88
105
*/
89
106
public function get_usage_data () {
90
107
$ data = get_option ( self ::OPTION_NAME , array () );
@@ -94,8 +111,9 @@ public function get_usage_data() {
94
111
/**
95
112
* Update usage data.
96
113
*
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
99
117
*/
100
118
public function update_usage_data ( $ new_data ) {
101
119
$ current_data = $ this ->get_usage_data ();
@@ -104,10 +122,9 @@ public function update_usage_data( $new_data ) {
104
122
}
105
123
106
124
/**
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.
109
126
*
110
- * @return void
127
+ * @since 5.0.7
111
128
*/
112
129
public function track_rss_import () {
113
130
$ data = $ this ->get_usage_data ();
@@ -128,10 +145,9 @@ public function track_rss_import() {
128
145
}
129
146
130
147
/**
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.
133
149
*
134
- * @return void
150
+ * @since 5.0.7
135
151
*/
136
152
public function track_import_creation () {
137
153
$ data = $ this ->get_usage_data ();
@@ -144,19 +160,20 @@ public function track_import_creation() {
144
160
}
145
161
146
162
/**
147
- * Delete the usage data option.
148
- * Useful for plugin uninstall.
163
+ * Delete usage data option.
149
164
*
150
- * @return bool True if the option was deleted, false otherwise.
165
+ * @since 5.0.7
166
+ * @return bool
151
167
*/
152
168
public function delete_usage_data () {
153
169
return delete_option (self ::OPTION_NAME );
154
170
}
155
171
156
172
/**
157
- * Get usage statistics in a formatted array .
173
+ * Get formatted usage statistics with calculated fields .
158
174
*
159
- * @return array<string, string|int> Formatted usage statistics.
175
+ * @since 5.0.7
176
+ * @return array<string, string|int>
160
177
*/
161
178
public function get_usage_stats () {
162
179
$ data = $ this ->get_usage_data ();
@@ -191,8 +208,9 @@ public function get_usage_stats() {
191
208
}
192
209
193
210
/**
194
- * Check if the user is new to track the first usage .
211
+ * Check if user installed plugin within last day .
195
212
*
213
+ * @since 5.0.7
196
214
* @return bool
197
215
*/
198
216
public function is_new_user () {
0 commit comments