PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.22.1
Independent Analytics – WordPress Analytics Plugin v1.22.1
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 Migrations 3 years ago Models 3 years ago Queries 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 Current_Resource.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 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 Settings.php 3 years ago Track_Resource_Changes.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
262 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.", 'iawp')), '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', 'iawp'), 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', 'iawp'), [$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', 'iawp'), [$this, 'track_authenticated_users_callback'], 'independent-analytics-settings', 'iawp-settings-section', ['class' => 'logged-in']);
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', 'iawp'), [$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_need_clear_cache', $args);
62 }
63 public function dark_mode_callback()
64 {
65 echo \IAWP_SCOPED\iawp()->templates()->render('settings/dark_mode', ['dark_mode' => \IAWP_SCOPED\iawp()->get_option('iawp_dark_mode', \false)]);
66 }
67 public function track_authenticated_users_callback()
68 {
69 echo \IAWP_SCOPED\iawp()->templates()->render('settings/track_authenticated_users', ['track_authenticated_users' => \IAWP_SCOPED\iawp()->get_option('iawp_track_authenticated_users', \false)]);
70 }
71 public function starting_dow_callback()
72 {
73 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', 'iawp'), 1 => \esc_html__('Monday', 'iawp'), 2 => \esc_html__('Tuesday', 'iawp'), 3 => \esc_html__('Wednesday', 'iawp'), 4 => \esc_html__('Thursday', 'iawp'), 5 => \esc_html__('Friday', 'iawp'), 6 => \esc_html__('Saturday', 'iawp')]]);
74 }
75 public function register_view_counter_settings()
76 {
77 \add_settings_section('iawp-view-counter-settings-section', \esc_html__('Public View Counter', 'iawp'), function () {
78 }, 'independent-analytics-view-counter-settings');
79 $args = ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean'];
80 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_enable', $args);
81 \add_settings_field('iawp_view_counter_enable', \esc_html__('Enable the view counter', 'iawp'), [$this, 'view_counter_enable_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'enable']);
82 $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_view_counter_post_types']];
83 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_post_types', $args);
84 \add_settings_field('iawp_view_counter_post_types', \esc_html__('Display on these post types', 'iawp'), [$this, 'view_counter_post_types_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'post-types']);
85 $args = ['type' => 'string', 'default' => 'after', 'sanitize_callback' => [$this, 'sanitize_view_counter_position']];
86 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_position', $args);
87 \add_settings_field('iawp_view_counter_position', \esc_html__('Show it in this location', 'iawp'), [$this, 'view_counter_position_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'position']);
88 $args = ['type' => 'string', 'default' => '', 'sanitize_callback' => [$this, 'sanitize_view_counter_exclude']];
89 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_exclude', $args);
90 \add_settings_field('iawp_view_counter_exclude', \esc_html__('Exclude these pages', 'iawp'), [$this, 'view_counter_exclude_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'exclude']);
91 $default = \function_exists('IAWP_SCOPED\\pll__') ? pll__('Views:', 'iawp') : \__('Views:', 'iawp');
92 $args = ['type' => 'string', 'default' => $default, 'sanitize_callback' => 'sanitize_text_field'];
93 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_label', $args);
94 \add_settings_field('iawp_view_counter_label', \esc_html__('Edit the label', 'iawp'), [$this, 'view_counter_label_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'counter-label']);
95 $args = ['type' => 'boolean', 'default' => \true, 'sanitize_callback' => 'rest_sanitize_boolean'];
96 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_icon', $args);
97 \add_settings_field('iawp_view_counter_icon', \esc_html__('Display the icon', 'iawp'), [$this, 'view_counter_icon_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'icon']);
98 }
99 public function view_counter_enable_callback()
100 {
101 echo \IAWP_SCOPED\iawp()->templates()->render('settings/view_counter/enable', ['enable' => \IAWP_SCOPED\iawp()->get_option('iawp_view_counter_enable', \false)]);
102 }
103 public function view_counter_post_types_callback()
104 {
105 $site_post_types = \get_post_types(['public' => \true], 'objects');
106 $counter = 0;
107 foreach ($site_post_types as $post_type) {
108 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', [])]);
109 $counter++;
110 }
111 ?>
112 <p class="description"><?php
113 \esc_html_e('Uncheck all boxes to only show view count manually. See shortcode documentation below for details.', 'iawp');
114 ?></p>
115 <?php
116 }
117 public function view_counter_position_callback()
118 {
119 echo \IAWP_SCOPED\iawp()->templates()->render('settings/view_counter/position', ['position' => \IAWP_SCOPED\iawp()->get_option('iawp_view_counter_position', 'after')]);
120 }
121 public function view_counter_exclude_callback()
122 {
123 echo \IAWP_SCOPED\iawp()->templates()->render('settings/view_counter/exclude', ['exclude' => \IAWP_SCOPED\iawp()->get_option('iawp_view_counter_exclude', '')]);
124 }
125 public function view_counter_label_callback()
126 {
127 $default = \function_exists('IAWP_SCOPED\\pll__') ? pll__('Views:', 'iawp') : \__('Views:', 'iawp');
128 echo \IAWP_SCOPED\iawp()->templates()->render('settings/view_counter/label', ['label' => \IAWP_SCOPED\iawp()->get_option('iawp_view_counter_label', $default)]);
129 }
130 public function view_counter_icon_callback()
131 {
132 echo \IAWP_SCOPED\iawp()->templates()->render('settings/view_counter/icon', ['icon' => \get_option('iawp_view_counter_icon', \true)]);
133 }
134 public function register_blocked_ip_settings()
135 {
136 \add_settings_section('iawp-blocked-ips-settings-section', \esc_html__('Block IP Addresses', 'iawp'), function () {
137 }, 'iawp-blocked-ips-settings');
138 $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_blocked_ips']];
139 \register_setting('iawp_blocked_ip_settings', 'iawp_blocked_ips', $args);
140 }
141 public function register_user_permission_settings()
142 {
143 \add_settings_section('iawp-user-permission-settings-section', \esc_html__('User Permissions', 'iawp'), function () {
144 }, 'iawp-user-permission-settings');
145 $args = ['type' => 'bool', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean'];
146 \register_setting('iawp_user_permission_settings', 'iawp_white_label', $args);
147 }
148 public function register_email_report_settings()
149 {
150 \add_settings_section('iawp-email-report-settings-section', \esc_html__('Scheduled Email Reports', 'iawp'), function () {
151 }, 'iawp-email-report-settings');
152 $args = ['type' => 'number', 'default' => 9, 'sanitize_callback' => [$this, 'sanitize_email_report_time']];
153 \register_setting('iawp_email_report_settings', 'iawp_email_report_time', $args);
154 $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.", 'iawp'), 'sanitize_callback' => 'sanitize_textarea_field'];
155 \register_setting('iawp_email_report_settings', 'iawp_email_report_message', $args);
156 $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_email_addresses']];
157 \register_setting('iawp_email_report_settings', 'iawp_email_report_email_addresses', $args);
158 }
159 public function register_block_by_role_settings()
160 {
161 \add_settings_section('iawp-block-by-role-settings-section', \esc_html__('Block by User Role', 'iawp'), function () {
162 }, 'iawp-block-by-role-settings');
163 $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_blocked_roles']];
164 \register_setting('iawp_block_by_role_settings', 'iawp_blocked_roles', $args);
165 }
166 public function sanitize_view_counter_post_types($user_input)
167 {
168 $site_post_types = \get_post_types(['public' => \true]);
169 $to_save = [];
170 foreach ($user_input as $post_type) {
171 if (\in_array($post_type, $site_post_types)) {
172 $to_save[] = $post_type;
173 }
174 }
175 return $to_save;
176 }
177 public function sanitize_view_counter_position($user_input)
178 {
179 if (\in_array($user_input, ['before', 'after', 'both'])) {
180 return $user_input;
181 } else {
182 return 'after';
183 }
184 }
185 public function sanitize_view_counter_exclude($user_input)
186 {
187 $user_input = \explode(',', $user_input);
188 $to_save = [];
189 foreach ($user_input as $id) {
190 $save = \absint($id);
191 if ($save != 0) {
192 $to_save[] = $save;
193 }
194 }
195 $to_save = \implode(',', $to_save);
196 return $to_save;
197 }
198 public function sanitize_blocked_ips($user_input)
199 {
200 $to_save = [];
201 foreach ($user_input as $ip) {
202 if (!String_Util::str_contains($ip, '*')) {
203 if (\filter_var($ip, \FILTER_VALIDATE_IP)) {
204 $to_save[] = $ip;
205 }
206 } else {
207 $subs = \explode('.', $ip);
208 $built_ip = [];
209 for ($i = 0; $i < \count($subs); $i++) {
210 if ($subs[$i] == '*') {
211 $built_ip[] = $subs[$i];
212 } else {
213 $int = \absint($subs[$i]);
214 if ($int < 0 || $int > 255) {
215 break;
216 }
217 $built_ip[] = $int;
218 }
219 if ($i == \count($subs) - 1) {
220 $to_save[] = \implode('.', $built_ip);
221 }
222 }
223 }
224 }
225 return $to_save;
226 }
227 public function sanitize_email_addresses($emails)
228 {
229 $to_save = [];
230 foreach ($emails as $email) {
231 $cleaned = \sanitize_email($email);
232 if (\is_email($cleaned)) {
233 $to_save[] = $cleaned;
234 }
235 }
236 return $to_save;
237 }
238 public function sanitize_email_report_time($user_time)
239 {
240 $accepted_times = [];
241 for ($i = 0; $i < 24; $i++) {
242 $accepted_times[] = $i;
243 }
244 if (\in_array($user_time, $accepted_times)) {
245 return $user_time;
246 } else {
247 return 9;
248 }
249 }
250 public function sanitize_blocked_roles($blocked_roles)
251 {
252 $to_save = [];
253 $user_roles = \array_keys(\wp_roles()->roles);
254 foreach ($blocked_roles as $blocked) {
255 if (\in_array($blocked, $user_roles)) {
256 $to_save[] = $blocked;
257 }
258 }
259 return $to_save;
260 }
261 }
262