PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.4.4
Post Views Counter v1.4.4
1.7.13 1.7.12 1.7.11 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.2 1.3.2.1 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.7.10 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9
post-views-counter / includes / class-settings.php
post-views-counter / includes Last commit date
class-admin.php 2 years ago class-columns.php 2 years ago class-counter.php 2 years ago class-crawler-detect.php 2 years ago class-cron.php 2 years ago class-dashboard.php 2 years ago class-frontend.php 2 years ago class-functions.php 2 years ago class-query.php 2 years ago class-settings-api.php 2 years ago class-settings.php 2 years ago class-update.php 2 years ago class-widgets.php 2 years ago functions.php 2 years ago
class-settings.php
1291 lines
1 <?php
2 // exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) )
4 exit;
5
6 /**
7 * Post_Views_Counter_Settings class.
8 *
9 * @class Post_Views_Counter_Settings
10 */
11 class Post_Views_Counter_Settings {
12
13 /**
14 * Class constructor.
15 *
16 * @return void
17 */
18 public function __construct() {
19 // actions
20 add_action( 'admin_init', [ $this, 'update_counter_mode' ], 12 );
21 add_action( 'pvc_settings_sidebar', [ $this, 'settings_sidebar' ], 12 );
22 add_action( 'pvc_settings_form', [ $this, 'settings_form' ], 10, 4 );
23
24 // filters
25 add_filter( 'post_views_counter_settings_data', [ $this, 'settings_data' ] );
26 add_filter( 'post_views_counter_settings_pages', [ $this, 'settings_page' ] );
27 add_filter( 'post_views_counter_settings_page_class', [ $this, 'settings_page_class' ] );
28 }
29
30 /**
31 * Add hidden inputs to redirect to valid page after changing menu position.
32 *
33 * @param string $setting
34 * @param string $page_type
35 * @param string $url_page
36 * @param string $tab_key
37 * @return void
38 */
39 public function settings_form( $setting, $page_type, $url_page, $tab_key ) {
40 // get main instance
41 $pvc = Post_Views_Counter();
42
43 // topmenu referer
44 $topmenu = '<input type="hidden" name="_wp_http_referer" data-pvc-menu="topmenu" value="' .esc_url( admin_url( 'admin.php?page=post-views-counter' . ( $tab_key !== '' ? '&tab=' . $tab_key : '' ) ) ) . '" />';
45
46 // submenu referer
47 $submenu = '<input type="hidden" name="_wp_http_referer" data-pvc-menu="submenu" value="' .esc_url( admin_url( 'options-general.php?page=post-views-counter' . ( $tab_key !== '' ? '&tab=' . $tab_key : '' ) ) ) . '" />';
48
49 if ( $pvc->options['other']['menu_position'] === 'sub' )
50 echo $topmenu . $submenu;
51 else
52 echo $submenu . $topmenu;
53 }
54
55 /**
56 * Display settings sidebar.
57 *
58 * @return void
59 */
60 public function settings_sidebar() {
61 // get main instance
62 $pvc = Post_Views_Counter();
63
64 $license_data = get_option( 'post_views_counter_pro_license', [] );
65 $is_pro = class_exists( 'Post_Views_Counter_Pro' );
66
67 if ( ! $is_pro ) {
68 echo '
69 <div class="post-views-sidebar">
70 <div class="post-views-credits">
71 <div class="inside">
72 <div class="inner">
73 <div class="pvc-sidebar-info">
74 <div class="pvc-sidebar-head">
75 <p>' . esc_html__( "You're using", 'post-views-counter' ) . '</p>
76 <h2>Post Views Counter</h2>
77 <h2>Lite</h2>
78 </div>
79 <div class="pvc-sidebar-body">
80 <p><span class="pvc-icon pvc-icon-arrow-right"></span>' . __( 'Get <b>more accurate information</b> about the number of views of your site, regardless of what the user is visiting.', 'post-views-counter' ) . '</p>
81 <p><span class="pvc-icon pvc-icon-arrow-right"></span>' . __( 'Unlock <b>optimization features</b> and speed up view count tracking.', 'post-views-counter' ) . '</p>
82 <p><span class="pvc-icon pvc-icon-arrow-right"></span>' . __( 'Take your insights to the next level with dedicated, <b>customizable reporting</b>.', 'post-views-counter' ) . '</p>
83 </div>
84 <div class="pvc-pricing-footer">
85 <a href="https://postviewscounter.com/upgrade/?utm_source=post-views-counter-lite&utm_medium=button&utm_campaign=upgrade-to-pro" class="button button-secondary button-hero pvc-button" target="_blank">' . esc_html__( 'Upgrade to Pro', 'post-views-counter' ) . '</a>
86 </div>
87 </div>
88 </div>
89 </div>
90 </div>
91 </div>';
92 }
93 }
94
95 /**
96 * Update counter mode.
97 *
98 * @return void
99 */
100 public function update_counter_mode() {
101 // get main instance
102 $pvc = Post_Views_Counter();
103
104 // get settings
105 $settings = $pvc->settings_api->get_settings();
106
107 // fast ajax as active but not available counter mode?
108 if ( $pvc->options['general']['counter_mode'] === 'ajax' && in_array( 'ajax', $settings['post-views-counter']['fields']['counter_mode']['disabled'], true ) ) {
109 // set standard javascript ajax calls
110 $pvc->options['general']['counter_mode'] = 'js';
111
112 // update database options
113 update_option( 'post_views_counter_settings_general', $pvc->options['general'] );
114 }
115 }
116
117 /**
118 * Get available counter modes.
119 *
120 * @return array
121 */
122 public function get_counter_modes() {
123 // counter modes
124 $modes = [
125 'php' => __( 'PHP', 'post-views-counter' ),
126 'js' => __( 'JavaScript', 'post-views-counter' ),
127 'rest_api' => __( 'REST API', 'post-views-counter' ),
128 'ajax' => __( 'Fast AJAX', 'post-views-counter' )
129 ];
130
131 return apply_filters( 'pvc_get_counter_modes', $modes );
132 }
133
134 /**
135 * Add settings data.
136 *
137 * @param array $settings
138 * @return array
139 */
140 public function settings_data( $settings ) {
141 // get main instance
142 $pvc = Post_Views_Counter();
143
144 // time types
145 $time_types = [
146 'minutes' => __( 'minutes', 'post-views-counter' ),
147 'hours' => __( 'hours', 'post-views-counter' ),
148 'days' => __( 'days', 'post-views-counter' ),
149 'weeks' => __( 'weeks', 'post-views-counter' ),
150 'months' => __( 'months', 'post-views-counter' ),
151 'years' => __( 'years', 'post-views-counter' )
152 ];
153
154 // user groups
155 $groups = [
156 'robots' => __( 'robots', 'post-views-counter' ),
157 'users' => __( 'logged in users', 'post-views-counter' ),
158 'guests' => __( 'guests', 'post-views-counter' ),
159 'roles' => __( 'selected user roles', 'post-views-counter' )
160 ];
161
162 // get user roles
163 $user_roles = $pvc->functions->get_user_roles();
164
165 // get post types
166 $post_types = $pvc->functions->get_post_types();
167
168 // add settings
169 $settings['post-views-counter'] = [
170 'label' => __( 'Post Views Counter Settings', 'post-views-counter' ),
171 'form' => [
172 'reports' => [
173 'buttons' => false
174 ]
175 ],
176 'option_name' => [
177 'general' => 'post_views_counter_settings_general',
178 'display' => 'post_views_counter_settings_display',
179 'reports' => 'post_views_counter_settings_reports',
180 'other' => 'post_views_counter_settings_other'
181 ],
182 'validate' => [ $this, 'validate_settings' ],
183 'sections' => [
184 'post_views_counter_general_settings' => [
185 'tab' => 'general'
186 ],
187 'post_views_counter_display_settings' => [
188 'tab' => 'display'
189 ],
190 'post_views_counter_reports_settings' => [
191 'tab' => 'reports',
192 'callback' => [ $this, 'section_reports_placeholder' ]
193 ],
194 'post_views_counter_other_settings' => [
195 'tab' => 'other'
196 ]
197 ],
198 'fields' => [
199 'post_types_count' => [
200 'tab' => 'general',
201 'title' => __( 'Post Types Count', 'post-views-counter' ),
202 'section' => 'post_views_counter_general_settings',
203 'type' => 'checkbox',
204 'display_type' => 'horizontal',
205 'description' => __( 'Select post types for which post views will be counted.', 'post-views-counter' ),
206 'options' => $post_types
207 ],
208 'taxonomies_count' => [
209 'tab' => 'general',
210 'title' => __( 'Taxonomies Count', 'post-views-counter' ),
211 'section' => 'post_views_counter_general_settings',
212 'type' => 'custom',
213 'label' => __( 'Enable to count taxonomy terms visits.', 'post-views-counter' ),
214 'class' => 'pvc-pro',
215 'skip_saving' => true,
216 'callback' => [ $this, 'setting_taxonomies_count' ]
217 ],
218 'users_count' => [
219 'tab' => 'general',
220 'title' => __( 'Authors Count', 'post-views-counter' ),
221 'section' => 'post_views_counter_general_settings',
222 'type' => 'custom',
223 'label' => __( 'Enable to count authors archive visits.', 'post-views-counter' ),
224 'class' => 'pvc-pro',
225 'skip_saving' => true,
226 'callback' => [ $this, 'setting_users_count' ]
227 ],
228 'other_count' => [
229 'tab' => 'general',
230 'title' => __( 'Other Count', 'post-views-counter' ),
231 'section' => 'post_views_counter_general_settings',
232 'type' => 'boolean',
233 'label' => __( 'Enable to count visits of front page, post type and date archives, 404 and search pages.', 'post-views-counter' ),
234 'class' => 'pvc-pro',
235 'disabled' => true,
236 'skip_saving' => true,
237 'value' => false
238 ],
239 'counter_mode' => [
240 'tab' => 'general',
241 'title' => __( 'Counter Mode', 'post-views-counter' ),
242 'section' => 'post_views_counter_general_settings',
243 'type' => 'radio',
244 'description' => __( 'Select the method of collecting post views data. If you are using any of the caching plugins select JavaScript, REST API or Fast AJAX (if available).', 'post-views-counter' ),
245 'class' => 'pvc-pro-extended',
246 'options' => $this->get_counter_modes(),
247 'disabled' => [ 'ajax' ]
248 ],
249 'post_views_column' => [
250 'tab' => 'general',
251 'title' => __( 'Post Views Column', 'post-views-counter' ),
252 'section' => 'post_views_counter_general_settings',
253 'type' => 'boolean',
254 'description' => '',
255 'label' => __( 'Enable to display post views count column for each of the selected post types.', 'post-views-counter' )
256 ],
257 'data_storage' => [
258 'tab' => 'general',
259 'title' => __( 'Data Storage', 'post-views-counter' ),
260 'section' => 'post_views_counter_general_settings',
261 'type' => 'radio',
262 'class' => 'pvc-pro',
263 'skip_saving' => true,
264 'description' => __( "Choose how to store the content views data in the user's browser - with or without cookies.", 'post-views-counter' ),
265 'options' => [
266 'cookies' => __( 'Cookies', 'post-views-counter' ),
267 'cookieless' => __( 'Cookieless', 'post-views-counter' )
268 ],
269 'disabled' => [ 'cookies', 'cookieless' ],
270 'value' => 'cookies'
271 ],
272 'amp_support' => [
273 'tab' => 'general',
274 'title' => __( 'AMP Support', 'post-views-counter' ),
275 'section' => 'post_views_counter_general_settings',
276 'type' => 'boolean',
277 'class' => 'pvc-pro',
278 'disabled' => true,
279 'skip_saving' => true,
280 'value' => false,
281 'label' => __( 'Enable to support Google AMP.', 'post-views-counter' ),
282 'description' => __( 'This feature requires official WordPress Google AMP plugin to be installed and activated.', 'post-views-counter' )
283 ],
284 'restrict_edit_views' => [
285 'tab' => 'general',
286 'title' => __( 'Restrict Edit', 'post-views-counter' ),
287 'section' => 'post_views_counter_general_settings',
288 'type' => 'boolean',
289 'description' => '',
290 'label' => __( 'Enable to restrict post views editing to admins only.', 'post-views-counter' )
291 ],
292 'time_between_counts' => [
293 'tab' => 'general',
294 'title' => __( 'Count Interval', 'post-views-counter' ),
295 'section' => 'post_views_counter_general_settings',
296 'type' => 'custom',
297 'description' => '',
298 'min' => 0,
299 'max' => 999999,
300 'options' => $time_types,
301 'callback' => [ $this, 'setting_time_between_counts' ],
302 'validate' => [ $this, 'validate_time_between_counts' ]
303 ],
304 'reset_counts' => [
305 'tab' => 'general',
306 'title' => __( 'Cleanup Interval', 'post-views-counter' ),
307 'section' => 'post_views_counter_general_settings',
308 'type' => 'custom',
309 'description' => sprintf( __( 'Delete single day post views data older than specified above. Enter %s if you want to preserve your daily views data regardless of its age.', 'post-views-counter' ), '<code>0</code>' ),
310 'min' => 0,
311 'max' => 999999,
312 'options' => $time_types,
313 'callback' => [ $this, 'setting_reset_counts' ],
314 'validate' => [ $this, 'validate_reset_counts' ]
315 ],
316 'object_cache' => [
317 'tab' => 'general',
318 'title' => __( 'Object Cache Support', 'post-views-counter' ),
319 'section' => 'post_views_counter_general_settings',
320 'type' => 'boolean',
321 'class' => 'pvc-pro',
322 'disabled' => true,
323 'value' => false,
324 'skip_saving' => true,
325 'label' => sprintf( __( 'Enable to use object cache optimization.', 'post-views-counter' ), '<code>Redis</code>', '<code>Memcached</code>' ),
326 'description' => sprintf( __( 'This feature requires a persistent object cache like %s or %s to be installed and activated.', 'post-views-counter' ), '<code>Redis</code>', '<code>Memcached</code>' )
327 ],
328 'exclude' => [
329 'tab' => 'general',
330 'title' => __( 'Exclude Visitors', 'post-views-counter' ),
331 'section' => 'post_views_counter_general_settings',
332 'type' => 'custom',
333 'description' => '',
334 'options' => [
335 'groups' => $groups,
336 'roles' => $user_roles
337 ],
338 'callback' => [ $this, 'setting_exclude' ],
339 'validate' => [ $this, 'validate_exclude' ]
340 ],
341 'exclude_ips' => [
342 'tab' => 'general',
343 'title' => __( 'Exclude IPs', 'post-views-counter' ),
344 'section' => 'post_views_counter_general_settings',
345 'type' => 'custom',
346 'description' => '',
347 'callback' => [ $this, 'setting_exclude_ips' ],
348 'validate' => [ $this, 'validate_exclude_ips' ]
349 ],
350 'strict_counts' => [
351 'tab' => 'general',
352 'title' => __( 'Strict counts', 'post-views-counter' ),
353 'section' => 'post_views_counter_general_settings',
354 'type' => 'boolean',
355 'class' => 'pvc-pro',
356 'disabled' => true,
357 'skip_saving' => true,
358 'value' => false,
359 'description' => '',
360 'label' => __( 'Enable to prevent bypassing the counts interval (for e.g. using incognito browser window or by clearing cookies).', 'post-views-counter' )
361 ],
362 'label' => [
363 'tab' => 'display',
364 'title' => __( 'Views Label', 'post-views-counter' ),
365 'section' => 'post_views_counter_display_settings',
366 'type' => 'input',
367 'description' => __( 'Enter the label for the post views counter field.', 'post-views-counter' ),
368 'subclass' => 'regular-text',
369 'validate' => [ $this, 'validate_label' ],
370 'reset' => [ $this, 'reset_label' ]
371 ],
372 'display_period' => [
373 'tab' => 'display',
374 'title' => __( 'Views Period', 'post-views-counter' ),
375 'section' => 'post_views_counter_display_settings',
376 'type' => 'select',
377 'class' => 'pvc-pro',
378 'disabled' => true,
379 'skip_saving' => true,
380 'description' => __( 'Select the time period to be included when displaying the number of views. The default display is the total number of views of the post.', 'post-views-counter' ),
381 'options' => [
382 'total' => __( 'Total Views', 'post-views-counter' )
383 ]
384 ],
385 'display_style' => [
386 'tab' => 'display',
387 'title' => __( 'Display Style', 'post-views-counter' ),
388 'section' => 'post_views_counter_display_settings',
389 'type' => 'custom',
390 'description' => __( 'Choose how to display the post views counter.', 'post-views-counter' ),
391 'callback' => [ $this, 'setting_display_style' ],
392 'validate' => [ $this, 'validate_display_style' ],
393 'options' => [
394 'icon' => __( 'icon', 'post-views-counter' ),
395 'text' => __( 'label', 'post-views-counter' )
396 ]
397 ],
398 'icon_class' => [
399 'tab' => 'display',
400 'title' => __( 'Icon Class', 'post-views-counter' ),
401 'section' => 'post_views_counter_display_settings',
402 'type' => 'class',
403 'default' => '',
404 'description' => sprintf( __( 'Enter the post views icon class. Any of the <a href="%s" target="_blank">Dashicons</a> classes are available.', 'post-views-counter' ), 'https://developer.wordpress.org/resource/dashicons/' ),
405 'subclass' => 'regular-text'
406 ],
407 'position' => [
408 'tab' => 'display',
409 'title' => __( 'Position', 'post-views-counter' ),
410 'section' => 'post_views_counter_display_settings',
411 'type' => 'select',
412 'description' => sprintf( __( 'Select where would you like to display the post views counter. Use %s shortcode for manual display.', 'post-views-counter' ), '<code>[post-views]</code>' ),
413 'options' => [
414 'before' => __( 'before the content', 'post-views-counter' ),
415 'after' => __( 'after the content', 'post-views-counter' ),
416 'manual' => __( 'manual', 'post-views-counter' )
417 ]
418 ],
419 'use_format' => [
420 'tab' => 'display',
421 'title' => __( 'Format Number', 'post-views-counter' ),
422 'section' => 'post_views_counter_display_settings',
423 'type' => 'boolean',
424
425 'value' => true,
426 'label' => __( 'Enable to display the views number formatted based on the locale (using the WP number_format_i18n function).', 'post-views-counter' )
427 ],
428 'taxonomies_display' => [
429 'tab' => 'display',
430 'title' => __( 'Taxonomies', 'post-views-counter' ),
431 'section' => 'post_views_counter_display_settings',
432 'type' => 'custom',
433 'class' => 'pvc-pro',
434 'skip_saving' => true,
435 'options' => $pvc->functions->get_taxonomies( 'labels' ),
436 'callback' => [ $this, 'setting_taxonomies_display' ]
437 ],
438 'user_display' => [
439 'tab' => 'display',
440 'title' => __( 'Authors', 'post-views-counter' ),
441 'section' => 'post_views_counter_display_settings',
442 'type' => 'boolean',
443 'class' => 'pvc-pro',
444 'disabled' => true,
445 'skip_saving' => true,
446 'value' => false,
447 'label' => __( 'Display number of views on authors archive pages.', 'post-views-counter' )
448 ],
449 'post_types_display' => [
450 'tab' => 'display',
451 'title' => __( 'Post Type', 'post-views-counter' ),
452 'section' => 'post_views_counter_display_settings',
453 'type' => 'checkbox',
454 'display_type' => 'horizontal',
455 'description' => __( 'Select post types for which the views count will be displayed.', 'post-views-counter' ),
456 'options' => $post_types
457 ],
458 'page_types_display' => [
459 'tab' => 'display',
460 'title' => __( 'Page Type', 'post-views-counter' ),
461 'section' => 'post_views_counter_display_settings',
462 'type' => 'checkbox',
463 'display_type' => 'horizontal',
464 'description' => __( 'Select page types where the views count will be displayed.', 'post-views-counter' ),
465 'options' => apply_filters(
466 'pvc_page_types_display_options',
467 [
468 'home' => __( 'Home', 'post-views-counter' ),
469 'archive' => __( 'Archives', 'post-views-counter' ),
470 'singular' => __( 'Single pages', 'post-views-counter' ),
471 'search' => __( 'Search results', 'post-views-counter' ),
472 ]
473 )
474 ],
475 'restrict_display' => [
476 'tab' => 'display',
477 'title' => __( 'User Type', 'post-views-counter' ),
478 'section' => 'post_views_counter_display_settings',
479 'type' => 'custom',
480 'description' => '',
481 'options' => [
482 'groups' => $groups,
483 'roles' => $user_roles
484 ],
485 'callback' => [ $this, 'setting_restrict_display' ],
486 'validate' => [ $this, 'validate_restrict_display' ]
487 ],
488 'toolbar_statistics' => [
489 'tab' => 'display',
490 'title' => __( 'Toolbar Chart', 'post-views-counter' ),
491 'section' => 'post_views_counter_display_settings',
492 'type' => 'boolean',
493 'description' => __( 'The post views chart will be displayed for the post types that are being counted.', 'post-views-counter' ),
494 'label' => __( 'Enable to display the post views chart at the toolbar.', 'post-views-counter' )
495 ],
496 'license' => [
497 'tab' => 'other',
498 'title' => __( 'License', 'post-views-counter' ),
499 'section' => 'post_views_counter_other_settings',
500 'disabled' => true,
501 'value' => $pvc->options['other']['license'],
502 'type' => 'input',
503 'description' => __( 'Enter your Post Views Counter Pro license key (requires Pro version to be installed and active).', 'post-views-counter' ),
504 'subclass' => 'regular-text',
505 'validate' => [ $this, 'validate_license' ],
506 'append' => '<span class="pvc-icon license-icon"></span>'
507 ],
508 'menu_position' => [
509 'tab' => 'other',
510 'title' => __( 'Menu Position', 'post-views-counter' ),
511 'section' => 'post_views_counter_other_settings',
512 'type' => 'radio',
513 'options' => [
514 'top' => __( 'Top menu', 'post-views-counter' ),
515 'sub' => __( 'Settings submenu', 'post-views-counter' )
516 ],
517 'description' => __( "Choose where to display the plugin's menu.", 'post-views-counter' ),
518 ],
519 'import_views' => [
520 'tab' => 'other',
521 'title' => __( 'Import Views', 'post-views-counter' ),
522 'section' => 'post_views_counter_other_settings',
523 'type' => 'custom',
524 'description' => '',
525 'skip_saving' => true,
526 'callback' => [ $this, 'setting_import_views' ]
527 ],
528 'delete_views' => [
529 'tab' => 'other',
530 'title' => __( 'Delete Views', 'post-views-counter' ),
531 'section' => 'post_views_counter_other_settings',
532 'type' => 'custom',
533 'description' => '',
534 'skip_saving' => true,
535 'callback' => [ $this, 'setting_delete_views' ]
536 ],
537 'deactivation_delete' => [
538 'tab' => 'other',
539 'title' => __( 'Deactivation', 'post-views-counter' ),
540 'section' => 'post_views_counter_other_settings',
541 'type' => 'boolean',
542 'description' => __( 'If you deactivate the plugin with this option enabled all plugin data will be deleted along with the number of post views.', 'post-views-counter' ),
543 'label' => __( 'Enable to delete all plugin data on deactivation.', 'post-views-counter' )
544 ]
545 ]
546 ];
547
548 return $settings;
549 }
550
551 /**
552 * Add settings page.
553 *
554 * @param array $pages
555 * @return array
556 */
557 public function settings_page( $pages ) {
558 // get main instance
559 $pvc = Post_Views_Counter();
560
561 // default page
562 $pages['post-views-counter'] = [
563 'menu_slug' => 'post-views-counter',
564 'page_title' => __( 'Post Views Counter Settings', 'post-views-counter' ),
565 'menu_title' => $pvc->options['other']['menu_position'] === 'sub' ? __( 'Post Views Counter', 'post-views-counter' ) : __( 'Post Views', 'post-views-counter' ),
566 'capability' => apply_filters( 'pvc_settings_capability', 'manage_options' ),
567 'callback' => null,
568 'tabs' => [
569 'general' => [
570 'label' => __( 'General', 'post-views-counter' ),
571 'option_name' => 'post_views_counter_settings_general'
572 ],
573 'display' => [
574 'label' => __( 'Display', 'post-views-counter' ),
575 'option_name' => 'post_views_counter_settings_display'
576 ],
577 'reports' => [
578 'label' => __( 'Reports', 'post-views-counter' ),
579 'option_name' => 'post_views_counter_settings_reports'
580 ],
581 'other' => [
582 'label' => __( 'Other', 'post-views-counter' ),
583 'option_name' => 'post_views_counter_settings_other'
584 ]
585 ]
586 ];
587
588 // submenu?
589 if ( $pvc->options['other']['menu_position'] === 'sub' ) {
590 $pages['post-views-counter']['type'] = 'settings_page';
591 // topmenu?
592 } else {
593 // highlight submenus
594 add_filter( 'submenu_file', [ $this, 'submenu_file' ], 10, 2 );
595
596 // add parameters
597 $pages['post-views-counter']['type'] = 'page';
598 $pages['post-views-counter']['icon'] = 'dashicons-chart-bar';
599 $pages['post-views-counter']['position'] = '99.301';
600
601 // add subpages
602 $pages['post-views-counter-general'] = [
603 'menu_slug' => 'post-views-counter',
604 'parent_slug' => 'post-views-counter',
605 'type' => 'subpage',
606 'page_title' => __( 'General', 'post-views-counter' ),
607 'menu_title' => __( 'General', 'post-views-counter' ),
608 'capability' => apply_filters( 'pvc_settings_capability', 'manage_options' ),
609 'callback' => null
610 ];
611
612 $pages['post-views-counter-display'] = [
613 'menu_slug' => 'post-views-counter&tab=display',
614 'parent_slug' => 'post-views-counter',
615 'type' => 'subpage',
616 'page_title' => __( 'Display', 'post-views-counter' ),
617 'menu_title' => __( 'Display', 'post-views-counter' ),
618 'capability' => apply_filters( 'pvc_settings_capability', 'manage_options' ),
619 'callback' => null
620 ];
621
622 $pages['post-views-counter-reports'] = [
623 'menu_slug' => 'post-views-counter&tab=reports',
624 'parent_slug' => 'post-views-counter',
625 'type' => 'subpage',
626 'page_title' => __( 'Reports', 'post-views-counter' ),
627 'menu_title' => __( 'Reports', 'post-views-counter' ),
628 'capability' => apply_filters( 'pvc_settings_capability', 'manage_options' ),
629 'callback' => null
630 ];
631
632 $pages['post-views-counter-other'] = [
633 'menu_slug' => 'post-views-counter&tab=other',
634 'parent_slug' => 'post-views-counter',
635 'type' => 'subpage',
636 'page_title' => __( 'Other', 'post-views-counter' ),
637 'menu_title' => __( 'Other', 'post-views-counter' ),
638 'capability' => apply_filters( 'pvc_settings_capability', 'manage_options' ),
639 'callback' => null
640 ];
641 }
642
643 return $pages;
644 }
645
646 /**
647 * Settings page CSS class(es).
648 *
649 * @param array $class
650 * @return array
651 */
652 public function settings_page_class( $class ) {
653 $is_pro = class_exists( 'Post_Views_Counter_Pro' );
654
655 if ( ! $is_pro )
656 $class[] = 'has-sidebar';
657
658 return $class;
659 }
660
661 /**
662 * Highlight submenu items.
663 *
664 * @param string|null $submenu_file
665 * @param string $parent_file
666 * @return string|null
667 */
668 public function submenu_file( $submenu_file, $parent_file ) {
669 if ( $parent_file === 'post-views-counter' ) {
670 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'general';
671
672 if ( $tab !== 'general' )
673 return 'post-views-counter&tab=' . $tab;
674 }
675
676 return $submenu_file;
677 }
678
679 /**
680 * Validate options.
681 *
682 * @global object $wpdb
683 *
684 * @param array $input
685 * @return array
686 */
687 public function validate_settings( $input ) {
688 // check capability
689 if ( ! current_user_can( 'manage_options' ) )
690 return $input;
691
692 global $wpdb;
693
694 // get main instance
695 $pvc = Post_Views_Counter();
696
697 // use internal settings api to validate settings first
698 $input = $pvc->settings_api->validate_settings( $input );
699
700 // update meta key on save changes
701 if ( isset( $_POST['post_views_counter_import_meta_key'] ) && isset( $_POST['save_post_views_counter_settings_other'] ) )
702 $input['import_meta_key'] = sanitize_key( $_POST['post_views_counter_import_meta_key'] );
703
704 // import post views data from another plugin
705 if ( isset( $_POST['post_views_counter_import_wp_postviews'] ) ) {
706 // make sure we do not change anything in the settings
707 $input = $pvc->options['other'];
708
709 // get views key
710 $meta_key = sanitize_key( apply_filters( 'pvc_import_meta_key', ( isset( $_POST['post_views_counter_import_meta_key'] ) ? $_POST['post_views_counter_import_meta_key'] : $pvc->options['other']['import_meta_key'] ) ) );
711
712 // set meta_key option
713 $input['import_meta_key'] = $meta_key;
714
715 // get views
716 $views = $wpdb->get_results( "SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = '" . $meta_key . "'", ARRAY_A, 0 );
717
718 // any views?
719 if ( ! empty( $views ) ) {
720 $sql = [];
721
722 foreach ( $views as $view ) {
723 $sql[] = "(" . (int) $view['post_id'] . ", 4, 'total', " . (int) $view['meta_value'] . ")";
724 }
725
726 $wpdb->query( "INSERT INTO " . $wpdb->prefix . "post_views(id, type, period, count) VALUES " . implode( ',', $sql ) . " ON DUPLICATE KEY UPDATE count = " . ( isset( $_POST['post_views_counter_import_wp_postviews_override'] ) ? '' : 'count + ' ) . "VALUES(count)" );
727
728 add_settings_error( 'wp_postviews_import', 'wp_postviews_import', __( 'Post views data imported successfully.', 'post-views-counter' ), 'updated' );
729 } else
730 add_settings_error( 'wp_postviews_import', 'wp_postviews_import', __( 'There was no post views data to import.', 'post-views-counter' ), 'updated' );
731 // delete all post views data
732 } elseif ( isset( $_POST['post_views_counter_reset_views'] ) ) {
733 // make sure we do not change anything in the settings
734 $input = $pvc->options['other'];
735
736 if ( $wpdb->query( 'TRUNCATE TABLE ' . $wpdb->prefix . 'post_views' ) )
737 add_settings_error( 'reset_post_views', 'reset_post_views', __( 'All existing data deleted successfully.', 'post-views-counter' ), 'updated' );
738 else
739 add_settings_error( 'reset_post_views', 'reset_post_views', __( 'Error occurred. All existing data were not deleted.', 'post-views-counter' ), 'error' );
740 // save general settings
741 } elseif ( isset( $_POST['save_post_views_counter_settings_general'] ) ) {
742 $input['update_version'] = $pvc->options['general']['update_version'];
743 $input['update_notice'] = $pvc->options['general']['update_notice'];
744 $input['update_delay_date'] = $pvc->options['general']['update_delay_date'];
745 // reset general settings
746 } elseif ( isset( $_POST['reset_post_views_counter_settings_general'] ) ) {
747 $input['update_version'] = $pvc->options['general']['update_version'];
748 $input['update_notice'] = $pvc->options['general']['update_notice'];
749 $input['update_delay_date'] = $pvc->options['general']['update_delay_date'];
750 }
751
752 return $input;
753 }
754
755 /**
756 * Setting: taxonomies count.
757 *
758 * @param array $field
759 * @return string
760 */
761 public function setting_taxonomies_count( $field ) {
762 $html = '
763 <label><input id="post_views_counter_general_taxonomies_count" type="checkbox" name="" value="" disabled />' . esc_html( $field['label'] ) . '</label>';
764
765 return $html;
766 }
767
768 /**
769 * Setting: users count.
770 *
771 * @param array $field
772 * @return string
773 */
774 public function setting_users_count( $field ) {
775 // get base instance
776 $pvc = Post_Views_Counter();
777
778 $html = '
779 <label><input id="post_views_counter_general_users_count" type="checkbox" name="" value="" disabled />' . esc_html( $field['label'] ) . '</label>';
780
781 return $html;
782 }
783
784 /**
785 * Setting: taxonomies count.
786 *
787 * @param array $field
788 * @return string
789 */
790 public function setting_taxonomies_display( $field ) {
791 // get base instance
792 $pvc = Post_Views_Counter();
793
794 $html = '';
795
796 foreach ( $field['options'] as $taxonomy => $label ) {
797 $html .= '
798 <label><input type="checkbox" name="" value="" disabled />' . esc_html( $label ) . '</label>';
799 }
800
801 $html .= '
802 <p class="description">' . esc_html__( 'Select taxonomies for which the views count will be displayed.', 'post-views-counter' ) . '</p>';
803
804 return $html;
805 }
806
807 /**
808 * Validate label.
809 *
810 * @param array $input
811 * @param array $field
812 * @return array
813 */
814 public function validate_label( $input, $field ) {
815 // get main instance
816 $pvc = Post_Views_Counter();
817
818 if ( ! isset( $input ) )
819 $input = $pvc->defaults['display']['label'];
820
821 // use internal settings API to validate settings first
822 $input = $pvc->settings_api->validate_field( $input, 'input', $field );
823
824 if ( function_exists( 'icl_register_string' ) )
825 icl_register_string( 'Post Views Counter', 'Post Views Label', $input );
826
827 return $input;
828 }
829
830 /**
831 * Restore post views label to default value.
832 *
833 * @param array $default
834 * @param array $field
835 * @return array
836 */
837 public function reset_label( $default, $field ) {
838 if ( function_exists( 'icl_register_string' ) )
839 icl_register_string( 'Post Views Counter', 'Post Views Label', $default );
840
841 return $default;
842 }
843
844 /**
845 * Setting: display style.
846 *
847 * @param array $field
848 * @return string
849 */
850 public function setting_display_style( $field ) {
851 // get main instance
852 $pvc = Post_Views_Counter();
853
854 $html = '
855 <input type="hidden" name="post_views_counter_settings_display[display_style]" value="empty" />';
856
857 foreach ( $field['options'] as $key => $label ) {
858 $html .= '
859 <label><input id="post_views_counter_display_display_style_' . esc_attr( $key ) . '" type="checkbox" name="post_views_counter_settings_display[display_style][]" value="' . esc_attr( $key ) . '" ' . checked( ! empty( $pvc->options['display']['display_style'][$key] ), true, false ) . ' />' . esc_html( $label ) . '</label> ';
860 }
861
862 return $html;
863 }
864
865 /**
866 * Validate display style.
867 *
868 * @param array $input
869 * @param array $field
870 * @return array
871 */
872 public function validate_display_style( $input, $field ) {
873 // get main instance
874 $pvc = Post_Views_Counter();
875
876 $data = [];
877
878 foreach ( $field['options'] as $value => $label ) {
879 $data[$value] = false;
880 }
881
882 // any data?
883 if ( ! empty( $input['display_style'] && $input['display_style'] !== 'empty' && is_array( $input['display_style'] ) ) ) {
884 foreach ( $input['display_style'] as $value ) {
885 if ( array_key_exists( $value, $field['options'] ) )
886 $data[$value] = true;
887 }
888 }
889
890 $input['display_style'] = $data;
891
892 return $input;
893 }
894
895 /**
896 * Setting: count interval.
897 *
898 * @param array $field
899 * @return string
900 */
901 public function setting_time_between_counts( $field ) {
902 // get main instance
903 $pvc = Post_Views_Counter();
904
905 $html = '
906 <input size="6" type="number" min="' . ( (int) $field['min'] ) . '" max="' . ( (int) $field['max'] ) . '" name="post_views_counter_settings_general[time_between_counts][number]" value="' . esc_attr( $pvc->options['general']['time_between_counts']['number'] ) . '" />
907 <select name="post_views_counter_settings_general[time_between_counts][type]">';
908
909 foreach ( $field['options'] as $type => $type_name ) {
910 $html .= '
911 <option value="' . esc_attr( $type ) . '" ' . selected( $type, $pvc->options['general']['time_between_counts']['type'], false ) . '>' . esc_html( $type_name ) . '</option>';
912 }
913
914 $html .= '
915 </select>
916 <p class="description">' . sprintf( __( 'Enter the time between single user visit count. Enter %s if you want to count every page view.', 'post-views-counter' ), '<code>0</code>' ) . '</p>';
917
918 return $html;
919 }
920
921 /**
922 * Validate count interval.
923 *
924 * @param array $input
925 * @param array $field
926 * @return array
927 */
928 public function validate_time_between_counts( $input, $field ) {
929 // get main instance
930 $pvc = Post_Views_Counter();
931
932 // number
933 $input['time_between_counts']['number'] = isset( $input['time_between_counts']['number'] ) ? (int) $input['time_between_counts']['number'] : $pvc->defaults['general']['time_between_counts']['number'];
934
935 if ( $input['time_between_counts']['number'] < $field['min'] || $input['time_between_counts']['number'] > $field['max'] )
936 $input['time_between_counts']['number'] = $pvc->defaults['general']['time_between_counts']['number'];
937
938 // type
939 $input['time_between_counts']['type'] = isset( $input['time_between_counts']['type'], $field['options'][$input['time_between_counts']['type']] ) ? $input['time_between_counts']['type'] : $pvc->defaults['general']['time_between_counts']['type'];
940
941 return $input;
942 }
943
944 /**
945 * Setting: reset data interval.
946 *
947 * @param array $field
948 * @return string
949 */
950 public function setting_reset_counts( $field ) {
951 // get main instance
952 $pvc = Post_Views_Counter();
953
954 $html = '
955 <input size="6" type="number" min="' . ( (int) $field['min'] ) . '" max="' . ( (int) $field['max'] ) . '" name="post_views_counter_settings_general[reset_counts][number]" value="' . esc_attr( $pvc->options['general']['reset_counts']['number'] ) . '" />
956 <select name="post_views_counter_settings_general[reset_counts][type]">';
957
958 foreach ( array_slice( $field['options'], 2, null, true ) as $type => $type_name ) {
959 $html .= '
960 <option value="' . esc_attr( $type ) . '" ' . selected( $type, $pvc->options['general']['reset_counts']['type'], false ) . '>' . esc_html( $type_name ) . '</option>';
961 }
962
963 $html .= '
964 </select>';
965
966 return $html;
967 }
968
969 /**
970 * Validate reset data interval.
971 *
972 * @param array $input
973 * @param array $field
974 * @return array
975 */
976 public function validate_reset_counts( $input, $field ) {
977 // get main instance
978 $pvc = Post_Views_Counter();
979
980 // number
981 $input['reset_counts']['number'] = isset( $input['reset_counts']['number'] ) ? (int) $input['reset_counts']['number'] : $pvc->defaults['general']['reset_counts']['number'];
982
983 if ( $input['reset_counts']['number'] < $field['min'] || $input['reset_counts']['number'] > $field['max'] )
984 $input['reset_counts']['number'] = $pvc->defaults['general']['reset_counts']['number'];
985
986 // type
987 $input['reset_counts']['type'] = isset( $input['reset_counts']['type'], $field['options'][$input['reset_counts']['type']] ) ? $input['reset_counts']['type'] : $pvc->defaults['general']['reset_counts']['type'];
988
989 // run cron on next visit?
990 $input['cron_run'] = ( $input['reset_counts']['number'] > 0 );
991
992 // cron update?
993 $input['cron_update'] = ( $input['cron_run'] && ( $pvc->options['general']['reset_counts']['number'] !== $input['reset_counts']['number'] || $pvc->options['general']['reset_counts']['type'] !== $input['reset_counts']['type'] ) );
994
995 return $input;
996 }
997
998 /**
999 * Setting: object cache.
1000 *
1001 * @param array $field
1002 * @return string
1003 */
1004 public function setting_object_cache( $field ) {
1005 // get main instance
1006 $pvc = Post_Views_Counter();
1007
1008 // check object cache
1009 $wp_using_ext_object_cache = wp_using_ext_object_cache();
1010
1011 $html = '
1012 <input size="4" type="number" min="' . ( (int) $field['min'] ) . '" max="' . ( (int) $field['max'] ) . '" name="" value="0" disabled /> <span>' . __( 'minutes', 'post-views-counter' ) . '</span>
1013 <p class="">' . __( 'Persistent Object Cache', 'post-views-counter' ) . ': <span class="' . ( $wp_using_ext_object_cache ? '' : 'un' ) . 'available">' . ( $wp_using_ext_object_cache ? __( 'available', 'post-views-counter' ) : __( 'unavailable', 'post-views-counter' ) ) . '</span></p>
1014 <p class="description">' . sprintf( __( 'How often to flush cached view counts from the object cache into the database. This feature is used only if a persistent object cache like %s or %s is detected and the interval is greater than %s. When used, view counts will be collected and stored in the object cache instead of the database and will then be asynchronously flushed to the database according to the specified interval. The maximum value is %s which means 24 hours.%sNotice:%s Potential data loss may occur if the object cache is cleared/unavailable for the duration of the interval.', 'post-views-counter' ), '<code>Redis</code>', '<code>Memcached</code>', '<code>0</code>', '<code>1440</code>', '<br /><strong> ', '</strong>' ) . '</p>';
1015
1016 return $html;
1017 }
1018
1019 /**
1020 * Setting: exclude visitors.
1021 *
1022 * @param array $field
1023 * @return string
1024 */
1025 public function setting_exclude( $field ) {
1026 // get main instance
1027 $pvc = Post_Views_Counter();
1028
1029 $html = '';
1030
1031 foreach ( $field['options']['groups'] as $type => $type_name ) {
1032 $html .= '
1033 <label><input id="' . esc_attr( 'pvc_exclude-' . $type ) . '" type="checkbox" name="post_views_counter_settings_general[exclude][groups][' . esc_attr( $type ) . ']" value="1" ' . checked( in_array( $type, $pvc->options['general']['exclude']['groups'], true ), true, false ) . ' />' . esc_html( $type_name ) . '</label>';
1034 }
1035
1036 $html .= '
1037 <p class="description">' . __( 'Use it exclude specific user groups from post views count.', 'post-views-counter' ) . '</p>
1038 <div class="pvc_user_roles pvc_subfield"' . ( in_array( 'roles', $pvc->options['general']['exclude']['groups'], true ) ? '' : ' style="display: none;"' ) . '>';
1039
1040 foreach ( $field['options']['roles'] as $role => $role_name ) {
1041 $html .= '
1042 <label><input type="checkbox" name="post_views_counter_settings_general[exclude][roles][' . $role . ']" value="1" ' . checked( in_array( $role, $pvc->options['general']['exclude']['roles'], true ), true, false ) . ' />' . esc_html( $role_name ) . '</label>';
1043 }
1044
1045 $html .= '
1046 <p class="description">' . __( 'Use it to exclude specific user roles from post views count.', 'post-views-counter' ) . '</p>
1047 </div>';
1048
1049 return $html;
1050 }
1051
1052 /**
1053 * Validate exclude visitors.
1054 *
1055 * @param array $input
1056 * @param array $field
1057 * @return array
1058 */
1059 public function validate_exclude( $input, $field ) {
1060 // any groups?
1061 if ( isset( $input['exclude']['groups'] ) ) {
1062 $groups = [];
1063
1064 foreach ( $input['exclude']['groups'] as $group => $set ) {
1065 if ( isset( $field['options']['groups'][$group] ) )
1066 $groups[] = $group;
1067 }
1068
1069 $input['exclude']['groups'] = array_unique( $groups );
1070 } else
1071 $input['exclude']['groups'] = [];
1072
1073 // any roles?
1074 if ( in_array( 'roles', $input['exclude']['groups'], true ) && isset( $input['exclude']['roles'] ) ) {
1075 $roles = [];
1076
1077 foreach ( $input['exclude']['roles'] as $role => $set ) {
1078 if ( isset( $field['options']['roles'][$role] ) )
1079 $roles[] = $role;
1080 }
1081
1082 $input['exclude']['roles'] = array_unique( $roles );
1083 } else
1084 $input['exclude']['roles'] = [];
1085
1086 return $input;
1087 }
1088
1089 /**
1090 * Setting: exclude IP addresses.
1091 *
1092 * @return string
1093 */
1094 public function setting_exclude_ips() {
1095 // get ip addresses
1096 $ips = Post_Views_Counter()->options['general']['exclude_ips'];
1097
1098 $html = '';
1099
1100 // any ip addresses?
1101 if ( ! empty( $ips ) ) {
1102 foreach ( $ips as $key => $ip ) {
1103 $html .= '
1104 <div class="ip-box">
1105 <input type="text" name="post_views_counter_settings_general[exclude_ips][]" value="' . esc_attr( $ip ) . '" /> <a href="#" class="remove-exclude-ip" title="' . esc_attr__( 'Remove', 'post-views-counter' ) . '">' . esc_html__( 'Remove', 'post-views-counter' ) . '</a>
1106 </div>';
1107 }
1108 } else {
1109 $html .= '
1110 <div class="ip-box">
1111 <input type="text" name="post_views_counter_settings_general[exclude_ips][]" value="" /> <a href="#" class="remove-exclude-ip" title="' . esc_attr__( 'Remove', 'post-views-counter' ) . '" style="display: none">' . esc_html__( 'Remove', 'post-views-counter' ) . '</a>
1112 </div>';
1113 }
1114
1115 $html .= '
1116 <p><input type="button" class="button button-secondary add-exclude-ip" value="' . esc_attr__( 'Add new', 'post-views-counter' ) . '" /> <input type="button" class="button button-secondary add-current-ip" value="' . esc_attr__( 'Add my current IP', 'post-views-counter' ) . '" data-rel="' . esc_attr( $_SERVER['REMOTE_ADDR'] ) . '" /></p>
1117 <p class="description">' . esc_html__( 'Enter the IP addresses to be excluded from post views count.', 'post-views-counter' ) . '</p>';
1118
1119 return $html;
1120 }
1121
1122 /**
1123 * Validate exclude IP addresses.
1124 *
1125 * @param array $input
1126 * @param array $field
1127 * @return array
1128 */
1129 public function validate_exclude_ips( $input, $field ) {
1130 // any ip addresses?
1131 if ( isset( $input['exclude_ips'] ) ) {
1132 $ips = [];
1133
1134 foreach ( $input['exclude_ips'] as $ip ) {
1135 if ( strpos( $ip, '*' ) !== false ) {
1136 $new_ip = str_replace( '*', '0', $ip );
1137
1138 if ( filter_var( $new_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) )
1139 $ips[] = $ip;
1140 } elseif ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) )
1141 $ips[] = $ip;
1142 }
1143
1144 $input['exclude_ips'] = array_unique( $ips );
1145 }
1146
1147 return $input;
1148 }
1149
1150 /**
1151 * Setting: tools.
1152 *
1153 * @return string
1154 */
1155 public function setting_import_views() {
1156 $html = '
1157 <div>
1158 <input type="text" class="regular-text" name="post_views_counter_import_meta_key" value="' . esc_attr( Post_Views_Counter()->options['other']['import_meta_key'] ) . '"/>
1159 <p class="description">' . esc_html__( 'Enter the meta key from which the views data is to be retrieved during import.', 'post-views-counter' ) . '</p>
1160 </div>
1161 <div class="pvc-subfield">
1162 <input type="submit" class="button button-secondary" name="post_views_counter_import_wp_postviews" value="' . esc_attr__( 'Import Views', 'post-views-counter' ) . '"/> <label><input id="pvc-wp-postviews" type="checkbox" name="post_views_counter_import_wp_postviews_override" value="1" />' . esc_html__( 'Override existing views data during import.', 'post-views-counter' ) . '</label>
1163 <p class="description">' . esc_html__( 'Click Import Views to start importing the views data.', 'post-views-counter' ) . '</p>
1164 </div>';
1165
1166 return $html;
1167 }
1168
1169 /**
1170 * Setting: delete views.
1171 *
1172 * @return string
1173 */
1174 public function setting_delete_views() {
1175 $html = '
1176 <input type="submit" class="button button-secondary" name="post_views_counter_reset_views" value="' . esc_attr__( 'Delete Views', 'post-views-counter' ) . '" />
1177 <p class="description">' . esc_html__( 'Delete ALL the existing post views data. Note that this is an irreversible process!', 'post-views-counter' ) . '</p>';
1178
1179 return $html;
1180 }
1181
1182 /**
1183 * Setting: user type.
1184 *
1185 * @param array $field
1186 * @return string
1187 */
1188 public function setting_restrict_display( $field ) {
1189 // get main instance
1190 $pvc = Post_Views_Counter();
1191
1192 $html = '';
1193
1194 foreach ( $field['options']['groups'] as $type => $type_name ) {
1195 if ( $type === 'robots' )
1196 continue;
1197
1198 $html .= '
1199 <label><input id="pvc_restrict_display-' . esc_attr( $type ) . '" type="checkbox" name="post_views_counter_settings_display[restrict_display][groups][' . esc_attr( $type ) . ']" value="1" ' . checked( in_array( $type, $pvc->options['display']['restrict_display']['groups'], true ), true, false ) . ' />' . esc_html( $type_name ) . '</label>';
1200 }
1201
1202 $html .= '
1203 <p class="description">' . __( 'Use it to hide the post views counter from selected type of visitors.', 'post-views-counter' ) . '</p>
1204 <div class="pvc_user_roles pvc-subfield"' . ( in_array( 'roles', $pvc->options['display']['restrict_display']['groups'], true ) ? '' : ' style="display: none;"' ) . '>';
1205
1206 foreach ( $field['options']['roles'] as $role => $role_name ) {
1207 $html .= '
1208 <label><input type="checkbox" name="post_views_counter_settings_display[restrict_display][roles][' . esc_attr( $role ) . ']" value="1" ' . checked( in_array( $role, $pvc->options['display']['restrict_display']['roles'], true ), true, false ) . ' />' . esc_html( $role_name ) . '</label>';
1209 }
1210
1211 $html .= '
1212 <p class="description">' . __( 'Use it to hide the post views counter from selected user roles.', 'post-views-counter' ) . '</p>
1213 </div>';
1214
1215 return $html;
1216 }
1217
1218 /**
1219 * Validate user type.
1220 *
1221 * @param array $input
1222 * @param array $field
1223 * @return array
1224 */
1225 public function validate_restrict_display( $input, $field ) {
1226 // any groups?
1227 if ( isset( $input['restrict_display']['groups'] ) ) {
1228 $groups = [];
1229
1230 foreach ( $input['restrict_display']['groups'] as $group => $set ) {
1231 if ( $group === 'robots' )
1232 continue;
1233
1234 if ( isset( $field['options']['groups'][$group] ) )
1235 $groups[] = $group;
1236 }
1237
1238 $input['restrict_display']['groups'] = array_unique( $groups );
1239 } else
1240 $input['restrict_display']['groups'] = [];
1241
1242 // any roles?
1243 if ( in_array( 'roles', $input['restrict_display']['groups'], true ) && isset( $input['restrict_display']['roles'] ) ) {
1244 $roles = [];
1245
1246 foreach ( $input['restrict_display']['roles'] as $role => $set ) {
1247 if ( isset( $field['options']['roles'][$role] ) )
1248 $roles[] = $role;
1249 }
1250
1251 $input['restrict_display']['roles'] = array_unique( $roles );
1252 } else
1253 $input['restrict_display']['roles'] = [];
1254
1255 return $input;
1256 }
1257
1258 /**
1259 * Reports page placeholder.
1260 */
1261 public function section_reports_placeholder() {
1262 echo '
1263 <form action="#">
1264 <div id="pvc-reports-placeholder">
1265 <img id="pvc-reports-bg" src="' . esc_url( POST_VIEWS_COUNTER_URL ) . '/css/page-reports.png" alt="Post Views Counter - Reports" />
1266 <div id="pvc-reports-upgrade">
1267 <div id="pvc-reports-modal">
1268 <h2>' . esc_html__( 'Display Reports and Export Views to CSV/XML', 'post-views-counter' ) . '</h2>
1269 <p>' . esc_html__( 'View detailed stats about the popularity of your content.', 'post-views-counter' ) . '</p>
1270 <p>' . esc_html__( 'Generate views reports in any date range you need.', 'post-views-counter' ) . '</p>
1271 <p>' . esc_html__( 'Export, download and share your website views data.', 'post-views-counter' ) . '</p>
1272 <p><a href="https://postviewscounter.com/upgrade/?utm_source=post-views-counter-lite&utm_medium=button&utm_campaign=upgrade-to-pro" class="button button-secondary button-hero pvc-button" target="_blank">' . esc_html__( 'Upgrade to Pro', 'post-views-counter' ) . '</a></p>
1273 </div>
1274 </div>
1275 </div>
1276 </form>';
1277 }
1278
1279 /**
1280 * Validate license.
1281 *
1282 * @param array $input
1283 * @param array $field
1284 * @return array
1285 */
1286 public function validate_license( $input, $field ) {
1287 // save value from database
1288 return $field['value'];
1289 }
1290 }
1291