PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.25.0
Independent Analytics – WordPress Analytics Plugin v1.25.0
2.15.5 2.15.4 2.15.3 2.15.2 2.15.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 3 years ago Date_Range 3 years ago Interval 3 years ago Menu_Bar_Stats 3 years ago Migrations 3 years ago Models 3 years ago Queries 3 years ago Statistics 3 years ago Tables 3 years ago Utils 3 years ago Campaign_Builder.php 3 years ago Capability_Manager.php 3 years ago Chart.php 3 years ago Chart_Geo.php 3 years ago Chart_SVG.php 3 years ago Dashboard_Options.php 3 years ago Dashboard_Widget.php 3 years ago Email_Reports.php 3 years ago Filters.php 3 years ago Geo_Database.php 3 years ago Geo_Database_Download_Job.php 3 years ago Health_Check.php 3 years ago Illuminate_Builder.php 3 years ago Independent_Analytics.php 3 years ago Known_Referrers.php 3 years ago PDF.php 3 years ago Query.php 3 years ago Quick_Stats.php 3 years ago REST_API.php 3 years ago Real_Time.php 3 years ago Reset_Database.php 3 years ago Resource_Identifier.php 3 years ago Settings.php 3 years ago Sort_Configuration.php 3 years ago Track_Resource_Changes.php 3 years ago View.php 3 years ago View_Counter.php 3 years ago WP_Option_Cache_Bust.php 3 years ago WooCommerce_Order.php 3 years ago
Settings.php
268 lines
1 <?php
2
3 namespace IAWP_SCOPED\IAWP;
4
5 use IAWP_SCOPED\IAWP\Utils\String_Util;
6 class Settings
7 {
8 public function __construct()
9 {
10 \add_action('admin_init', [$this, 'register_settings']);
11 \add_action('admin_init', [$this, 'register_view_counter_settings']);
12 \add_action('admin_init', [$this, 'register_blocked_ip_settings']);
13 \add_action('admin_init', [$this, 'register_block_by_role_settings']);
14 if (\IAWP_SCOPED\iawp_is_pro()) {
15 \add_action('admin_init', [$this, 'register_email_report_settings']);
16 }
17 }
18 /**
19 * @return array
20 */
21 private function get_editable_roles() : array
22 {
23 $editable_roles = [];
24 $wp_roles = \wp_roles()->roles;
25 \array_walk($wp_roles, function ($role, $role_key) use(&$editable_roles) {
26 if ($role_key === 'administrator') {
27 return;
28 }
29 $read_only_access = $role['capabilities']['iawp_read_only_access'] ?? \false;
30 $full_access = $role['capabilities']['iawp_full_access'] ?? \false;
31 $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];
32 });
33 return $editable_roles;
34 }
35 public function render_settings()
36 {
37 echo \IAWP_SCOPED\iawp()->templates()->render('settings/index');
38 if (\IAWP_SCOPED\iawp_is_pro()) {
39 echo \IAWP_SCOPED\iawp()->templates()->render('settings/email_reports', ['time' => \IAWP_SCOPED\iawp()->get_option('iawp_email_report_time', 9), 'message' => \IAWP_SCOPED\iawp()->get_option('iawp_email_report_message', \esc_html__("Please find the performance report attached to this email. It includes last month's views & visitors, as well as the top pages, referrers, and countries.", 'independent-analytics')), 'emails' => \IAWP_SCOPED\iawp()->get_option('iawp_email_report_email_addresses', [])]);
40 }
41 echo \IAWP_SCOPED\iawp()->templates()->render('settings/block_ips', ['ips' => \IAWP_SCOPED\iawp()->get_option('iawp_blocked_ips', [])]);
42 echo \IAWP_SCOPED\iawp()->templates()->render('settings/block_by_role', ['roles' => \wp_roles()->roles, 'blocked' => \IAWP_SCOPED\iawp()->get_option('iawp_blocked_roles', [])]);
43 echo \IAWP_SCOPED\iawp()->templates()->render('settings/capabilities', ['editable_roles' => $this->get_editable_roles(), 'capabilities' => Capability_Manager::all_capabilities()]);
44 echo \IAWP_SCOPED\iawp()->templates()->render('settings/view_counter');
45 echo \IAWP_SCOPED\iawp()->templates()->render('settings/export');
46 echo \IAWP_SCOPED\iawp()->templates()->render('settings/delete', ['site_name' => \get_bloginfo('name'), 'site_url' => \site_url()]);
47 }
48 public function register_settings()
49 {
50 \add_settings_section('iawp-settings-section', \esc_html__('Basic Settings', 'independent-analytics'), function () {
51 }, 'independent-analytics-settings');
52 $args = ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean'];
53 \register_setting('iawp_settings', 'iawp_dark_mode', $args);
54 \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']);
55 \register_setting('iawp_settings', 'iawp_track_authenticated_users', $args);
56 \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']);
57 \register_setting('iawp_settings', 'iawp_disable_admin_toolbar_analytics', $args);
58 \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');
59 $args = ['type' => 'integer', 'default' => 0, 'sanitize_callback' => 'absint'];
60 \register_setting('iawp_settings', 'iawp_dow', $args);
61 \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']);
62 $args = ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean'];
63 \register_setting('iawp_settings', 'iawp_need_clear_cache', $args);
64 }
65 public function dark_mode_callback()
66 {
67 echo \IAWP_SCOPED\iawp()->templates()->render('settings/dark_mode', ['dark_mode' => \IAWP_SCOPED\iawp()->get_option('iawp_dark_mode', \false)]);
68 }
69 public function track_authenticated_users_callback()
70 {
71 echo \IAWP_SCOPED\iawp()->templates()->render('settings/track_authenticated_users', ['track_authenticated_users' => \IAWP_SCOPED\iawp()->get_option('iawp_track_authenticated_users', \false)]);
72 }
73 public function disable_admin_toolbar_analytics_callback()
74 {
75 echo \IAWP_SCOPED\iawp()->templates()->render('settings/disable_admin_toolbar_analytics', ['value' => \IAWP_SCOPED\iawp()->get_option('iawp_disable_admin_toolbar_analytics', \false)]);
76 }
77 public function starting_dow_callback()
78 {
79 echo \IAWP_SCOPED\iawp()->templates()->render('settings/first_day_of_week', ['day_of_week' => \IAWP_SCOPED\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')]]);
80 }
81 public function register_view_counter_settings()
82 {
83 \add_settings_section('iawp-view-counter-settings-section', \esc_html__('Public View Counter', 'independent-analytics'), function () {
84 }, 'independent-analytics-view-counter-settings');
85 $args = ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean'];
86 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_enable', $args);
87 \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']);
88 $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_view_counter_post_types']];
89 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_post_types', $args);
90 \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']);
91 $args = ['type' => 'string', 'default' => 'after', 'sanitize_callback' => [$this, 'sanitize_view_counter_position']];
92 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_position', $args);
93 \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']);
94 $args = ['type' => 'string', 'default' => '', 'sanitize_callback' => [$this, 'sanitize_view_counter_exclude']];
95 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_exclude', $args);
96 \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']);
97 $default = \function_exists('IAWP_SCOPED\\pll__') ? pll__('Views:', 'independent-analytics') : \__('Views:', 'independent-analytics');
98 $args = ['type' => 'string', 'default' => $default, 'sanitize_callback' => 'sanitize_text_field'];
99 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_label', $args);
100 \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']);
101 $args = ['type' => 'boolean', 'default' => \true, 'sanitize_callback' => 'rest_sanitize_boolean'];
102 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_icon', $args);
103 \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']);
104 }
105 public function view_counter_enable_callback()
106 {
107 echo \IAWP_SCOPED\iawp()->templates()->render('settings/view_counter/enable', ['enable' => \IAWP_SCOPED\iawp()->get_option('iawp_view_counter_enable', \false)]);
108 }
109 public function view_counter_post_types_callback()
110 {
111 $site_post_types = \get_post_types(['public' => \true], 'objects');
112 $counter = 0;
113 foreach ($site_post_types as $post_type) {
114 echo \IAWP_SCOPED\iawp()->templates()->render('settings/view_counter/post_types', ['counter' => $counter, 'post_type' => $post_type, 'saved' => \IAWP_SCOPED\iawp()->get_option('iawp_view_counter_post_types', [])]);
115 $counter++;
116 }
117 ?>
118 <p class="description"><?php
119 \esc_html_e('Uncheck all boxes to only show view count manually. See shortcode documentation below for details.', 'independent-analytics');
120 ?></p>
121 <?php
122 }
123 public function view_counter_position_callback()
124 {
125 echo \IAWP_SCOPED\iawp()->templates()->render('settings/view_counter/position', ['position' => \IAWP_SCOPED\iawp()->get_option('iawp_view_counter_position', 'after')]);
126 }
127 public function view_counter_exclude_callback()
128 {
129 echo \IAWP_SCOPED\iawp()->templates()->render('settings/view_counter/exclude', ['exclude' => \IAWP_SCOPED\iawp()->get_option('iawp_view_counter_exclude', '')]);
130 }
131 public function view_counter_label_callback()
132 {
133 $default = \function_exists('IAWP_SCOPED\\pll__') ? pll__('Views:', 'independent-analytics') : \__('Views:', 'independent-analytics');
134 echo \IAWP_SCOPED\iawp()->templates()->render('settings/view_counter/label', ['label' => \IAWP_SCOPED\iawp()->get_option('iawp_view_counter_label', $default)]);
135 }
136 public function view_counter_icon_callback()
137 {
138 echo \IAWP_SCOPED\iawp()->templates()->render('settings/view_counter/icon', ['icon' => \get_option('iawp_view_counter_icon', \true)]);
139 }
140 public function register_blocked_ip_settings()
141 {
142 \add_settings_section('iawp-blocked-ips-settings-section', \esc_html__('Block IP Addresses', 'independent-analytics'), function () {
143 }, 'iawp-blocked-ips-settings');
144 $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_blocked_ips']];
145 \register_setting('iawp_blocked_ip_settings', 'iawp_blocked_ips', $args);
146 }
147 public function register_user_permission_settings()
148 {
149 \add_settings_section('iawp-user-permission-settings-section', \esc_html__('User Permissions', 'independent-analytics'), function () {
150 }, 'iawp-user-permission-settings');
151 $args = ['type' => 'bool', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean'];
152 \register_setting('iawp_user_permission_settings', 'iawp_white_label', $args);
153 }
154 public function register_email_report_settings()
155 {
156 \add_settings_section('iawp-email-report-settings-section', \esc_html__('Scheduled Email Reports', 'independent-analytics'), function () {
157 }, 'iawp-email-report-settings');
158 $args = ['type' => 'number', 'default' => 9, 'sanitize_callback' => [$this, 'sanitize_email_report_time']];
159 \register_setting('iawp_email_report_settings', 'iawp_email_report_time', $args);
160 $args = ['type' => 'string', 'default' => \esc_html__("Please find the performance report attached to this email. It includes last month's views & visitors, as well as the top pages, referrers, and countries.", 'independent-analytics'), 'sanitize_callback' => 'sanitize_textarea_field'];
161 \register_setting('iawp_email_report_settings', 'iawp_email_report_message', $args);
162 $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_email_addresses']];
163 \register_setting('iawp_email_report_settings', 'iawp_email_report_email_addresses', $args);
164 }
165 public function register_block_by_role_settings()
166 {
167 \add_settings_section('iawp-block-by-role-settings-section', \esc_html__('Block by User Role', 'independent-analytics'), function () {
168 }, 'iawp-block-by-role-settings');
169 $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_blocked_roles']];
170 \register_setting('iawp_block_by_role_settings', 'iawp_blocked_roles', $args);
171 }
172 public function sanitize_view_counter_post_types($user_input)
173 {
174 $site_post_types = \get_post_types(['public' => \true]);
175 $to_save = [];
176 foreach ($user_input as $post_type) {
177 if (\in_array($post_type, $site_post_types)) {
178 $to_save[] = $post_type;
179 }
180 }
181 return $to_save;
182 }
183 public function sanitize_view_counter_position($user_input)
184 {
185 if (\in_array($user_input, ['before', 'after', 'both'])) {
186 return $user_input;
187 } else {
188 return 'after';
189 }
190 }
191 public function sanitize_view_counter_exclude($user_input)
192 {
193 $user_input = \explode(',', $user_input);
194 $to_save = [];
195 foreach ($user_input as $id) {
196 $save = \absint($id);
197 if ($save != 0) {
198 $to_save[] = $save;
199 }
200 }
201 $to_save = \implode(',', $to_save);
202 return $to_save;
203 }
204 public function sanitize_blocked_ips($user_input)
205 {
206 $to_save = [];
207 foreach ($user_input as $ip) {
208 if (!String_Util::str_contains($ip, '*')) {
209 if (\filter_var($ip, \FILTER_VALIDATE_IP)) {
210 $to_save[] = $ip;
211 }
212 } else {
213 $subs = \explode('.', $ip);
214 $built_ip = [];
215 for ($i = 0; $i < \count($subs); $i++) {
216 if ($subs[$i] == '*') {
217 $built_ip[] = $subs[$i];
218 } else {
219 $int = \absint($subs[$i]);
220 if ($int < 0 || $int > 255) {
221 break;
222 }
223 $built_ip[] = $int;
224 }
225 if ($i == \count($subs) - 1) {
226 $to_save[] = \implode('.', $built_ip);
227 }
228 }
229 }
230 }
231 return $to_save;
232 }
233 public function sanitize_email_addresses($emails)
234 {
235 $to_save = [];
236 foreach ($emails as $email) {
237 $cleaned = \sanitize_email($email);
238 if (\is_email($cleaned)) {
239 $to_save[] = $cleaned;
240 }
241 }
242 return $to_save;
243 }
244 public function sanitize_email_report_time($user_time)
245 {
246 $accepted_times = [];
247 for ($i = 0; $i < 24; $i++) {
248 $accepted_times[] = $i;
249 }
250 if (\in_array($user_time, $accepted_times)) {
251 return $user_time;
252 } else {
253 return 9;
254 }
255 }
256 public function sanitize_blocked_roles($blocked_roles)
257 {
258 $to_save = [];
259 $user_roles = \array_keys(\wp_roles()->roles);
260 foreach ($blocked_roles as $blocked) {
261 if (\in_array($blocked, $user_roles)) {
262 $to_save[] = $blocked;
263 }
264 }
265 return $to_save;
266 }
267 }
268