PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.4.6
Post Views Counter v1.4.6
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
1289 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 (up to <code>10+</code> times faster!).', '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 'label' => __( 'Enable to display the views number formatted based on the locale (using the WP number_format_i18n function).', 'post-views-counter' )
425 ],
426 'taxonomies_display' => [
427 'tab' => 'display',
428 'title' => __( 'Taxonomies', 'post-views-counter' ),
429 'section' => 'post_views_counter_display_settings',
430 'type' => 'custom',
431 'class' => 'pvc-pro',
432 'skip_saving' => true,
433 'options' => $pvc->functions->get_taxonomies( 'labels' ),
434 'callback' => [ $this, 'setting_taxonomies_display' ]
435 ],
436 'user_display' => [
437 'tab' => 'display',
438 'title' => __( 'Authors', 'post-views-counter' ),
439 'section' => 'post_views_counter_display_settings',
440 'type' => 'boolean',
441 'class' => 'pvc-pro',
442 'disabled' => true,
443 'skip_saving' => true,
444 'value' => false,
445 'label' => __( 'Display number of views on authors archive pages.', 'post-views-counter' )
446 ],
447 'post_types_display' => [
448 'tab' => 'display',
449 'title' => __( 'Post Type', 'post-views-counter' ),
450 'section' => 'post_views_counter_display_settings',
451 'type' => 'checkbox',
452 'display_type' => 'horizontal',
453 'description' => __( 'Select post types for which the views count will be displayed.', 'post-views-counter' ),
454 'options' => $post_types
455 ],
456 'page_types_display' => [
457 'tab' => 'display',
458 'title' => __( 'Page Type', 'post-views-counter' ),
459 'section' => 'post_views_counter_display_settings',
460 'type' => 'checkbox',
461 'display_type' => 'horizontal',
462 'description' => __( 'Select page types where the views count will be displayed.', 'post-views-counter' ),
463 'options' => apply_filters(
464 'pvc_page_types_display_options',
465 [
466 'home' => __( 'Home', 'post-views-counter' ),
467 'archive' => __( 'Archives', 'post-views-counter' ),
468 'singular' => __( 'Single pages', 'post-views-counter' ),
469 'search' => __( 'Search results', 'post-views-counter' ),
470 ]
471 )
472 ],
473 'restrict_display' => [
474 'tab' => 'display',
475 'title' => __( 'User Type', 'post-views-counter' ),
476 'section' => 'post_views_counter_display_settings',
477 'type' => 'custom',
478 'description' => '',
479 'options' => [
480 'groups' => $groups,
481 'roles' => $user_roles
482 ],
483 'callback' => [ $this, 'setting_restrict_display' ],
484 'validate' => [ $this, 'validate_restrict_display' ]
485 ],
486 'toolbar_statistics' => [
487 'tab' => 'display',
488 'title' => __( 'Toolbar Chart', 'post-views-counter' ),
489 'section' => 'post_views_counter_display_settings',
490 'type' => 'boolean',
491 'description' => __( 'The post views chart will be displayed for the post types that are being counted.', 'post-views-counter' ),
492 'label' => __( 'Enable to display the post views chart at the toolbar.', 'post-views-counter' )
493 ],
494 'license' => [
495 'tab' => 'other',
496 'title' => __( 'License', 'post-views-counter' ),
497 'section' => 'post_views_counter_other_settings',
498 'disabled' => true,
499 'value' => $pvc->options['other']['license'],
500 'type' => 'input',
501 'description' => __( 'Enter your Post Views Counter Pro license key (requires Pro version to be installed and active).', 'post-views-counter' ),
502 'subclass' => 'regular-text',
503 'validate' => [ $this, 'validate_license' ],
504 'append' => '<span class="pvc-icon license-icon"></span>'
505 ],
506 'menu_position' => [
507 'tab' => 'other',
508 'title' => __( 'Menu Position', 'post-views-counter' ),
509 'section' => 'post_views_counter_other_settings',
510 'type' => 'radio',
511 'options' => [
512 'top' => __( 'Top menu', 'post-views-counter' ),
513 'sub' => __( 'Settings submenu', 'post-views-counter' )
514 ],
515 'description' => __( "Choose where to display the plugin's menu.", 'post-views-counter' ),
516 ],
517 'import_views' => [
518 'tab' => 'other',
519 'title' => __( 'Import Views', 'post-views-counter' ),
520 'section' => 'post_views_counter_other_settings',
521 'type' => 'custom',
522 'description' => '',
523 'skip_saving' => true,
524 'callback' => [ $this, 'setting_import_views' ]
525 ],
526 'delete_views' => [
527 'tab' => 'other',
528 'title' => __( 'Delete Views', 'post-views-counter' ),
529 'section' => 'post_views_counter_other_settings',
530 'type' => 'custom',
531 'description' => '',
532 'skip_saving' => true,
533 'callback' => [ $this, 'setting_delete_views' ]
534 ],
535 'deactivation_delete' => [
536 'tab' => 'other',
537 'title' => __( 'Deactivation', 'post-views-counter' ),
538 'section' => 'post_views_counter_other_settings',
539 'type' => 'boolean',
540 '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' ),
541 'label' => __( 'Enable to delete all plugin data on deactivation.', 'post-views-counter' )
542 ]
543 ]
544 ];
545
546 return $settings;
547 }
548
549 /**
550 * Add settings page.
551 *
552 * @param array $pages
553 * @return array
554 */
555 public function settings_page( $pages ) {
556 // get main instance
557 $pvc = Post_Views_Counter();
558
559 // default page
560 $pages['post-views-counter'] = [
561 'menu_slug' => 'post-views-counter',
562 'page_title' => __( 'Post Views Counter Settings', 'post-views-counter' ),
563 'menu_title' => $pvc->options['other']['menu_position'] === 'sub' ? __( 'Post Views Counter', 'post-views-counter' ) : __( 'Post Views', 'post-views-counter' ),
564 'capability' => apply_filters( 'pvc_settings_capability', 'manage_options' ),
565 'callback' => null,
566 'tabs' => [
567 'general' => [
568 'label' => __( 'General', 'post-views-counter' ),
569 'option_name' => 'post_views_counter_settings_general'
570 ],
571 'display' => [
572 'label' => __( 'Display', 'post-views-counter' ),
573 'option_name' => 'post_views_counter_settings_display'
574 ],
575 'reports' => [
576 'label' => __( 'Reports', 'post-views-counter' ),
577 'option_name' => 'post_views_counter_settings_reports'
578 ],
579 'other' => [
580 'label' => __( 'Other', 'post-views-counter' ),
581 'option_name' => 'post_views_counter_settings_other'
582 ]
583 ]
584 ];
585
586 // submenu?
587 if ( $pvc->options['other']['menu_position'] === 'sub' ) {
588 $pages['post-views-counter']['type'] = 'settings_page';
589 // topmenu?
590 } else {
591 // highlight submenus
592 add_filter( 'submenu_file', [ $this, 'submenu_file' ], 10, 2 );
593
594 // add parameters
595 $pages['post-views-counter']['type'] = 'page';
596 $pages['post-views-counter']['icon'] = 'dashicons-chart-bar';
597 $pages['post-views-counter']['position'] = '99.301';
598
599 // add subpages
600 $pages['post-views-counter-general'] = [
601 'menu_slug' => 'post-views-counter',
602 'parent_slug' => 'post-views-counter',
603 'type' => 'subpage',
604 'page_title' => __( 'General', 'post-views-counter' ),
605 'menu_title' => __( 'General', 'post-views-counter' ),
606 'capability' => apply_filters( 'pvc_settings_capability', 'manage_options' ),
607 'callback' => null
608 ];
609
610 $pages['post-views-counter-display'] = [
611 'menu_slug' => 'post-views-counter&tab=display',
612 'parent_slug' => 'post-views-counter',
613 'type' => 'subpage',
614 'page_title' => __( 'Display', 'post-views-counter' ),
615 'menu_title' => __( 'Display', 'post-views-counter' ),
616 'capability' => apply_filters( 'pvc_settings_capability', 'manage_options' ),
617 'callback' => null
618 ];
619
620 $pages['post-views-counter-reports'] = [
621 'menu_slug' => 'post-views-counter&tab=reports',
622 'parent_slug' => 'post-views-counter',
623 'type' => 'subpage',
624 'page_title' => __( 'Reports', 'post-views-counter' ),
625 'menu_title' => __( 'Reports', 'post-views-counter' ),
626 'capability' => apply_filters( 'pvc_settings_capability', 'manage_options' ),
627 'callback' => null
628 ];
629
630 $pages['post-views-counter-other'] = [
631 'menu_slug' => 'post-views-counter&tab=other',
632 'parent_slug' => 'post-views-counter',
633 'type' => 'subpage',
634 'page_title' => __( 'Other', 'post-views-counter' ),
635 'menu_title' => __( 'Other', 'post-views-counter' ),
636 'capability' => apply_filters( 'pvc_settings_capability', 'manage_options' ),
637 'callback' => null
638 ];
639 }
640
641 return $pages;
642 }
643
644 /**
645 * Settings page CSS class(es).
646 *
647 * @param array $class
648 * @return array
649 */
650 public function settings_page_class( $class ) {
651 $is_pro = class_exists( 'Post_Views_Counter_Pro' );
652
653 if ( ! $is_pro )
654 $class[] = 'has-sidebar';
655
656 return $class;
657 }
658
659 /**
660 * Highlight submenu items.
661 *
662 * @param string|null $submenu_file
663 * @param string $parent_file
664 * @return string|null
665 */
666 public function submenu_file( $submenu_file, $parent_file ) {
667 if ( $parent_file === 'post-views-counter' ) {
668 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'general';
669
670 if ( $tab !== 'general' )
671 return 'post-views-counter&tab=' . $tab;
672 }
673
674 return $submenu_file;
675 }
676
677 /**
678 * Validate options.
679 *
680 * @global object $wpdb
681 *
682 * @param array $input
683 * @return array
684 */
685 public function validate_settings( $input ) {
686 // check capability
687 if ( ! current_user_can( 'manage_options' ) )
688 return $input;
689
690 global $wpdb;
691
692 // get main instance
693 $pvc = Post_Views_Counter();
694
695 // use internal settings api to validate settings first
696 $input = $pvc->settings_api->validate_settings( $input );
697
698 // update meta key on save changes
699 if ( isset( $_POST['post_views_counter_import_meta_key'] ) && isset( $_POST['save_post_views_counter_settings_other'] ) )
700 $input['import_meta_key'] = sanitize_key( $_POST['post_views_counter_import_meta_key'] );
701
702 // import post views data from another plugin
703 if ( isset( $_POST['post_views_counter_import_wp_postviews'] ) ) {
704 // make sure we do not change anything in the settings
705 $input = $pvc->options['other'];
706
707 // get views key
708 $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'] ) ) );
709
710 // set meta_key option
711 $input['import_meta_key'] = $meta_key;
712
713 // get views
714 $views = $wpdb->get_results( $wpdb->prepare( "SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s", $meta_key ), ARRAY_A, 0 );
715
716 // any views?
717 if ( ! empty( $views ) ) {
718 $sql = [];
719
720 foreach ( $views as $view ) {
721 $sql[] = $wpdb->prepare( "(%d, 4, 'total', %d)", (int) $view['post_id'], (int) $view['meta_value'] );
722 }
723
724 $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)" );
725
726 add_settings_error( 'wp_postviews_import', 'wp_postviews_import', __( 'Post views data imported successfully.', 'post-views-counter' ), 'updated' );
727 } else
728 add_settings_error( 'wp_postviews_import', 'wp_postviews_import', __( 'There was no post views data to import.', 'post-views-counter' ), 'updated' );
729 // delete all post views data
730 } elseif ( isset( $_POST['post_views_counter_reset_views'] ) ) {
731 // make sure we do not change anything in the settings
732 $input = $pvc->options['other'];
733
734 if ( $wpdb->query( 'TRUNCATE TABLE ' . $wpdb->prefix . 'post_views' ) )
735 add_settings_error( 'reset_post_views', 'reset_post_views', __( 'All existing data deleted successfully.', 'post-views-counter' ), 'updated' );
736 else
737 add_settings_error( 'reset_post_views', 'reset_post_views', __( 'Error occurred. All existing data were not deleted.', 'post-views-counter' ), 'error' );
738 // save general settings
739 } elseif ( isset( $_POST['save_post_views_counter_settings_general'] ) ) {
740 $input['update_version'] = $pvc->options['general']['update_version'];
741 $input['update_notice'] = $pvc->options['general']['update_notice'];
742 $input['update_delay_date'] = $pvc->options['general']['update_delay_date'];
743 // reset general settings
744 } elseif ( isset( $_POST['reset_post_views_counter_settings_general'] ) ) {
745 $input['update_version'] = $pvc->options['general']['update_version'];
746 $input['update_notice'] = $pvc->options['general']['update_notice'];
747 $input['update_delay_date'] = $pvc->options['general']['update_delay_date'];
748 }
749
750 return $input;
751 }
752
753 /**
754 * Setting: taxonomies count.
755 *
756 * @param array $field
757 * @return string
758 */
759 public function setting_taxonomies_count( $field ) {
760 $html = '
761 <label><input id="post_views_counter_general_taxonomies_count" type="checkbox" name="" value="" disabled />' . esc_html( $field['label'] ) . '</label>';
762
763 return $html;
764 }
765
766 /**
767 * Setting: users count.
768 *
769 * @param array $field
770 * @return string
771 */
772 public function setting_users_count( $field ) {
773 // get base instance
774 $pvc = Post_Views_Counter();
775
776 $html = '
777 <label><input id="post_views_counter_general_users_count" type="checkbox" name="" value="" disabled />' . esc_html( $field['label'] ) . '</label>';
778
779 return $html;
780 }
781
782 /**
783 * Setting: taxonomies count.
784 *
785 * @param array $field
786 * @return string
787 */
788 public function setting_taxonomies_display( $field ) {
789 // get base instance
790 $pvc = Post_Views_Counter();
791
792 $html = '';
793
794 foreach ( $field['options'] as $taxonomy => $label ) {
795 $html .= '
796 <label><input type="checkbox" name="" value="" disabled />' . esc_html( $label ) . '</label>';
797 }
798
799 $html .= '
800 <p class="description">' . esc_html__( 'Select taxonomies for which the views count will be displayed.', 'post-views-counter' ) . '</p>';
801
802 return $html;
803 }
804
805 /**
806 * Validate label.
807 *
808 * @param array $input
809 * @param array $field
810 * @return array
811 */
812 public function validate_label( $input, $field ) {
813 // get main instance
814 $pvc = Post_Views_Counter();
815
816 if ( ! isset( $input ) )
817 $input = $pvc->defaults['display']['label'];
818
819 // use internal settings API to validate settings first
820 $input = $pvc->settings_api->validate_field( $input, 'input', $field );
821
822 if ( function_exists( 'icl_register_string' ) )
823 icl_register_string( 'Post Views Counter', 'Post Views Label', $input );
824
825 return $input;
826 }
827
828 /**
829 * Restore post views label to default value.
830 *
831 * @param array $default
832 * @param array $field
833 * @return array
834 */
835 public function reset_label( $default, $field ) {
836 if ( function_exists( 'icl_register_string' ) )
837 icl_register_string( 'Post Views Counter', 'Post Views Label', $default );
838
839 return $default;
840 }
841
842 /**
843 * Setting: display style.
844 *
845 * @param array $field
846 * @return string
847 */
848 public function setting_display_style( $field ) {
849 // get main instance
850 $pvc = Post_Views_Counter();
851
852 $html = '
853 <input type="hidden" name="post_views_counter_settings_display[display_style]" value="empty" />';
854
855 foreach ( $field['options'] as $key => $label ) {
856 $html .= '
857 <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> ';
858 }
859
860 return $html;
861 }
862
863 /**
864 * Validate display style.
865 *
866 * @param array $input
867 * @param array $field
868 * @return array
869 */
870 public function validate_display_style( $input, $field ) {
871 // get main instance
872 $pvc = Post_Views_Counter();
873
874 $data = [];
875
876 foreach ( $field['options'] as $value => $label ) {
877 $data[$value] = false;
878 }
879
880 // any data?
881 if ( ! empty( $input['display_style'] && $input['display_style'] !== 'empty' && is_array( $input['display_style'] ) ) ) {
882 foreach ( $input['display_style'] as $value ) {
883 if ( array_key_exists( $value, $field['options'] ) )
884 $data[$value] = true;
885 }
886 }
887
888 $input['display_style'] = $data;
889
890 return $input;
891 }
892
893 /**
894 * Setting: count interval.
895 *
896 * @param array $field
897 * @return string
898 */
899 public function setting_time_between_counts( $field ) {
900 // get main instance
901 $pvc = Post_Views_Counter();
902
903 $html = '
904 <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'] ) . '" />
905 <select name="post_views_counter_settings_general[time_between_counts][type]">';
906
907 foreach ( $field['options'] as $type => $type_name ) {
908 $html .= '
909 <option value="' . esc_attr( $type ) . '" ' . selected( $type, $pvc->options['general']['time_between_counts']['type'], false ) . '>' . esc_html( $type_name ) . '</option>';
910 }
911
912 $html .= '
913 </select>
914 <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>';
915
916 return $html;
917 }
918
919 /**
920 * Validate count interval.
921 *
922 * @param array $input
923 * @param array $field
924 * @return array
925 */
926 public function validate_time_between_counts( $input, $field ) {
927 // get main instance
928 $pvc = Post_Views_Counter();
929
930 // number
931 $input['time_between_counts']['number'] = isset( $input['time_between_counts']['number'] ) ? (int) $input['time_between_counts']['number'] : $pvc->defaults['general']['time_between_counts']['number'];
932
933 if ( $input['time_between_counts']['number'] < $field['min'] || $input['time_between_counts']['number'] > $field['max'] )
934 $input['time_between_counts']['number'] = $pvc->defaults['general']['time_between_counts']['number'];
935
936 // type
937 $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'];
938
939 return $input;
940 }
941
942 /**
943 * Setting: reset data interval.
944 *
945 * @param array $field
946 * @return string
947 */
948 public function setting_reset_counts( $field ) {
949 // get main instance
950 $pvc = Post_Views_Counter();
951
952 $html = '
953 <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'] ) . '" />
954 <select name="post_views_counter_settings_general[reset_counts][type]">';
955
956 foreach ( array_slice( $field['options'], 2, null, true ) as $type => $type_name ) {
957 $html .= '
958 <option value="' . esc_attr( $type ) . '" ' . selected( $type, $pvc->options['general']['reset_counts']['type'], false ) . '>' . esc_html( $type_name ) . '</option>';
959 }
960
961 $html .= '
962 </select>';
963
964 return $html;
965 }
966
967 /**
968 * Validate reset data interval.
969 *
970 * @param array $input
971 * @param array $field
972 * @return array
973 */
974 public function validate_reset_counts( $input, $field ) {
975 // get main instance
976 $pvc = Post_Views_Counter();
977
978 // number
979 $input['reset_counts']['number'] = isset( $input['reset_counts']['number'] ) ? (int) $input['reset_counts']['number'] : $pvc->defaults['general']['reset_counts']['number'];
980
981 if ( $input['reset_counts']['number'] < $field['min'] || $input['reset_counts']['number'] > $field['max'] )
982 $input['reset_counts']['number'] = $pvc->defaults['general']['reset_counts']['number'];
983
984 // type
985 $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'];
986
987 // run cron on next visit?
988 $input['cron_run'] = ( $input['reset_counts']['number'] > 0 );
989
990 // cron update?
991 $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'] ) );
992
993 return $input;
994 }
995
996 /**
997 * Setting: object cache.
998 *
999 * @param array $field
1000 * @return string
1001 */
1002 public function setting_object_cache( $field ) {
1003 // get main instance
1004 $pvc = Post_Views_Counter();
1005
1006 // check object cache
1007 $wp_using_ext_object_cache = wp_using_ext_object_cache();
1008
1009 $html = '
1010 <input size="4" type="number" min="' . ( (int) $field['min'] ) . '" max="' . ( (int) $field['max'] ) . '" name="" value="0" disabled /> <span>' . __( 'minutes', 'post-views-counter' ) . '</span>
1011 <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>
1012 <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>';
1013
1014 return $html;
1015 }
1016
1017 /**
1018 * Setting: exclude visitors.
1019 *
1020 * @param array $field
1021 * @return string
1022 */
1023 public function setting_exclude( $field ) {
1024 // get main instance
1025 $pvc = Post_Views_Counter();
1026
1027 $html = '';
1028
1029 foreach ( $field['options']['groups'] as $type => $type_name ) {
1030 $html .= '
1031 <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>';
1032 }
1033
1034 $html .= '
1035 <p class="description">' . __( 'Use it exclude specific user groups from post views count.', 'post-views-counter' ) . '</p>
1036 <div class="pvc_user_roles pvc_subfield"' . ( in_array( 'roles', $pvc->options['general']['exclude']['groups'], true ) ? '' : ' style="display: none;"' ) . '>';
1037
1038 foreach ( $field['options']['roles'] as $role => $role_name ) {
1039 $html .= '
1040 <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>';
1041 }
1042
1043 $html .= '
1044 <p class="description">' . __( 'Use it to exclude specific user roles from post views count.', 'post-views-counter' ) . '</p>
1045 </div>';
1046
1047 return $html;
1048 }
1049
1050 /**
1051 * Validate exclude visitors.
1052 *
1053 * @param array $input
1054 * @param array $field
1055 * @return array
1056 */
1057 public function validate_exclude( $input, $field ) {
1058 // any groups?
1059 if ( isset( $input['exclude']['groups'] ) ) {
1060 $groups = [];
1061
1062 foreach ( $input['exclude']['groups'] as $group => $set ) {
1063 if ( isset( $field['options']['groups'][$group] ) )
1064 $groups[] = $group;
1065 }
1066
1067 $input['exclude']['groups'] = array_unique( $groups );
1068 } else
1069 $input['exclude']['groups'] = [];
1070
1071 // any roles?
1072 if ( in_array( 'roles', $input['exclude']['groups'], true ) && isset( $input['exclude']['roles'] ) ) {
1073 $roles = [];
1074
1075 foreach ( $input['exclude']['roles'] as $role => $set ) {
1076 if ( isset( $field['options']['roles'][$role] ) )
1077 $roles[] = $role;
1078 }
1079
1080 $input['exclude']['roles'] = array_unique( $roles );
1081 } else
1082 $input['exclude']['roles'] = [];
1083
1084 return $input;
1085 }
1086
1087 /**
1088 * Setting: exclude IP addresses.
1089 *
1090 * @return string
1091 */
1092 public function setting_exclude_ips() {
1093 // get ip addresses
1094 $ips = Post_Views_Counter()->options['general']['exclude_ips'];
1095
1096 $html = '';
1097
1098 // any ip addresses?
1099 if ( ! empty( $ips ) ) {
1100 foreach ( $ips as $key => $ip ) {
1101 $html .= '
1102 <div class="ip-box">
1103 <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>
1104 </div>';
1105 }
1106 } else {
1107 $html .= '
1108 <div class="ip-box">
1109 <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>
1110 </div>';
1111 }
1112
1113 $html .= '
1114 <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>
1115 <p class="description">' . esc_html__( 'Enter the IP addresses to be excluded from post views count.', 'post-views-counter' ) . '</p>';
1116
1117 return $html;
1118 }
1119
1120 /**
1121 * Validate exclude IP addresses.
1122 *
1123 * @param array $input
1124 * @param array $field
1125 * @return array
1126 */
1127 public function validate_exclude_ips( $input, $field ) {
1128 // any ip addresses?
1129 if ( isset( $input['exclude_ips'] ) ) {
1130 $ips = [];
1131
1132 foreach ( $input['exclude_ips'] as $ip ) {
1133 if ( strpos( $ip, '*' ) !== false ) {
1134 $new_ip = str_replace( '*', '0', $ip );
1135
1136 if ( filter_var( $new_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) )
1137 $ips[] = $ip;
1138 } elseif ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) )
1139 $ips[] = $ip;
1140 }
1141
1142 $input['exclude_ips'] = array_unique( $ips );
1143 }
1144
1145 return $input;
1146 }
1147
1148 /**
1149 * Setting: tools.
1150 *
1151 * @return string
1152 */
1153 public function setting_import_views() {
1154 $html = '
1155 <div>
1156 <input type="text" class="regular-text" name="post_views_counter_import_meta_key" value="' . esc_attr( Post_Views_Counter()->options['other']['import_meta_key'] ) . '"/>
1157 <p class="description">' . esc_html__( 'Enter the meta key from which the views data is to be retrieved during import.', 'post-views-counter' ) . '</p>
1158 </div>
1159 <div class="pvc-subfield">
1160 <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>
1161 <p class="description">' . esc_html__( 'Click Import Views to start importing the views data.', 'post-views-counter' ) . '</p>
1162 </div>';
1163
1164 return $html;
1165 }
1166
1167 /**
1168 * Setting: delete views.
1169 *
1170 * @return string
1171 */
1172 public function setting_delete_views() {
1173 $html = '
1174 <input type="submit" class="button button-secondary" name="post_views_counter_reset_views" value="' . esc_attr__( 'Delete Views', 'post-views-counter' ) . '" />
1175 <p class="description">' . esc_html__( 'Delete ALL the existing post views data. Note that this is an irreversible process!', 'post-views-counter' ) . '</p>';
1176
1177 return $html;
1178 }
1179
1180 /**
1181 * Setting: user type.
1182 *
1183 * @param array $field
1184 * @return string
1185 */
1186 public function setting_restrict_display( $field ) {
1187 // get main instance
1188 $pvc = Post_Views_Counter();
1189
1190 $html = '';
1191
1192 foreach ( $field['options']['groups'] as $type => $type_name ) {
1193 if ( $type === 'robots' )
1194 continue;
1195
1196 $html .= '
1197 <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>';
1198 }
1199
1200 $html .= '
1201 <p class="description">' . __( 'Use it to hide the post views counter from selected type of visitors.', 'post-views-counter' ) . '</p>
1202 <div class="pvc_user_roles pvc-subfield"' . ( in_array( 'roles', $pvc->options['display']['restrict_display']['groups'], true ) ? '' : ' style="display: none;"' ) . '>';
1203
1204 foreach ( $field['options']['roles'] as $role => $role_name ) {
1205 $html .= '
1206 <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>';
1207 }
1208
1209 $html .= '
1210 <p class="description">' . __( 'Use it to hide the post views counter from selected user roles.', 'post-views-counter' ) . '</p>
1211 </div>';
1212
1213 return $html;
1214 }
1215
1216 /**
1217 * Validate user type.
1218 *
1219 * @param array $input
1220 * @param array $field
1221 * @return array
1222 */
1223 public function validate_restrict_display( $input, $field ) {
1224 // any groups?
1225 if ( isset( $input['restrict_display']['groups'] ) ) {
1226 $groups = [];
1227
1228 foreach ( $input['restrict_display']['groups'] as $group => $set ) {
1229 if ( $group === 'robots' )
1230 continue;
1231
1232 if ( isset( $field['options']['groups'][$group] ) )
1233 $groups[] = $group;
1234 }
1235
1236 $input['restrict_display']['groups'] = array_unique( $groups );
1237 } else
1238 $input['restrict_display']['groups'] = [];
1239
1240 // any roles?
1241 if ( in_array( 'roles', $input['restrict_display']['groups'], true ) && isset( $input['restrict_display']['roles'] ) ) {
1242 $roles = [];
1243
1244 foreach ( $input['restrict_display']['roles'] as $role => $set ) {
1245 if ( isset( $field['options']['roles'][$role] ) )
1246 $roles[] = $role;
1247 }
1248
1249 $input['restrict_display']['roles'] = array_unique( $roles );
1250 } else
1251 $input['restrict_display']['roles'] = [];
1252
1253 return $input;
1254 }
1255
1256 /**
1257 * Reports page placeholder.
1258 */
1259 public function section_reports_placeholder() {
1260 echo '
1261 <form action="#">
1262 <div id="pvc-reports-placeholder">
1263 <img id="pvc-reports-bg" src="' . esc_url( POST_VIEWS_COUNTER_URL ) . '/css/page-reports.png" alt="Post Views Counter - Reports" />
1264 <div id="pvc-reports-upgrade">
1265 <div id="pvc-reports-modal">
1266 <h2>' . esc_html__( 'Display Reports and Export Views to CSV/XML', 'post-views-counter' ) . '</h2>
1267 <p>' . esc_html__( 'View detailed stats about the popularity of your content.', 'post-views-counter' ) . '</p>
1268 <p>' . esc_html__( 'Generate views reports in any date range you need.', 'post-views-counter' ) . '</p>
1269 <p>' . esc_html__( 'Export, download and share your website views data.', 'post-views-counter' ) . '</p>
1270 <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>
1271 </div>
1272 </div>
1273 </div>
1274 </form>';
1275 }
1276
1277 /**
1278 * Validate license.
1279 *
1280 * @param array $input
1281 * @param array $field
1282 * @return array
1283 */
1284 public function validate_license( $input, $field ) {
1285 // save value from database
1286 return $field['value'];
1287 }
1288 }
1289