PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.10
Independent Analytics – WordPress Analytics Plugin v1.10
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 / inc / settings.php
independent-analytics / inc Last commit date
ajax 3 years ago databases 3 years ago migrations 3 years ago models 3 years ago queries 3 years ago utils 3 years ago chart.php 3 years ago chart_geo.php 3 years ago dashboard_widget.php 3 years ago db.php 3 years ago filters.php 3 years ago freemius.php 3 years ago independent_analytics.php 3 years ago known_referrers.php 3 years ago quick_stats.php 3 years ago rest_api.php 3 years ago settings.php 3 years ago table.php 3 years ago table_geo.php 3 years ago table_referrers.php 3 years ago table_views.php 3 years ago track_resource_changes.php 3 years ago view_counter.php 3 years ago
settings.php
217 lines
1 <?php
2
3 namespace IAWP;
4
5 class Settings
6 {
7 public function __construct()
8 {
9 add_action('admin_init', [$this, 'register_settings']);
10 add_action('admin_init', [$this, 'register_view_counter_settings']);
11 }
12
13 public function render_settings()
14 {
15 echo IAWP()->templates()->render('settings/index', [
16 'site_name' => get_bloginfo('name'),
17 'site_url' => site_url(),
18 ]);
19 }
20
21 public function register_settings()
22 {
23 add_settings_section('iawp-settings-section', esc_html__('Analytics Settings', 'iawp'), '', 'independent-analytics-settings');
24
25 $args = [
26 'type' => 'boolean',
27 'default' => false,
28 'sanitize_callback' => 'rest_sanitize_boolean',
29 ];
30 register_setting('iawp_settings', 'iawp_dark_mode', $args);
31 add_settings_field('iawp_dark_mode', esc_html__('Dark mode', 'iawp'), [$this, 'dark_mode_callback'], 'independent-analytics-settings', 'iawp-settings-section', ['class' => 'dark-mode']);
32
33 register_setting('iawp_settings', 'iawp_track_authenticated_users', $args);
34 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']);
35
36 $args = [
37 'type' => 'integer',
38 'default' => 1,
39 'sanitize_callback' => 'absint',
40 ];
41 register_setting('iawp_settings', 'iawp_dow', $args);
42 add_settings_field('iawp_dow', esc_html__('First day of week', 'iawp'), [$this, 'starting_dow_callback'], 'independent-analytics-settings', 'iawp-settings-section', ['class' => 'dow']);
43 }
44
45 public function dark_mode_callback()
46 {
47 echo IAWP()->templates()->render('settings/dark_mode', [
48 'dark_mode' => IAWP()->get_option('iawp_dark_mode', false),
49 ]);
50 }
51
52 public function track_authenticated_users_callback()
53 {
54 echo IAWP()->templates()->render('settings/track_authenticated_users', [
55 'track_authenticated_users' => IAWP()->get_option('iawp_track_authenticated_users', false),
56 ]);
57 }
58
59 public function starting_dow_callback()
60 {
61 echo IAWP()->templates()->render('settings/first_day_of_week', [
62 'day_of_week' => IAWP()->get_option('iawp_dow', 0),
63 'days' => [
64 0 => esc_html__('Sunday', 'iawp'),
65 1 => esc_html__('Monday', 'iawp'),
66 2 => esc_html__('Tuesday', 'iawp'),
67 3 => esc_html__('Wednesday', 'iawp'),
68 4 => esc_html__('Thursday', 'iawp'),
69 5 => esc_html__('Friday', 'iawp'),
70 6 => esc_html__('Saturday', 'iawp'),
71 ],
72 ]);
73 }
74
75 public function register_view_counter_settings()
76 {
77 add_settings_section('iawp-view-counter-settings-section', esc_html__('Public View Counter', 'iawp'), '', 'independent-analytics-view-counter-settings');
78
79 $args = [
80 'type' => 'boolean',
81 'default' => false,
82 'sanitize_callback' => 'rest_sanitize_boolean',
83 ];
84 register_setting('iawp_view_counter_settings', 'iawp_view_counter_enable', $args);
85 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']);
86
87 $args = [
88 'type' => 'array',
89 'default' => [],
90 'sanitize_callback' => [$this, 'sanitize_view_counter_post_types'],
91 ];
92 register_setting('iawp_view_counter_settings', 'iawp_view_counter_post_types', $args);
93 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']);
94
95 $args = [
96 'type' => 'string',
97 'default' => 'after',
98 'sanitize_callback' => [$this, 'sanitize_view_counter_position'],
99 ];
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', 'iawp'), [$this, 'view_counter_position_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'position']);
102
103 $args = [
104 'type' => 'string',
105 'default' => '',
106 'sanitize_callback' => [$this, 'sanitize_view_counter_exclude'],
107 ];
108 register_setting('iawp_view_counter_settings', 'iawp_view_counter_exclude', $args);
109 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']);
110
111 $args = [
112 'type' => 'string',
113 'default' => '',
114 'sanitize_callback' => 'sanitize_text_field',
115 ];
116 register_setting('iawp_view_counter_settings', 'iawp_view_counter_label', $args);
117 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']);
118
119 $args = [
120 'type' => 'boolean',
121 'default' => true,
122 'sanitize_callback' => 'rest_sanitize_boolean',
123 ];
124 register_setting('iawp_view_counter_settings', 'iawp_view_counter_icon', $args);
125 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']);
126 }
127
128 public function view_counter_enable_callback()
129 {
130 echo IAWP()->templates()->render('settings/view_counter/enable', [
131 'enable' => IAWP()->get_option('iawp_view_counter_enable', false),
132 ]);
133 }
134
135 public function view_counter_post_types_callback()
136 {
137 $site_post_types = get_post_types(['public' => true], 'objects');
138 $counter = 0;
139 foreach ($site_post_types as $post_type) {
140 echo IAWP()->templates()->render('settings/view_counter/post_types', [
141 'counter' => $counter,
142 'post_type' => $post_type,
143 'saved' => IAWP()->get_option('iawp_view_counter_post_types', []),
144 ]);
145 $counter++;
146 } ?>
147 <p class="description"><?php esc_html_e('Uncheck all boxes to only show view count manually. See shortcode documentation below for details.', 'iawp'); ?></p>
148 <?php
149 }
150
151 public function view_counter_position_callback()
152 {
153 echo IAWP()->templates()->render('settings/view_counter/position', [
154 'position' => IAWP()->get_option('iawp_view_counter_position', 'after'),
155 ]);
156 }
157
158 public function view_counter_exclude_callback()
159 {
160 echo IAWP()->templates()->render('settings/view_counter/exclude', [
161 'exclude' => IAWP()->get_option('iawp_view_counter_exclude', ''),
162 ]);
163 }
164
165 public function view_counter_label_callback()
166 {
167 echo IAWP()->templates()->render('settings/view_counter/label', [
168 'label' => IAWP()->get_option('iawp_view_counter_label', esc_html__('Views:', 'iawp')),
169 ]);
170 }
171
172 public function view_counter_icon_callback()
173 {
174 echo IAWP()->templates()->render('settings/view_counter/icon', [
175 'icon' => get_option('iawp_view_counter_icon', true),
176 ]);
177 }
178
179 public function sanitize_view_counter_post_types($user_input)
180 {
181 $site_post_types = get_post_types(['public' => true]);
182 $to_save = [];
183 foreach ($user_input as $post_type) {
184 if (in_array($post_type, $site_post_types)) {
185 $to_save[] = $post_type;
186 }
187 }
188
189 return $to_save;
190 }
191
192 public function sanitize_view_counter_position($user_input)
193 {
194 if (in_array($user_input, ['before', 'after', 'both'])) {
195 return $user_input;
196 } else {
197 return 'after';
198 }
199 }
200
201 public function sanitize_view_counter_exclude($user_input)
202 {
203 $user_input = explode(',', $user_input);
204 $to_save = [];
205
206 foreach ($user_input as $id) {
207 $save = absint($id);
208 if ($save != 0) {
209 $to_save[] = $save;
210 }
211 }
212 $to_save = implode(',', $to_save);
213
214 return $to_save;
215 }
216 }
217