PluginProbe ʕ •ᴥ•ʔ
WP Popular Posts / trunk
WP Popular Posts vtrunk
4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 5.0.0 5.0.1 5.0.2 5.1.0 5.2.0 5.2.1 5.2.2 5.2.3 5.2.4 5.3.0 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.4.0 5.4.1 5.4.2 5.5.0 5.5.1 6.0.0 6.0.1 6.0.2 6.0.3 6.0.4 6.0.5 6.1.0 6.1.1 6.1.2 6.1.3 6.1.4 6.2.0 6.2.1 6.3.0 6.3.1 6.3.2 6.3.3 6.3.4 6.4.0 6.4.1 6.4.2 7.0.0 7.0.1 7.1.0 7.2.0 7.3.0 7.3.1 7.3.2 7.3.3 7.3.4 7.3.5 7.3.6 7.3.7 7.3.8 7.4.0 trunk 2.3.7 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.2 4.0.3 4.0.5 4.0.6
wordpress-popular-posts / src / Admin / admin-page.php
wordpress-popular-posts / src / Admin Last commit date
Admin.php 1 month ago ListColumnTotalViews.php 1 month ago admin-page.php 1 month ago screen-debug.php 1 month ago screen-stats.php 1 month ago screen-tools.php 1 month ago
admin-page.php
159 lines
1 <?php
2 if ( basename($_SERVER['SCRIPT_NAME']) == basename(__FILE__) ) {
3 exit('Please do not load this page directly');
4 }
5
6 $wpp_tabs = [
7 'stats' => __('Stats', 'wordpress-popular-posts'),
8 'tools' => __('Tools', 'wordpress-popular-posts'),
9 'params' => __('Parameters', 'wordpress-popular-posts'),
10 'debug' => 'Debug'
11 ];
12
13 // Set active tab
14 if ( isset($_GET['tab'] ) && isset($wpp_tabs[$_GET['tab']] ) ) {
15 $current = $_GET['tab']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- $current will be equal to one of the registered tabs
16 } else {
17 $current = 'stats';
18 }
19
20 // Update options on form submission
21 if ( isset($_POST['section']) ) {
22
23 if ( 'stats' == $_POST['section'] ) {
24 $current = 'stats';
25
26 if ( isset($_POST['wpp-update-stats-options-token']) && wp_verify_nonce($_POST['wpp-update-stats-options-token'], 'wpp-update-stats-options') ) {
27 $this->config['stats']['limit'] = ( \WordPressPopularPosts\Helper::is_number($_POST['stats_limit']) && $_POST['stats_limit'] > 0 ) ? (int) $_POST['stats_limit'] : 10;
28 $this->config['stats']['post_type'] = empty($_POST['stats_type']) ? 'post' : sanitize_text_field($_POST['stats_type']);
29 $this->config['stats']['freshness'] = isset($_POST['stats_freshness']);
30 $this->config['stats']['y_scale'] = isset($_POST['stats_y_scale']);
31
32 update_option('wpp_settings_config', $this->config);
33 echo '<div class="notice notice-success is-dismissible"><p><strong>' . esc_html(__('Settings saved.', 'wordpress-popular-posts')) . '</strong></p></div>';
34 }
35 }
36 elseif ( 'misc' == $_POST['section'] ) {
37 $current = 'tools';
38
39 if ( isset($_POST['wpp-update-misc-options-token'] ) && wp_verify_nonce($_POST['wpp-update-misc-options-token'], 'wpp-update-misc-options') ) {
40 $this->config['tools']['link']['target'] = '_blank' === $_POST['link_target'] ? '_blank' : '_self';
41 $this->config['tools']['css'] = (bool) $_POST['css'];
42
43 update_option('wpp_settings_config', $this->config);
44 echo '<div class="notice notice-success is-dismissible"><p><strong>' . esc_html(__('Settings saved.', 'wordpress-popular-posts')) . '</strong></p></div>';
45 }
46 }
47 elseif ( 'thumb' == $_POST['section'] ) {
48 $current = 'tools';
49
50 if ( isset($_POST['wpp-update-thumbnail-options-token']) && wp_verify_nonce($_POST['wpp-update-thumbnail-options-token'], 'wpp-update-thumbnail-options') ) {
51 $valid_sources = ['featured', 'first_image', 'first_attachment', 'custom_field'];
52 $valid_formats = ['original', 'avif', 'webp'];
53 $thumb_source = isset($_POST['thumb_source']) && in_array($_POST['thumb_source'], $valid_sources) ? $_POST['thumb_source'] : 'featured';
54 $thumbnail_format = isset($_POST['thumb_format']) && in_array($_POST['thumb_format'], $valid_formats) ? $_POST['thumb_format'] : 'original';
55
56 if (
57 $thumb_source == 'custom_field'
58 && ( ! isset($_POST['thumb_field']) || empty($_POST['thumb_field']) )
59 ) {
60 echo '<div class="notice notice-error"><p>' . esc_html(__('Please provide the name of your custom field.', 'wordpress-popular-posts')) . '</p></div>';
61 }
62 else {
63 // thumbnail settings changed, flush transients
64 if ( $this->config['tools']['cache']['active'] ) {
65 $this->flush_transients();
66 }
67
68 if ( $thumbnail_format !== $this->config['tools']['thumbnail']['format'] ) {
69 $this->delete_thumbnails();
70 }
71
72 $this->config['tools']['thumbnail']['source'] = $thumb_source;
73 $this->config['tools']['thumbnail']['format'] = $thumbnail_format;
74 $this->config['tools']['thumbnail']['field'] = ( ! empty($_POST['thumb_field']) ) ? sanitize_text_field($_POST['thumb_field']) : 'wpp_thumbnail';
75 $this->config['tools']['thumbnail']['default'] = ( ! empty($_POST['upload_thumb_src']) ) ? $_POST['upload_thumb_src'] : $this->config['tools']['thumbnail']['default'];
76 $this->config['tools']['thumbnail']['resize'] = (bool) $_POST['thumb_field_resize'];
77 $this->config['tools']['thumbnail']['lazyload'] = (bool) $_POST['thumb_lazy_load'];
78
79 update_option('wpp_settings_config', $this->config );
80 echo '<div class="notice notice-success is-dismissible"><p><strong>' . esc_html(__('Settings saved.', 'wordpress-popular-posts')) . '</strong></p></div>';
81 }
82 }
83 }
84 elseif ( 'data' == $_POST['section'] && current_user_can('manage_options') ) {
85 $current = 'tools';
86
87 if ( isset($_POST['wpp-update-data-options-token'] ) && wp_verify_nonce($_POST['wpp-update-data-options-token'], 'wpp-update-data-options') ) {
88 $this->config['tools']['log']['level'] = (int) $_POST['log_option'];
89 $this->config['tools']['log']['limit'] = (int) $_POST['log_limit'];
90 $this->config['tools']['log']['expires_after'] = ( \WordPressPopularPosts\Helper::is_number($_POST['log_expire_time']) && $_POST['log_expire_time'] > 0 ) ? (int) $_POST['log_expire_time'] : 180;
91 $this->config['tools']['ajax'] = (bool) $_POST['ajax'];
92 $this->config['tools']['views_column']['active'] = (bool) $_POST['views_column'];
93 $this->config['tools']['views_column']['post_types'] = '';
94
95 if ( is_array($_POST['views_column_post_types']) && ! empty($_POST['views_column_post_types']) ) {
96 $registered_post_types = get_post_types(['public' => true], 'names');
97
98 $post_types = array_values(
99 array_intersect(
100 $_POST['views_column_post_types'],
101 $registered_post_types
102 )
103 );
104
105 $this->config['tools']['views_column']['post_types'] = $post_types ? implode(',', $post_types) : '';
106 }
107
108 // if any of the caching settings was updated, destroy all transients created by the plugin
109 if (
110 $this->config['tools']['cache']['active'] != $_POST['cache']
111 || $this->config['tools']['cache']['interval']['time'] != $_POST['cache_interval_time']
112 || $this->config['tools']['cache']['interval']['value'] != $_POST['cache_interval_value']
113 ) {
114 $this->flush_transients();
115 }
116
117 $this->config['tools']['cache']['active'] = (bool) $_POST['cache'];
118 $this->config['tools']['cache']['interval']['time'] = $_POST['cache_interval_time']; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
119 $this->config['tools']['cache']['interval']['value'] = ( isset($_POST['cache_interval_value']) && \WordPressPopularPosts\Helper::is_number($_POST['cache_interval_value']) && $_POST['cache_interval_value'] > 0 ) ? (int) $_POST['cache_interval_value'] : 1;
120
121 $this->config['tools']['sampling']['active'] = (bool) $_POST['sampling'];
122 $this->config['tools']['sampling']['rate'] = ( isset($_POST['sample_rate']) && \WordPressPopularPosts\Helper::is_number($_POST['sample_rate']) && $_POST['sample_rate'] > 0 )
123 ? (int) $_POST['sample_rate']
124 : 100;
125
126 update_option('wpp_settings_config', $this->config);
127 echo '<div class="notice notice-success is-dismissible"><p><strong>' . esc_html(__('Settings saved.', 'wordpress-popular-posts')) . '</strong></p></div>';
128 }
129 }
130
131 }
132 ?>
133
134 <?php if ( current_user_can('edit_others_posts') ) : ?>
135 <nav id="wpp-menu">
136 <ul>
137 <li <?php echo ('stats' == $current ) ? 'class="current"' : ''; ?>><a href="<?php echo esc_url(admin_url('options-general.php?page=wordpress-popular-posts&tab=stats')); ?>" title="<?php esc_attr_e('Stats', 'wordpress-popular-posts'); ?>"><span><?php esc_html_e('Stats', 'wordpress-popular-posts'); ?></span></a></li>
138 <li <?php echo ('tools' == $current ) ? 'class="current"' : ''; ?>><a href="<?php echo esc_url(admin_url('options-general.php?page=wordpress-popular-posts&tab=tools')); ?>" title="<?php esc_attr_e('Tools', 'wordpress-popular-posts'); ?>"><span><?php esc_html_e('Tools', 'wordpress-popular-posts'); ?></span></a></li>
139 <li <?php echo ('debug' == $current ) ? 'class="current"' : ''; ?>><a href="<?php echo esc_url(admin_url('options-general.php?page=wordpress-popular-posts&tab=debug')); ?>" title="Debug"><span>Debug</span></a></li>
140 </ul>
141 </nav>
142 <?php endif; ?>
143
144 <div class="wpp-wrapper wpp-section-<?php echo esc_attr($current); ?>">
145 <div class="wpp-header">
146 <p>WP Popular Posts</p>
147 <h1><?php echo esc_html($wpp_tabs[$current]); ?></h1>
148 </div>
149
150 <?php
151 // Stats
152 require_once 'screen-stats.php';
153 // Tools
154 require_once 'screen-tools.php';
155 // Debug
156 require_once 'screen-debug.php';
157 ?>
158 </div>
159