PluginProbe ʕ •ᴥ•ʔ
WP Popular Posts / 7.3.7
WP Popular Posts v7.3.7
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 9 months ago admin-page.php 5 months ago screen-debug.php 2 years ago screen-stats.php 5 months ago screen-tools.php 9 months ago
admin-page.php
145 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 $this->config['tools']['experimental'] = isset($_POST['experimental_features']);
43
44 update_option('wpp_settings_config', $this->config);
45 echo '<div class="notice notice-success is-dismissible"><p><strong>' . esc_html(__('Settings saved.', 'wordpress-popular-posts')) . '</strong></p></div>';
46 }
47 }
48 elseif ( 'thumb' == $_POST['section'] ) {
49 $current = 'tools';
50
51 if ( isset($_POST['wpp-update-thumbnail-options-token']) && wp_verify_nonce($_POST['wpp-update-thumbnail-options-token'], 'wpp-update-thumbnail-options') ) {
52 $valid_sources = ['featured', 'first_image', 'first_attachment', 'custom_field'];
53 $valid_formats = ['original', 'avif', 'webp'];
54 $thumb_source = isset($_POST['thumb_source']) && in_array($_POST['thumb_source'], $valid_sources) ? $_POST['thumb_source'] : 'featured';
55 $thumbnail_format = isset($_POST['thumb_format']) && in_array($_POST['thumb_format'], $valid_formats) ? $_POST['thumb_format'] : 'original';
56
57 if (
58 $thumb_source == 'custom_field'
59 && ( ! isset($_POST['thumb_field']) || empty($_POST['thumb_field']) )
60 ) {
61 echo '<div class="notice notice-error"><p>' . esc_html(__('Please provide the name of your custom field.', 'wordpress-popular-posts')) . '</p></div>';
62 }
63 else {
64 // thumbnail settings changed, flush transients
65 if ( $this->config['tools']['cache']['active'] ) {
66 $this->flush_transients();
67 }
68
69 if ( $thumbnail_format !== $this->config['tools']['thumbnail']['format'] ) {
70 $this->delete_thumbnails();
71 }
72
73 $this->config['tools']['thumbnail']['source'] = $thumb_source;
74 $this->config['tools']['thumbnail']['format'] = $thumbnail_format;
75 $this->config['tools']['thumbnail']['field'] = ( ! empty($_POST['thumb_field']) ) ? sanitize_text_field($_POST['thumb_field']) : 'wpp_thumbnail';
76 $this->config['tools']['thumbnail']['default'] = ( ! empty($_POST['upload_thumb_src']) ) ? $_POST['upload_thumb_src'] : $this->config['tools']['thumbnail']['default'];
77 $this->config['tools']['thumbnail']['resize'] = (bool) $_POST['thumb_field_resize'];
78 $this->config['tools']['thumbnail']['lazyload'] = (bool) $_POST['thumb_lazy_load'];
79
80 update_option('wpp_settings_config', $this->config );
81 echo '<div class="notice notice-success is-dismissible"><p><strong>' . esc_html(__('Settings saved.', 'wordpress-popular-posts')) . '</strong></p></div>';
82 }
83 }
84 }
85 elseif ( 'data' == $_POST['section'] && current_user_can('manage_options') ) {
86 $current = 'tools';
87
88 if ( isset($_POST['wpp-update-data-options-token'] ) && wp_verify_nonce($_POST['wpp-update-data-options-token'], 'wpp-update-data-options') ) {
89 $this->config['tools']['log']['level'] = (int) $_POST['log_option'];
90 $this->config['tools']['log']['limit'] = (int) $_POST['log_limit'];
91 $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;
92 $this->config['tools']['ajax'] = (bool) $_POST['ajax'];
93
94 // if any of the caching settings was updated, destroy all transients created by the plugin
95 if (
96 $this->config['tools']['cache']['active'] != $_POST['cache']
97 || $this->config['tools']['cache']['interval']['time'] != $_POST['cache_interval_time']
98 || $this->config['tools']['cache']['interval']['value'] != $_POST['cache_interval_value']
99 ) {
100 $this->flush_transients();
101 }
102
103 $this->config['tools']['cache']['active'] = (bool) $_POST['cache'];
104 $this->config['tools']['cache']['interval']['time'] = $_POST['cache_interval_time']; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
105 $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;
106
107 $this->config['tools']['sampling']['active'] = (bool) $_POST['sampling'];
108 $this->config['tools']['sampling']['rate'] = ( isset($_POST['sample_rate']) && \WordPressPopularPosts\Helper::is_number($_POST['sample_rate']) && $_POST['sample_rate'] > 0 )
109 ? (int) $_POST['sample_rate']
110 : 100;
111
112 update_option('wpp_settings_config', $this->config);
113 echo '<div class="notice notice-success is-dismissible"><p><strong>' . esc_html(__('Settings saved.', 'wordpress-popular-posts')) . '</strong></p></div>';
114 }
115 }
116
117 }
118 ?>
119
120 <?php if ( current_user_can('edit_others_posts') ) : ?>
121 <nav id="wpp-menu">
122 <ul>
123 <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>
124 <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>
125 <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>
126 </ul>
127 </nav>
128 <?php endif; ?>
129
130 <div class="wpp-wrapper wpp-section-<?php echo esc_attr($current); ?>">
131 <div class="wpp-header">
132 <h2>WP Popular Posts</h2>
133 <h3><?php echo esc_html($wpp_tabs[$current]); ?></h3>
134 </div>
135
136 <?php
137 // Stats
138 require_once 'screen-stats.php';
139 // Tools
140 require_once 'screen-tools.php';
141 // Debug
142 require_once 'screen-debug.php';
143 ?>
144 </div>
145