PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.3.1
Independent Analytics – WordPress Analytics Plugin v2.3.1
2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / IAWP / Settings.php
independent-analytics / IAWP Last commit date
AJAX 2 years ago Admin_Page 2 years ago Date_Range 2 years ago Filter_Lists 2 years ago Interval 2 years ago Menu_Bar_Stats 2 years ago Migrations 2 years ago Models 2 years ago Public_API 2 years ago Rows 2 years ago Statistics 2 years ago Tables 2 years ago Utils 2 years ago Campaign_Builder.php 2 years ago Capability_Manager.php 2 years ago Chart.php 2 years ago Chart_Geo.php 2 years ago Cron_Manager.php 2 years ago Current_Traffic_Finder.php 2 years ago Dashboard_Options.php 2 years ago Dashboard_Widget.php 2 years ago Database.php 2 years ago Database_Manager.php 2 years ago Email_Chart.php 2 years ago Email_Reports.php 2 years ago Empty_Report_Option.php 2 years ago Env.php 2 years ago Filters.php 2 years ago Geo_Database_Background_Job.php 2 years ago Geo_Database_Manager.php 2 years ago Geoposition.php 2 years ago Icon_Directory.php 2 years ago Icon_Directory_Factory.php 2 years ago Illuminate_Builder.php 2 years ago Independent_Analytics.php 2 years ago Interrupt.php 2 years ago Known_Referrers.php 2 years ago Plugin_Conflict_Detector.php 2 years ago Query.php 2 years ago Quick_Stats.php 2 years ago REST_API.php 2 years ago Real_Time.php 2 years ago Report.php 2 years ago Report_Finder.php 2 years ago Report_Options_Parser.php 2 years ago Resource_Identifier.php 2 years ago Settings.php 2 years ago Sort_Configuration.php 2 years ago Track_Resource_Changes.php 2 years ago View.php 2 years ago View_Counter.php 2 years ago Visitors_Over_Time_Finder.php 2 years ago WP_Option_Cache_Bust.php 2 years ago WooCommerce_Order.php 2 years ago WooCommerce_Referrer_Meta_Box.php 2 years ago
Settings.php
322 lines
1 <?php
2
3 namespace IAWP;
4
5 use IAWP\Utils\Request;
6 use IAWP\Utils\String_Util;
7 /** @internal */
8 class Settings
9 {
10 public function __construct()
11 {
12 \add_action('admin_init', [$this, 'register_settings']);
13 \add_action('admin_init', [$this, 'register_view_counter_settings']);
14 \add_action('admin_init', [$this, 'register_blocked_ip_settings']);
15 \add_action('admin_init', [$this, 'register_block_by_role_settings']);
16 if (\IAWPSCOPED\iawp_is_pro()) {
17 \add_action('admin_init', [$this, 'register_email_report_settings']);
18 }
19 }
20 public function render_settings()
21 {
22 echo \IAWPSCOPED\iawp_blade()->run('settings.index');
23 if (\IAWPSCOPED\iawp_is_pro()) {
24 $defaults = $this->email_report_colors();
25 $saved = \IAWPSCOPED\iawp()->get_option('iawp_email_report_colors', $defaults);
26 // There were 6 colors and now 9, so there is a saved value but 7-9 don't exist
27 $input_defaults = $defaults;
28 for ($i = 0; $i < \count($saved); $i++) {
29 $input_defaults[$i] = $saved[$i];
30 }
31 echo \IAWPSCOPED\iawp_blade()->run('settings.email-reports', ['time' => \IAWPSCOPED\iawp()->get_option('iawp_email_report_time', 9), 'emails' => \IAWPSCOPED\iawp()->get_option('iawp_email_report_email_addresses', []), 'default_colors' => $defaults, 'input_default' => $input_defaults]);
32 }
33 $ip = Request::ip();
34 $ips = \IAWPSCOPED\iawp()->get_option('iawp_blocked_ips', []);
35 $ip_is_blocked = \in_array($ip, $ips);
36 echo \IAWPSCOPED\iawp_blade()->run('settings.block-ips', ['current_ip' => $ip, 'ip_is_blocked' => $ip_is_blocked, 'ips' => $ips]);
37 echo \IAWPSCOPED\iawp_blade()->run('settings.block-by-role', ['roles' => \wp_roles()->roles, 'blocked' => \IAWPSCOPED\iawp()->get_option('iawp_blocked_roles', [])]);
38 echo \IAWPSCOPED\iawp_blade()->run('settings.capabilities', ['editable_roles' => $this->get_editable_roles(), 'capabilities' => \IAWP\Capability_Manager::all_capabilities()]);
39 echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter');
40 echo \IAWPSCOPED\iawp_blade()->run('settings.export-reports', ['report_finder' => new \IAWP\Report_Finder()]);
41 echo \IAWPSCOPED\iawp_blade()->run('settings.export-data');
42 echo \IAWPSCOPED\iawp_blade()->run('settings.delete', ['site_name' => \get_bloginfo('name'), 'site_url' => \site_url()]);
43 }
44 public function register_settings()
45 {
46 \add_settings_section('iawp-settings-section', \esc_html__('Basic Settings', 'independent-analytics'), function () {
47 }, 'independent-analytics-settings');
48 $args = ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean'];
49 \register_setting('iawp_settings', 'iawp_dark_mode', $args);
50 \add_settings_field('iawp_dark_mode', \esc_html__('Dark mode', 'independent-analytics'), [$this, 'dark_mode_callback'], 'independent-analytics-settings', 'iawp-settings-section', ['class' => 'dark-mode']);
51 \register_setting('iawp_settings', 'iawp_track_authenticated_users', $args);
52 \add_settings_field('iawp_track_authenticated_users', \esc_html__('Track logged in users', 'independent-analytics'), [$this, 'track_authenticated_users_callback'], 'independent-analytics-settings', 'iawp-settings-section', ['class' => 'logged-in']);
53 \register_setting('iawp_settings', 'iawp_disable_admin_toolbar_analytics', $args);
54 \add_settings_field('iawp_disable_admin_toolbar_analytics', \esc_html__('Admin toolbar stats', 'independent-analytics'), [$this, 'disable_admin_toolbar_analytics_callback'], 'independent-analytics-settings', 'iawp-settings-section');
55 \register_setting('iawp_settings', 'iawp_disable_widget', $args);
56 \add_settings_field('iawp_disable_widget', \esc_html__('Dashboard widget', 'independent-analytics'), [$this, 'disable_widget_callback'], 'independent-analytics-settings', 'iawp-settings-section');
57 $args = ['type' => 'integer', 'default' => 0, 'sanitize_callback' => 'absint'];
58 \register_setting('iawp_settings', 'iawp_dow', $args);
59 \add_settings_field('iawp_dow', \esc_html__('First day of week', 'independent-analytics'), [$this, 'starting_dow_callback'], 'independent-analytics-settings', 'iawp-settings-section', ['class' => 'dow']);
60 $args = ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean'];
61 \register_setting('iawp_settings', 'iawp_refresh_salt', $args);
62 \add_settings_field('iawp_refresh_salt', \esc_html__('Salt refresh rate', 'independent-analytics'), [$this, 'refresh_salt_callback'], 'independent-analytics-settings', 'iawp-settings-section', ['class' => 'salt']);
63 }
64 public function dark_mode_callback()
65 {
66 echo \IAWPSCOPED\iawp_blade()->run('settings.dark-mode', ['dark_mode' => \IAWPSCOPED\iawp()->get_option('iawp_dark_mode', \false)]);
67 }
68 public function track_authenticated_users_callback()
69 {
70 echo \IAWPSCOPED\iawp_blade()->run('settings.track-authenticated-users', ['track_authenticated_users' => \IAWPSCOPED\iawp()->get_option('iawp_track_authenticated_users', \false)]);
71 }
72 public function disable_admin_toolbar_analytics_callback()
73 {
74 echo \IAWPSCOPED\iawp_blade()->run('settings.disable-admin-toolbar-analytics', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_disable_admin_toolbar_analytics', \false)]);
75 }
76 public function disable_widget_callback()
77 {
78 echo \IAWPSCOPED\iawp_blade()->run('settings.disable-widget', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_disable_widget', \false)]);
79 }
80 public function starting_dow_callback()
81 {
82 echo \IAWPSCOPED\iawp_blade()->run('settings.first-day-of-week', ['day_of_week' => \IAWPSCOPED\iawp()->get_option('iawp_dow', 0), 'days' => [0 => \esc_html__('Sunday', 'independent-analytics'), 1 => \esc_html__('Monday', 'independent-analytics'), 2 => \esc_html__('Tuesday', 'independent-analytics'), 3 => \esc_html__('Wednesday', 'independent-analytics'), 4 => \esc_html__('Thursday', 'independent-analytics'), 5 => \esc_html__('Friday', 'independent-analytics'), 6 => \esc_html__('Saturday', 'independent-analytics')]]);
83 }
84 public function refresh_salt_callback()
85 {
86 echo \IAWPSCOPED\iawp_blade()->run('settings.refresh-salt', ['refresh_salt' => \IAWPSCOPED\iawp()->get_option('iawp_refresh_salt', \false)]);
87 }
88 public function register_view_counter_settings()
89 {
90 \add_settings_section('iawp-view-counter-settings-section', \esc_html__('Public View Counter', 'independent-analytics'), function () {
91 }, 'independent-analytics-view-counter-settings');
92 $args = ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean'];
93 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_enable', $args);
94 \add_settings_field('iawp_view_counter_enable', \esc_html__('Enable the view counter', 'independent-analytics'), [$this, 'view_counter_enable_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'enable']);
95 $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_view_counter_post_types']];
96 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_post_types', $args);
97 \add_settings_field('iawp_view_counter_post_types', \esc_html__('Display on these post types', 'independent-analytics'), [$this, 'view_counter_post_types_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'post-types']);
98 // Position
99 $args = ['type' => 'string', 'default' => 'after', 'sanitize_callback' => [$this, 'sanitize_view_counter_position']];
100 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_position', $args);
101 \add_settings_field('iawp_view_counter_position', \esc_html__('Show it in this location', 'independent-analytics'), [$this, 'view_counter_position_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'position']);
102 // Views to count
103 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_views_to_count', ['type' => 'string', 'default' => 'total', 'sanitize_callback' => [$this, 'sanitize_view_counter_views_to_count']]);
104 \add_settings_field('iawp_view_counter_views_to_count', \esc_html__('Date range to count views', 'independent-analytics'), [$this, 'view_counter_views_to_count_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'views-to-count']);
105 // Exclude
106 $args = ['type' => 'string', 'default' => '', 'sanitize_callback' => [$this, 'sanitize_view_counter_exclude']];
107 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_exclude', $args);
108 \add_settings_field('iawp_view_counter_exclude', \esc_html__('Exclude these pages', 'independent-analytics'), [$this, 'view_counter_exclude_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'exclude']);
109 // Label
110 $default = \function_exists('IAWPSCOPED\\pll__') ? pll__('Views:', 'independent-analytics') : \__('Views:', 'independent-analytics');
111 $args = ['type' => 'string', 'default' => $default, 'sanitize_callback' => 'sanitize_text_field'];
112 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_label', $args);
113 \add_settings_field('iawp_view_counter_label', \esc_html__('Edit the label', 'independent-analytics'), [$this, 'view_counter_label_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'counter-label']);
114 // Icon
115 $args = ['type' => 'boolean', 'default' => \true, 'sanitize_callback' => 'rest_sanitize_boolean'];
116 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_icon', $args);
117 \add_settings_field('iawp_view_counter_icon', \esc_html__('Display the icon', 'independent-analytics'), [$this, 'view_counter_icon_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'icon']);
118 // Private
119 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_private', ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean']);
120 \add_settings_field('iawp_view_counter_private', \esc_html__('Make the view counter private?', 'independent-analytics'), [$this, 'view_counter_private_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'private']);
121 // Allow manual adjustment
122 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_manual_adjustment', ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean']);
123 \add_settings_field('iawp_view_counter_manual_adjustment', \esc_html__('Allow manual adjustment?', 'independent-analytics'), [$this, 'view_counter_manual_adjustment_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'manual-adjustment']);
124 }
125 public function view_counter_enable_callback()
126 {
127 echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.enable', ['enable' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_enable', \false)]);
128 }
129 public function view_counter_post_types_callback()
130 {
131 $site_post_types = \get_post_types(['public' => \true], 'objects');
132 $counter = 0;
133 foreach ($site_post_types as $post_type) {
134 echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.post-types', ['counter' => $counter, 'post_type' => $post_type, 'saved' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_post_types', [])]);
135 $counter++;
136 }
137 ?>
138 <p class="description"><?php
139 \esc_html_e('Uncheck all boxes to only show view count manually. See shortcode documentation below for details.', 'independent-analytics');
140 ?></p>
141 <?php
142 }
143 public function view_counter_position_callback()
144 {
145 echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.position', ['position' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_position', 'after')]);
146 }
147 public function view_counter_views_to_count_callback()
148 {
149 echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.views-to-count', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_views_to_count', 'total')]);
150 }
151 public function view_counter_exclude_callback()
152 {
153 echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.exclude', ['exclude' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_exclude', '')]);
154 }
155 public function view_counter_label_callback()
156 {
157 $default = \function_exists('IAWPSCOPED\\pll__') ? pll__('Views:', 'independent-analytics') : \__('Views:', 'independent-analytics');
158 echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.label', ['label' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_label', $default)]);
159 }
160 public function view_counter_icon_callback()
161 {
162 echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.icon', ['icon' => \get_option('iawp_view_counter_icon', \true)]);
163 }
164 public function view_counter_private_callback()
165 {
166 echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.private', ['private' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_private', \false)]);
167 }
168 public function view_counter_manual_adjustment_callback()
169 {
170 echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.manual-adjustment', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_manual_adjustment', \false)]);
171 }
172 public function register_blocked_ip_settings()
173 {
174 \add_settings_section('iawp-blocked-ips-settings-section', \esc_html__('Block IP Addresses', 'independent-analytics'), function () {
175 }, 'iawp-blocked-ips-settings');
176 $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_blocked_ips']];
177 \register_setting('iawp_blocked_ip_settings', 'iawp_blocked_ips', $args);
178 }
179 public function register_email_report_settings()
180 {
181 \add_settings_section('iawp-email-report-settings-section', \esc_html__('Scheduled Email Reports', 'independent-analytics'), function () {
182 }, 'iawp-email-report-settings');
183 $args = ['type' => 'number', 'default' => 9, 'sanitize_callback' => [$this, 'sanitize_email_report_time']];
184 \register_setting('iawp_email_report_settings', 'iawp_email_report_time', $args);
185 $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_email_addresses']];
186 \register_setting('iawp_email_report_settings', 'iawp_email_report_email_addresses', $args);
187 $args = ['type' => 'array', 'default' => $this->email_report_colors(), 'sanitize_callback' => [$this, 'sanitize_email_report_colors']];
188 \register_setting('iawp_email_report_settings', 'iawp_email_report_colors', $args);
189 }
190 public function register_block_by_role_settings()
191 {
192 \add_settings_section('iawp-block-by-role-settings-section', \esc_html__('Block by User Role', 'independent-analytics'), function () {
193 }, 'iawp-block-by-role-settings');
194 $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_blocked_roles']];
195 \register_setting('iawp_block_by_role_settings', 'iawp_blocked_roles', $args);
196 }
197 public function sanitize_view_counter_post_types($user_input)
198 {
199 $site_post_types = \get_post_types(['public' => \true]);
200 $to_save = [];
201 foreach ($user_input as $post_type) {
202 if (\in_array($post_type, $site_post_types)) {
203 $to_save[] = $post_type;
204 }
205 }
206 return $to_save;
207 }
208 public function sanitize_view_counter_position($user_input)
209 {
210 if (\in_array($user_input, ['before', 'after', 'both'])) {
211 return $user_input;
212 } else {
213 return 'after';
214 }
215 }
216 public function sanitize_view_counter_views_to_count($user_input)
217 {
218 if (\in_array($user_input, ['total', 'today', 'last_thirty', 'this_month', 'last_month'])) {
219 return $user_input;
220 } else {
221 return 'total';
222 }
223 }
224 public function sanitize_view_counter_exclude($user_input)
225 {
226 $user_input = \explode(',', $user_input);
227 $to_save = [];
228 foreach ($user_input as $id) {
229 $save = \absint($id);
230 if ($save != 0) {
231 $to_save[] = $save;
232 }
233 }
234 $to_save = \implode(',', $to_save);
235 return $to_save;
236 }
237 public function sanitize_blocked_ips($user_input)
238 {
239 $to_save = [];
240 foreach ($user_input as $ip) {
241 // Limit to two wildcards
242 if (\substr_count($ip, '*') > 2) {
243 continue;
244 }
245 // If it's safe with wildcard replacements, it's safe with them
246 $safe_replacement = String_Util::str_contains($ip, '.') ? '172' : '2601';
247 $wildcards_replaced = \str_replace('*', $safe_replacement, $ip);
248 if (\filter_var($wildcards_replaced, \FILTER_VALIDATE_IP)) {
249 $to_save[] = $ip;
250 }
251 }
252 return $to_save;
253 }
254 public function sanitize_email_addresses($emails)
255 {
256 $to_save = [];
257 foreach ($emails as $email) {
258 $cleaned = \sanitize_email($email);
259 if (\is_email($cleaned)) {
260 $to_save[] = $cleaned;
261 }
262 }
263 return $to_save;
264 }
265 public function sanitize_email_report_time($user_time)
266 {
267 $accepted_times = [];
268 for ($i = 0; $i < 24; $i++) {
269 $accepted_times[] = $i;
270 }
271 if (\in_array($user_time, $accepted_times)) {
272 return $user_time;
273 } else {
274 return 9;
275 }
276 }
277 public function sanitize_blocked_roles($blocked_roles)
278 {
279 $to_save = [];
280 $user_roles = \array_keys(\wp_roles()->roles);
281 foreach ($blocked_roles as $blocked) {
282 if (\in_array($blocked, $user_roles)) {
283 $to_save[] = $blocked;
284 }
285 }
286 return $to_save;
287 }
288 public function sanitize_email_report_colors($colors)
289 {
290 $to_save = [];
291 // No idea why WP sometimes returns an array, so this is for my sanity
292 if (\is_string($colors)) {
293 $colors = \explode(',', $colors);
294 }
295 foreach ($colors as $color) {
296 $to_save[] = \sanitize_hex_color($color);
297 }
298 return $to_save;
299 }
300 /**
301 * @return array
302 */
303 private function get_editable_roles() : array
304 {
305 $editable_roles = [];
306 $wp_roles = \wp_roles()->roles;
307 \array_walk($wp_roles, function ($role, $role_key) use(&$editable_roles) {
308 if ($role_key === 'administrator') {
309 return;
310 }
311 $read_only_access = $role['capabilities']['iawp_read_only_access'] ?? \false;
312 $full_access = $role['capabilities']['iawp_full_access'] ?? \false;
313 $editable_roles[] = ['key' => $role_key, 'name' => $role['name'], 'iawp_no_access' => !$read_only_access && !$full_access, 'iawp_read_only_access' => $read_only_access, 'iawp_full_access' => $full_access];
314 });
315 return $editable_roles;
316 }
317 private function email_report_colors()
318 {
319 return ['#5123a0', '#fafafa', '#3a1e6b', '#fafafa', '#5123a0', '#a985e6', '#ece9f2', '#f7f5fa', '#ece9f2', '#dedae6'];
320 }
321 }
322