PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.4
Post Views Counter v1.4
1.7.13 1.7.12 1.7.11 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.2 1.3.2.1 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.7.10 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9
post-views-counter / includes / class-settings.php
post-views-counter / includes Last commit date
class-admin.php 2 years ago class-columns.php 2 years ago class-counter.php 2 years ago class-crawler-detect.php 2 years ago class-cron.php 2 years ago class-dashboard.php 2 years ago class-frontend.php 2 years ago class-functions.php 2 years ago class-query.php 2 years ago class-settings-api.php 2 years ago class-settings.php 2 years ago class-update.php 2 years ago class-widgets.php 2 years ago functions.php 2 years ago
class-settings.php
1217 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 cn-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 'callback' => null,
192 'tab' => 'reports'
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 content 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 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 'menu_title' => __( 'Post Views Counter', 'post-views-counter' ),
535 'capability' => apply_filters( 'pvc_settings_capability', 'manage_options' ),
536 'callback' => null,
537 'tabs' => [
538 'general' => [
539 'label' => __( 'General', 'post-views-counter' ),
540 'option_name' => 'post_views_counter_settings_general'
541 ],
542 'display' => [
543 'label' => __( 'Display', 'post-views-counter' ),
544 'option_name' => 'post_views_counter_settings_display'
545 ],
546 'reports' => [
547 'label' => __( 'Reports', 'post-views-counter' ),
548 'option_name' => 'post_views_counter_settings_reports',
549 'disabled' => true,
550 'class' => 'pvc-pro'
551 ],
552 'other' => [
553 'label' => __( 'Other', 'post-views-counter' ),
554 'option_name' => 'post_views_counter_settings_other'
555 ]
556 ]
557 ];
558
559 // submenu?
560 // if ( $pvc->options['other']['menu_position'] === 'sub' ) {
561 $pages['post-views-counter']['type'] = 'settings_page';
562 // topmenu?
563 /* } else {
564 // highlight submenus
565 add_filter( 'submenu_file', [ $this, 'submenu_file' ], 10, 2 );
566
567 // add parameters
568 $pages['post-views-counter']['type'] = 'page';
569 $pages['post-views-counter']['icon'] = 'dashicons-chart-bar';
570 $pages['post-views-counter']['position'] = '99.301';
571
572 // add subpages
573 $pages['post-views-counter-general'] = [
574 'menu_slug' => 'post-views-counter',
575 'parent_slug' => 'post-views-counter',
576 'type' => 'subpage',
577 'page_title' => __( 'General', 'post-views-counter' ),
578 'menu_title' => __( 'General', 'post-views-counter' ),
579 'capability' => apply_filters( 'pvc_settings_capability', 'manage_options' ),
580 'callback' => null
581 ];
582
583 $pages['post-views-counter-display'] = [
584 'menu_slug' => 'post-views-counter&tab=display',
585 'parent_slug' => 'post-views-counter',
586 'type' => 'subpage',
587 'page_title' => __( 'Display', 'post-views-counter' ),
588 'menu_title' => __( 'Display', 'post-views-counter' ),
589 'capability' => apply_filters( 'pvc_settings_capability', 'manage_options' ),
590 'callback' => null
591 ];
592
593 $pages['post-views-counter-reports'] = [
594 'menu_slug' => 'post-views-counter&tab=reports',
595 'parent_slug' => 'post-views-counter',
596 'type' => 'subpage',
597 'page_title' => __( 'Reports', 'post-views-counter' ),
598 'menu_title' => __( 'Reports', 'post-views-counter' ),
599 'capability' => apply_filters( 'pvc_settings_capability', 'manage_options' ),
600 'callback' => null
601 ];
602
603 $pages['post-views-counter-other'] = [
604 'menu_slug' => 'post-views-counter&tab=other',
605 'parent_slug' => 'post-views-counter',
606 'type' => 'subpage',
607 'page_title' => __( 'Other', 'post-views-counter' ),
608 'menu_title' => __( 'Other', 'post-views-counter' ),
609 'capability' => apply_filters( 'pvc_settings_capability', 'manage_options' ),
610 'callback' => null
611 ];
612 } */
613
614 return $pages;
615 }
616
617 /**
618 * Settings page CSS class(es).
619 *
620 * @param array $class
621 * @return array
622 */
623 public function settings_page_class( $class ) {
624 $is_pro = class_exists( 'Post_Views_Counter_Pro' );
625
626 if ( ! $is_pro )
627 $class[] = 'has-sidebar';
628
629 return $class;
630 }
631
632 /**
633 * Highlight submenu items.
634 *
635 * @param string|null $submenu_file
636 * @param string $parent_file
637 * @return string|null
638 */
639 public function submenu_file( $submenu_file, $parent_file ) {
640 if ( $parent_file === 'post-views-counter' ) {
641 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'general';
642
643 if ( $tab !== 'general' )
644 return 'post-views-counter&tab=' . $tab;
645 }
646
647 return $submenu_file;
648 }
649
650 /**
651 * Validate options.
652 *
653 * @global object $wpdb
654 *
655 * @param array $input
656 * @return array
657 */
658 public function validate_settings( $input ) {
659 // check capability
660 if ( ! current_user_can( 'manage_options' ) )
661 return $input;
662
663 global $wpdb;
664
665 // get main instance
666 $pvc = Post_Views_Counter();
667
668 // use internal settings api to validate settings first
669 $input = $pvc->settings_api->validate_settings( $input );
670
671 // import post views data from another plugin
672 if ( isset( $_POST['post_views_counter_import_wp_postviews'] ) ) {
673 // make sure we do not change anything in the settings
674 $input = $pvc->options['other'];
675
676 // get views key
677 $meta_key = sanitize_key( apply_filters( 'pvc_import_meta_key', 'views' ) );
678
679 // get views
680 $views = $wpdb->get_results( "SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = '" . $meta_key . "'", ARRAY_A, 0 );
681
682 // any views?
683 if ( ! empty( $views ) ) {
684 $sql = [];
685
686 foreach ( $views as $view ) {
687 $sql[] = "(" . (int) $view['post_id'] . ", 4, 'total', " . (int) $view['meta_value'] . ")";
688 }
689
690 $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)" );
691
692 add_settings_error( 'wp_postviews_import', 'wp_postviews_import', __( 'Post views data imported successfully.', 'post-views-counter' ), 'updated' );
693 } else
694 add_settings_error( 'wp_postviews_import', 'wp_postviews_import', __( 'There was no post views data to import.', 'post-views-counter' ), 'updated' );
695 // delete all post views data
696 } elseif ( isset( $_POST['post_views_counter_reset_views'] ) ) {
697 // make sure we do not change anything in the settings
698 $input = $pvc->options['other'];
699
700 if ( $wpdb->query( 'TRUNCATE TABLE ' . $wpdb->prefix . 'post_views' ) )
701 add_settings_error( 'reset_post_views', 'reset_post_views', __( 'All existing data deleted successfully.', 'post-views-counter' ), 'updated' );
702 else
703 add_settings_error( 'reset_post_views', 'reset_post_views', __( 'Error occurred. All existing data were not deleted.', 'post-views-counter' ), 'error' );
704 // save general settings
705 } elseif ( isset( $_POST['save_post_views_counter_settings_general'] ) ) {
706 $input['update_version'] = $pvc->options['general']['update_version'];
707 $input['update_notice'] = $pvc->options['general']['update_notice'];
708 $input['update_delay_date'] = $pvc->options['general']['update_delay_date'];
709 // reset general settings
710 } elseif ( isset( $_POST['reset_post_views_counter_settings_general'] ) ) {
711 $input['update_version'] = $pvc->options['general']['update_version'];
712 $input['update_notice'] = $pvc->options['general']['update_notice'];
713 $input['update_delay_date'] = $pvc->options['general']['update_delay_date'];
714 }
715
716 return $input;
717 }
718
719 /**
720 * Setting: taxonomies count.
721 *
722 * @param array $field
723 * @return string
724 */
725 public function setting_taxonomies_count( $field ) {
726 $html = '
727 <label><input id="post_views_counter_general_taxonomies_count" type="checkbox" name="" value="" disabled />' . esc_html( $field['label'] ) . '</label>';
728
729 return $html;
730 }
731
732 /**
733 * Setting: users count.
734 *
735 * @param array $field
736 * @return string
737 */
738 public function setting_users_count( $field ) {
739 // get base instance
740 $pvc = Post_Views_Counter();
741
742 $html = '
743 <label><input id="post_views_counter_general_users_count" type="checkbox" name="" value="" disabled />' . esc_html( $field['label'] ) . '</label>';
744
745 return $html;
746 }
747
748 /**
749 * Setting: taxonomies count.
750 *
751 * @param array $field
752 * @return string
753 */
754 public function setting_taxonomies_display( $field ) {
755 // get base instance
756 $pvc = Post_Views_Counter();
757
758 $html = '';
759
760 foreach ( $field['options'] as $taxonomy => $label ) {
761 $html .= '
762 <label><input type="checkbox" name="" value="" disabled />' . esc_html( $label ) . '</label>';
763 }
764
765 $html .= '
766 <p class="description">' . esc_html__( 'Select taxonomies for which the views count will be displayed.', 'post-views-counter' ) . '</p>';
767
768 return $html;
769 }
770
771 /**
772 * Validate label.
773 *
774 * @param array $input
775 * @param array $field
776 * @return array
777 */
778 public function validate_label( $input, $field ) {
779 // get main instance
780 $pvc = Post_Views_Counter();
781
782 if ( ! isset( $input ) )
783 $input = $pvc->defaults['display']['label'];
784
785 // use internal settings API to validate settings first
786 $input = $pvc->settings_api->validate_field( $input, 'input', $field );
787
788 if ( function_exists( 'icl_register_string' ) )
789 icl_register_string( 'Post Views Counter', 'Post Views Label', $input );
790
791 return $input;
792 }
793
794 /**
795 * Restore post views label to default value.
796 *
797 * @param array $default
798 * @param array $field
799 * @return array
800 */
801 public function reset_label( $default, $field ) {
802 if ( function_exists( 'icl_register_string' ) )
803 icl_register_string( 'Post Views Counter', 'Post Views Label', $default );
804
805 return $default;
806 }
807
808 /**
809 * Setting: display style.
810 *
811 * @param array $field
812 * @return string
813 */
814 public function setting_display_style( $field ) {
815 // get main instance
816 $pvc = Post_Views_Counter();
817
818 $html = '
819 <input type="hidden" name="post_views_counter_settings_display[display_style]" value="empty" />';
820
821 foreach ( $field['options'] as $key => $label ) {
822 $html .= '
823 <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> ';
824 }
825
826 return $html;
827 }
828
829 /**
830 * Validate display style.
831 *
832 * @param array $input
833 * @param array $field
834 * @return array
835 */
836 public function validate_display_style( $input, $field ) {
837 // get main instance
838 $pvc = Post_Views_Counter();
839
840 $data = [];
841
842 foreach ( $field['options'] as $value => $label ) {
843 $data[$value] = false;
844 }
845
846 // any data?
847 if ( ! empty( $input['display_style'] && $input['display_style'] !== 'empty' && is_array( $input['display_style'] ) ) ) {
848 foreach ( $input['display_style'] as $value ) {
849 if ( array_key_exists( $value, $field['options'] ) )
850 $data[$value] = true;
851 }
852 }
853
854 $input['display_style'] = $data;
855
856 return $input;
857 }
858
859 /**
860 * Setting: count interval.
861 *
862 * @param array $field
863 * @return string
864 */
865 public function setting_time_between_counts( $field ) {
866 // get main instance
867 $pvc = Post_Views_Counter();
868
869 $html = '
870 <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'] ) . '" />
871 <select name="post_views_counter_settings_general[time_between_counts][type]">';
872
873 foreach ( $field['options'] as $type => $type_name ) {
874 $html .= '
875 <option value="' . esc_attr( $type ) . '" ' . selected( $type, $pvc->options['general']['time_between_counts']['type'], false ) . '>' . esc_html( $type_name ) . '</option>';
876 }
877
878 $html .= '
879 </select>
880 <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>';
881
882 return $html;
883 }
884
885 /**
886 * Validate count interval.
887 *
888 * @param array $input
889 * @param array $field
890 * @return array
891 */
892 public function validate_time_between_counts( $input, $field ) {
893 // get main instance
894 $pvc = Post_Views_Counter();
895
896 // number
897 $input['time_between_counts']['number'] = isset( $input['time_between_counts']['number'] ) ? (int) $input['time_between_counts']['number'] : $pvc->defaults['general']['time_between_counts']['number'];
898
899 if ( $input['time_between_counts']['number'] < $field['min'] || $input['time_between_counts']['number'] > $field['max'] )
900 $input['time_between_counts']['number'] = $pvc->defaults['general']['time_between_counts']['number'];
901
902 // type
903 $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'];
904
905 return $input;
906 }
907
908 /**
909 * Setting: reset data interval.
910 *
911 * @param array $field
912 * @return string
913 */
914 public function setting_reset_counts( $field ) {
915 // get main instance
916 $pvc = Post_Views_Counter();
917
918 $html = '
919 <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'] ) . '" />
920 <select name="post_views_counter_settings_general[reset_counts][type]">';
921
922 foreach ( array_slice( $field['options'], 2, null, true ) as $type => $type_name ) {
923 $html .= '
924 <option value="' . esc_attr( $type ) . '" ' . selected( $type, $pvc->options['general']['reset_counts']['type'], false ) . '>' . esc_html( $type_name ) . '</option>';
925 }
926
927 $html .= '
928 </select>';
929
930 return $html;
931 }
932
933 /**
934 * Validate reset data interval.
935 *
936 * @param array $input
937 * @param array $field
938 * @return array
939 */
940 public function validate_reset_counts( $input, $field ) {
941 // get main instance
942 $pvc = Post_Views_Counter();
943
944 // number
945 $input['reset_counts']['number'] = isset( $input['reset_counts']['number'] ) ? (int) $input['reset_counts']['number'] : $pvc->defaults['general']['reset_counts']['number'];
946
947 if ( $input['reset_counts']['number'] < $field['min'] || $input['reset_counts']['number'] > $field['max'] )
948 $input['reset_counts']['number'] = $pvc->defaults['general']['reset_counts']['number'];
949
950 // type
951 $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'];
952
953 // run cron on next visit?
954 $input['cron_run'] = ( $input['reset_counts']['number'] > 0 );
955
956 // cron update?
957 $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'] ) );
958
959 return $input;
960 }
961
962 /**
963 * Setting: object cache.
964 *
965 * @param array $field
966 * @return string
967 */
968 public function setting_object_cache( $field ) {
969 // get main instance
970 $pvc = Post_Views_Counter();
971
972 // check object cache
973 $wp_using_ext_object_cache = wp_using_ext_object_cache();
974
975 $html = '
976 <input size="4" type="number" min="' . ( (int) $field['min'] ) . '" max="' . ( (int) $field['max'] ) . '" name="" value="0" disabled /> <span>' . __( 'minutes', 'post-views-counter' ) . '</span>
977 <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>
978 <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>';
979
980 return $html;
981 }
982
983 /**
984 * Setting: exclude visitors.
985 *
986 * @param array $field
987 * @return string
988 */
989 public function setting_exclude( $field ) {
990 // get main instance
991 $pvc = Post_Views_Counter();
992
993 $html = '';
994
995 foreach ( $field['options']['groups'] as $type => $type_name ) {
996 $html .= '
997 <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>';
998 }
999
1000 $html .= '
1001 <p class="description">' . __( 'Use it exclude specific user groups from post views count.', 'post-views-counter' ) . '</p>
1002 <div class="pvc_user_roles"' . ( in_array( 'roles', $pvc->options['general']['exclude']['groups'], true ) ? '' : ' style="display: none;"' ) . '>';
1003
1004 foreach ( $field['options']['roles'] as $role => $role_name ) {
1005 $html .= '
1006 <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>';
1007 }
1008
1009 $html .= '
1010 <p class="description">' . __( 'Use it exclude specific user roles from post views count.', 'post-views-counter' ) . '</p>
1011 </div>';
1012
1013 return $html;
1014 }
1015
1016 /**
1017 * Validate exclude visitors.
1018 *
1019 * @param array $input
1020 * @param array $field
1021 * @return array
1022 */
1023 public function validate_exclude( $input, $field ) {
1024 // any groups?
1025 if ( isset( $input['exclude']['groups'] ) ) {
1026 $groups = [];
1027
1028 foreach ( $input['exclude']['groups'] as $group => $set ) {
1029 if ( isset( $field['options']['groups'][$group] ) )
1030 $groups[] = $group;
1031 }
1032
1033 $input['exclude']['groups'] = array_unique( $groups );
1034 } else
1035 $input['exclude']['groups'] = [];
1036
1037 // any roles?
1038 if ( in_array( 'roles', $input['exclude']['groups'], true ) && isset( $input['exclude']['roles'] ) ) {
1039 $roles = [];
1040
1041 foreach ( $input['exclude']['roles'] as $role => $set ) {
1042 if ( isset( $field['options']['roles'][$role] ) )
1043 $roles[] = $role;
1044 }
1045
1046 $input['exclude']['roles'] = array_unique( $roles );
1047 } else
1048 $input['exclude']['roles'] = [];
1049
1050 return $input;
1051 }
1052
1053 /**
1054 * Setting: exclude IP addresses.
1055 *
1056 * @return string
1057 */
1058 public function setting_exclude_ips() {
1059 // get ip addresses
1060 $ips = Post_Views_Counter()->options['general']['exclude_ips'];
1061
1062 $html = '';
1063
1064 // any ip addresses?
1065 if ( ! empty( $ips ) ) {
1066 foreach ( $ips as $key => $ip ) {
1067 $html .= '
1068 <div class="ip-box">
1069 <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>
1070 </div>';
1071 }
1072 } else {
1073 $html .= '
1074 <div class="ip-box">
1075 <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>
1076 </div>';
1077 }
1078
1079 $html .= '
1080 <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>
1081 <p class="description">' . esc_html__( 'Enter the IP addresses to be excluded from post views count.', 'post-views-counter' ) . '</p>';
1082
1083 return $html;
1084 }
1085
1086 /**
1087 * Validate exclude IP addresses.
1088 *
1089 * @param array $input
1090 * @param array $field
1091 * @return array
1092 */
1093 public function validate_exclude_ips( $input, $field ) {
1094 // any ip addresses?
1095 if ( isset( $input['exclude_ips'] ) ) {
1096 $ips = [];
1097
1098 foreach ( $input['exclude_ips'] as $ip ) {
1099 if ( strpos( $ip, '*' ) !== false ) {
1100 $new_ip = str_replace( '*', '0', $ip );
1101
1102 if ( filter_var( $new_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) )
1103 $ips[] = $ip;
1104 } elseif ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) )
1105 $ips[] = $ip;
1106 }
1107
1108 $input['exclude_ips'] = array_unique( $ips );
1109 }
1110
1111 return $input;
1112 }
1113
1114 /**
1115 * Setting: tools.
1116 *
1117 * @return string
1118 */
1119 public function setting_wp_postviews() {
1120 $html = '
1121 <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>
1122 <p class="description">' . __( 'Import post views data from WP-PostViews plugin.', 'post-views-counter' ) . '</p>
1123 <br /><input type="submit" class="button button-secondary" name="post_views_counter_reset_views" value="' . __( 'Delete views', 'post-views-counter' ) . '" />
1124 <p class="description">' . __( 'Delete all the existing post views data.', 'post-views-counter' ) . '</p>';
1125
1126 return $html;
1127 }
1128
1129 /**
1130 * Setting: user type.
1131 *
1132 * @param array $field
1133 * @return string
1134 */
1135 public function setting_restrict_display( $field ) {
1136 // get main instance
1137 $pvc = Post_Views_Counter();
1138
1139 $html = '';
1140
1141 foreach ( $field['options']['groups'] as $type => $type_name ) {
1142 if ( $type === 'robots' )
1143 continue;
1144
1145 $html .= '
1146 <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>';
1147 }
1148
1149 $html .= '
1150 <p class="description">' . __( 'Use it to hide the post views counter from selected type of visitors.', 'post-views-counter' ) . '</p>
1151 <div class="pvc_user_roles"' . ( in_array( 'roles', $pvc->options['display']['restrict_display']['groups'], true ) ? '' : ' style="display: none;"' ) . '>';
1152
1153 foreach ( $field['options']['roles'] as $role => $role_name ) {
1154 $html .= '
1155 <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>';
1156 }
1157
1158 $html .= '
1159 <p class="description">' . __( 'Use it to hide the post views counter from selected user roles.', 'post-views-counter' ) . '</p>
1160 </div>';
1161
1162 return $html;
1163 }
1164
1165 /**
1166 * Validate user type.
1167 *
1168 * @param array $input
1169 * @param array $field
1170 * @return array
1171 */
1172 public function validate_restrict_display( $input, $field ) {
1173 // any groups?
1174 if ( isset( $input['restrict_display']['groups'] ) ) {
1175 $groups = [];
1176
1177 foreach ( $input['restrict_display']['groups'] as $group => $set ) {
1178 if ( $group === 'robots' )
1179 continue;
1180
1181 if ( isset( $field['options']['groups'][$group] ) )
1182 $groups[] = $group;
1183 }
1184
1185 $input['restrict_display']['groups'] = array_unique( $groups );
1186 } else
1187 $input['restrict_display']['groups'] = [];
1188
1189 // any roles?
1190 if ( in_array( 'roles', $input['restrict_display']['groups'], true ) && isset( $input['restrict_display']['roles'] ) ) {
1191 $roles = [];
1192
1193 foreach ( $input['restrict_display']['roles'] as $role => $set ) {
1194 if ( isset( $field['options']['roles'][$role] ) )
1195 $roles[] = $role;
1196 }
1197
1198 $input['restrict_display']['roles'] = array_unique( $roles );
1199 } else
1200 $input['restrict_display']['roles'] = [];
1201
1202 return $input;
1203 }
1204
1205 /**
1206 * Validate license.
1207 *
1208 * @param array $input
1209 * @param array $field
1210 * @return array
1211 */
1212 public function validate_license( $input, $field ) {
1213 // save value from database
1214 return $field['value'];
1215 }
1216 }
1217