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