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 / Widget / form.php
wordpress-popular-posts / src / Widget Last commit date
Widget.php 3 weeks ago form.php 3 weeks ago
form.php
199 lines
1 <p><strong>Important notice for administrators:</strong> The WP Popular Posts "classic" widget has been removed.</p>
2 <p>This widget has reached end-of-life as of version 7.0. Please follow the <a href="https://cabrerahector.com/wordpress/migrating-from-the-classic-popular-posts-widget/" rel="nofollow">Migration Guide</a> to switch to either the <a href="https://github.com/cabrerahector/wordpress-popular-posts/wiki/1.-Using-WPP-on-posts-&-pages#the-wordpress-popular-posts-block" rel="nofollow">WP Popular Posts block</a> or the <a href="https://github.com/cabrerahector/wordpress-popular-posts/wiki/1.-Using-WPP-on-posts-&-pages#the-wpp-shortcode" rel="nofollow">wpp shortcode</a>.</p>
3 <p>If you decide on migrating to the <a href="https://github.com/cabrerahector/wordpress-popular-posts/wiki/1.-Using-WPP-on-posts-&-pages#the-wpp-shortcode" rel="nofollow">wpp shortcode</a>, the one below has the same settings as your classic widget:</p>
4
5 <?php
6 // possible values
7 $time_units = ['minute', 'hour', 'day', 'week', 'month'];
8 $range_values = ['daily', 'last24hours', 'weekly', 'last7days', 'monthly', 'last30days', 'all', 'custom'];
9 $order_by_values = ['comments', 'views', 'avg'];
10
11 $wpp_shortcode = '[wpp';
12
13 if ( $instance['title'] ) {
14 $current_sidebar_data = $this->get_sidebar_data();
15
16 $title_start = $current_sidebar_data['before_title'] ?? '';
17 $title_end = $current_sidebar_data['after_title'] ?? '';
18
19 $wpp_shortcode .= " header='" . strip_tags($instance['title']) . "'"; // phpcs:ignore WordPress.WP.AlternativeFunctions.strip_tags_strip_tags -- We want the behavior of strip_tags;
20
21 if ( $title_start ) {
22 $wpp_shortcode .= " header_start='" . \WordPressPopularPosts\Helper::sanitize_html($title_start, $instance) . "'";
23 }
24
25 if ( $title_end ) {
26 $wpp_shortcode .= " header_end='" . \WordPressPopularPosts\Helper::sanitize_html($title_end, $instance). "'";
27 }
28 }
29
30 $wpp_shortcode .= " post_type='" . (empty($instance['post_type']) ? 'post' : esc_html($instance['post_type'])) . "'";
31
32 $wpp_shortcode .= " limit=" . (( \WordPressPopularPosts\Helper::is_number($instance['limit']) && $instance['limit'] > 0 ) ? $instance['limit'] : 10);
33 $wpp_shortcode .= " range='" . (( in_array($instance['range'], $range_values) ) ? $instance['range'] : 'last24hours') . "'";
34
35 if ( 'custom' === $instance['range'] ) {
36 $wpp_shortcode .= " time_quantity=" . (( ! empty($instance['time_quantity']) && \WordPressPopularPosts\Helper::is_number($instance['time_quantity']) && $instance['time_quantity'] > 0 ) ? $instance['time_quantity'] : 24);
37 $wpp_shortcode .= " time_unit='" . (( in_array($instance['time_unit'], $time_units) ) ? $instance['time_unit'] : 'hour') . "'";
38 }
39
40 if ( $instance['freshness'] ) {
41 $wpp_shortcode .= " freshness=1";
42 }
43
44 $wpp_shortcode .= " order_by='" . (( in_array($instance['order_by'], $order_by_values) ) ? $instance['order_by'] : 'views') . "'";
45
46 if ( $instance['pid'] ) {
47 $pid = rtrim(preg_replace('|[^0-9,]|', '', $instance['pid']), ',');
48
49 if ( $pid ) {
50 $IDs_to_exclude = array_filter(explode(',', $pid), 'is_numeric');
51
52 if ( $IDs_to_exclude ) {
53 $wpp_shortcode .= " pid='" . implode(',', $IDs_to_exclude) . "'";
54 }
55 }
56 }
57
58 if ( $instance['author'] ) {
59 $author = rtrim(preg_replace('|[^0-9,]|', '', $instance['author']), ',');
60
61 if ( $author ) {
62 $IDs_to_include = array_filter(explode(',', $author), 'is_numeric');
63
64 if ( $IDs_to_include ) {
65 $wpp_shortcode .= " author='" . implode(',', $IDs_to_include) . "'";
66 }
67 }
68 }
69
70 if ( $instance['cat'] ) {
71 $cat = rtrim(preg_replace('|[^0-9,-]|', '', $instance['cat']), ',');
72
73 if ( $cat ) {
74 $cat_IDs = array_filter(explode(',', $cat), 'is_numeric');
75
76 if ( $cat_IDs ) {
77 $wpp_shortcode .= " cat='" . implode(',', $cat_IDs) . "'";
78 }
79 }
80 }
81 elseif ( $instance['term_id'] ) {
82 $term_id = rtrim(preg_replace('|[^0-9,;-]|', '', $instance['term_id']), ',');
83
84 if ( $term_id ) {
85 $term_id_chunks = explode(';', $term_id);
86
87 foreach( $term_id_chunks as $index => $chunk ) {
88 $term_id_chunks[$index] = array_filter(explode(',', $chunk), 'is_numeric');
89 $term_id_chunks[$index] = implode(',', $term_id_chunks[$index]);
90 }
91
92 $term_id_chunks = array_filter($term_id_chunks);
93
94 if ( $term_id_chunks ) {
95 $term_id_chunks = implode(';', $term_id_chunks);
96
97 $wpp_shortcode .= " term_id='" . $term_id_chunks . "'";
98
99 if ( $instance['taxonomy'] ) {
100 $taxonomy_slugs = array_map('sanitize_title', explode(';', $instance['taxonomy']));
101 $wpp_shortcode .= " taxonomy='" . implode(';', $taxonomy_slugs) . "'";
102 } else {
103 $wpp_shortcode .= " taxonomy='category'";
104 }
105 }
106 }
107 }
108
109 if (
110 $instance['shorten_title']['active']
111 && \WordPressPopularPosts\Helper::is_number($instance['shorten_title']['length'])
112 && $instance['shorten_title']['length'] > 0
113 ) {
114 $wpp_shortcode .= " title_length=" . $instance['shorten_title']['length'];
115
116 if ( $instance['shorten_title']['words'] ) {
117 $wpp_shortcode .= " title_by_words=1";
118 }
119 }
120
121 if (
122 $instance['post-excerpt']['active']
123 && \WordPressPopularPosts\Helper::is_number($instance['post-excerpt']['length'])
124 && $instance['post-excerpt']['length'] > 0
125 ) {
126 $wpp_shortcode .= " excerpt_length=" . $instance['post-excerpt']['length'];
127
128 if ( $instance['post-excerpt']['words'] ) {
129 $wpp_shortcode .= " excerpt_by_words=1";
130 }
131
132 if ( $instance['post-excerpt']['keep_format'] ) {
133 $wpp_shortcode .= " excerpt_format=1";
134 }
135 }
136
137 if (
138 $instance['thumbnail']['active']
139 && \WordPressPopularPosts\Helper::is_number($instance['thumbnail']['width'])
140 && $instance['thumbnail']['width'] > 0
141 && \WordPressPopularPosts\Helper::is_number($instance['thumbnail']['height'])
142 && $instance['thumbnail']['height'] > 0
143 ) {
144 $wpp_shortcode .= " thumbnail_width=" . $instance['thumbnail']['width'];
145 $wpp_shortcode .= " thumbnail_height=" . $instance['thumbnail']['height'];
146
147 if ( 'predefined' === $instance['thumbnail']['build'] ) {
148 $wpp_shortcode .= " thumbnail_build='predefined'";
149 }
150 }
151
152 if ( $instance['rating'] ) {
153 $wpp_shortcode .= " rating=1";
154 }
155
156 if ( $instance['stats_tag']['comment_count'] ) {
157 $wpp_shortcode .= " stats_comments=1";
158 }
159
160 if ( ! $instance['stats_tag']['views'] ) {
161 $wpp_shortcode .= " stats_views=0";
162 }
163
164 if ( $instance['stats_tag']['author'] ) {
165 $wpp_shortcode .= " stats_author=1";
166 }
167
168 if ( $instance['stats_tag']['date']['active'] ) {
169 $wpp_shortcode .= " stats_date=1";
170 $wpp_shortcode .= " stats_date_format='" . esc_html($instance['stats_tag']['date']['format']) . "'";
171 }
172
173 if ( $instance['stats_tag']['taxonomy']['active'] ) {
174 $wpp_shortcode .= " stats_taxonomy=1";
175 }
176
177 if ( $instance['markup']['custom_html'] ) {
178 $wpp_shortcode .= " header_start='" . \WordPressPopularPosts\Helper::sanitize_html($instance['markup']['title-start'], $instance) . "'";
179 $wpp_shortcode .= " header_end='" . \WordPressPopularPosts\Helper::sanitize_html($instance['markup']['title-end'], $instance) . "'";
180 $wpp_shortcode .= " wpp_start='" . \WordPressPopularPosts\Helper::sanitize_html($instance['markup']['wpp-start'], $instance) . "'";
181 $wpp_shortcode .= " wpp_end='" . \WordPressPopularPosts\Helper::sanitize_html($instance['markup']['wpp-end'], $instance) . "'";
182 $wpp_shortcode .= " post_html='" . \WordPressPopularPosts\Helper::sanitize_html($instance['markup']['post-html'], $instance) . "'";
183 }
184
185 if ( $instance['theme']['name'] ) {
186 // On the new Widgets screen $new_instance['theme'] is
187 // an array for some reason, let's grab the theme name
188 // from the array and move on
189 if ( is_array($instance['theme']['name']) ) {
190 $instance['theme']['name'] = $instance['theme']['name']['name'];
191 }
192
193 $wpp_shortcode .= " theme='" . sanitize_title($instance['theme']['name']) . "'";
194 }
195
196 $wpp_shortcode .= ']';
197
198 echo htmlentities($wpp_shortcode, ENT_NOQUOTES, 'UTF-8') . '<br /><br />';
199