PluginProbe ʕ •ᴥ•ʔ
WP Popular Posts / 7.1.0
WP Popular Posts v7.1.0
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 1 year ago form.php 1 year ago
form.php
186 lines
1 <p><strong>Important notice for administrators:</strong> The WordPress 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">WordPress 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 $wpp_shortcode .= " header='" . strip_tags($instance['title']) . "'"; // phpcs:ignore WordPress.WP.AlternativeFunctions.strip_tags_strip_tags -- We want the behavior of strip_tags;
15 }
16
17 $wpp_shortcode .= " post_type='" . (empty($instance['post_type']) ? 'post' : esc_html($instance['post_type'])) . "'";
18
19 $wpp_shortcode .= " limit=" . (( \WordPressPopularPosts\Helper::is_number($instance['limit']) && $instance['limit'] > 0 ) ? $instance['limit'] : 10);
20 $wpp_shortcode .= " range='" . (( in_array($instance['range'], $range_values) ) ? $instance['range'] : 'last24hours') . "'";
21
22 if ( 'custom' === $instance['range'] ) {
23 $wpp_shortcode .= " time_quantity=" . (( ! empty($instance['time_quantity']) && \WordPressPopularPosts\Helper::is_number($instance['time_quantity']) && $instance['time_quantity'] > 0 ) ? $instance['time_quantity'] : 24);
24 $wpp_shortcode .= " time_unit='" . (( in_array($instance['time_unit'], $time_units) ) ? $instance['time_unit'] : 'hour') . "'";
25 }
26
27 if ( $instance['freshness'] ) {
28 $wpp_shortcode .= " freshness=1";
29 }
30
31 $wpp_shortcode .= " order_by='" . (( in_array($instance['order_by'], $order_by_values) ) ? $instance['order_by'] : 'views') . "'";
32
33 if ( $instance['pid'] ) {
34 $pid = rtrim(preg_replace('|[^0-9,]|', '', $instance['pid']), ',');
35
36 if ( $pid ) {
37 $IDs_to_exclude = array_filter(explode(',', $pid), 'is_numeric');
38
39 if ( $IDs_to_exclude ) {
40 $wpp_shortcode .= " pid='" . implode(',', $IDs_to_exclude) . "'";
41 }
42 }
43 }
44
45 if ( $instance['author'] ) {
46 $author = rtrim(preg_replace('|[^0-9,]|', '', $instance['author']), ',');
47
48 if ( $author ) {
49 $IDs_to_include = array_filter(explode(',', $author), 'is_numeric');
50
51 if ( $IDs_to_include ) {
52 $wpp_shortcode .= " author='" . implode(',', $IDs_to_include) . "'";
53 }
54 }
55 }
56
57 if ( $instance['cat'] ) {
58 $cat = rtrim(preg_replace('|[^0-9,-]|', '', $instance['cat']), ',');
59
60 if ( $cat ) {
61 $cat_IDs = array_filter(explode(',', $cat), 'is_numeric');
62
63 if ( $cat_IDs ) {
64 $wpp_shortcode .= " cat='" . implode(',', $cat_IDs) . "'";
65 }
66 }
67 }
68 elseif ( $instance['term_id'] ) {
69 $term_id = rtrim(preg_replace('|[^0-9,;-]|', '', $instance['term_id']), ',');
70
71 if ( $term_id ) {
72 $term_id_chunks = explode(';', $term_id);
73
74 foreach( $term_id_chunks as $index => $chunk ) {
75 $term_id_chunks[$index] = array_filter(explode(',', $chunk), 'is_numeric');
76 $term_id_chunks[$index] = implode(',', $term_id_chunks[$index]);
77 }
78
79 $term_id_chunks = array_filter($term_id_chunks);
80
81 if ( $term_id_chunks ) {
82 $term_id_chunks = implode(';', $term_id_chunks);
83
84 $wpp_shortcode .= " term_id='" . $term_id_chunks . "'";
85
86 if ( $instance['taxonomy'] ) {
87 $taxonomy_slugs = array_map('sanitize_title', explode(';', $instance['taxonomy']));
88 $wpp_shortcode .= " taxonomy='" . implode(';', $taxonomy_slugs) . "'";
89 } else {
90 $wpp_shortcode .= " taxonomy='category'";
91 }
92 }
93 }
94 }
95
96 if (
97 $instance['shorten_title']['active']
98 && \WordPressPopularPosts\Helper::is_number($instance['shorten_title']['length'])
99 && $instance['shorten_title']['length'] > 0
100 ) {
101 $wpp_shortcode .= " title_length=" . $instance['shorten_title']['length'];
102
103 if ( $instance['shorten_title']['words'] ) {
104 $wpp_shortcode .= " title_by_words=1";
105 }
106 }
107
108 if (
109 $instance['post-excerpt']['active']
110 && \WordPressPopularPosts\Helper::is_number($instance['post-excerpt']['length'])
111 && $instance['post-excerpt']['length'] > 0
112 ) {
113 $wpp_shortcode .= " excerpt_length=" . $instance['post-excerpt']['length'];
114
115 if ( $instance['post-excerpt']['words'] ) {
116 $wpp_shortcode .= " excerpt_by_words=1";
117 }
118
119 if ( $instance['post-excerpt']['keep_format'] ) {
120 $wpp_shortcode .= " excerpt_format=1";
121 }
122 }
123
124 if (
125 $instance['thumbnail']['active']
126 && \WordPressPopularPosts\Helper::is_number($instance['thumbnail']['width'])
127 && $instance['thumbnail']['width'] > 0
128 && \WordPressPopularPosts\Helper::is_number($instance['thumbnail']['height'])
129 && $instance['thumbnail']['height'] > 0
130 ) {
131 $wpp_shortcode .= " thumbnail_width=" . $instance['thumbnail']['width'];
132 $wpp_shortcode .= " thumbnail_height=" . $instance['thumbnail']['height'];
133
134 if ( 'predefined' === $instance['thumbnail']['build'] ) {
135 $wpp_shortcode .= " thumbnail_build='predefined'";
136 }
137 }
138
139 if ( $instance['rating'] ) {
140 $wpp_shortcode .= " rating=1";
141 }
142
143 if ( $instance['stats_tag']['comment_count'] ) {
144 $wpp_shortcode .= " stats_comments=1";
145 }
146
147 if ( ! $instance['stats_tag']['views'] ) {
148 $wpp_shortcode .= " stats_views=0";
149 }
150
151 if ( $instance['stats_tag']['author'] ) {
152 $wpp_shortcode .= " stats_author=1";
153 }
154
155 if ( $instance['stats_tag']['date']['active'] ) {
156 $wpp_shortcode .= " stats_date=1";
157 $wpp_shortcode .= " stats_date_format='" . esc_html($instance['stats_tag']['date']['format']) . "'";
158 }
159
160 if ( $instance['stats_tag']['taxonomy']['active'] ) {
161 $wpp_shortcode .= " stats_taxonomy=1";
162 }
163
164 if ( $instance['markup']['custom_html'] ) {
165 $wpp_shortcode .= " header_start='" . \WordPressPopularPosts\Helper::sanitize_html($instance['markup']['title-start'], $instance) . "'";
166 $wpp_shortcode .= " header_end='" . \WordPressPopularPosts\Helper::sanitize_html($instance['markup']['title-end'], $instance) . "'";
167 $wpp_shortcode .= " wpp_start='" . \WordPressPopularPosts\Helper::sanitize_html($instance['markup']['wpp-start'], $instance) . "'";
168 $wpp_shortcode .= " wpp_end='" . \WordPressPopularPosts\Helper::sanitize_html($instance['markup']['wpp-end'], $instance) . "'";
169 $wpp_shortcode .= " post_html='" . \WordPressPopularPosts\Helper::sanitize_html($instance['markup']['post-html'], $instance) . "'";
170 }
171
172 if ( $instance['theme']['name'] ) {
173 // On the new Widgets screen $new_instance['theme'] is
174 // an array for some reason, let's grab the theme name
175 // from the array and move on
176 if ( is_array($instance['theme']['name']) ) {
177 $instance['theme']['name'] = $instance['theme']['name']['name'];
178 }
179
180 $wpp_shortcode .= " theme='" . sanitize_title($instance['theme']['name']) . "'";
181 }
182
183 $wpp_shortcode .= ']';
184
185 echo htmlentities($wpp_shortcode, ENT_NOQUOTES, 'UTF-8') . '<br /><br />';
186