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