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