PluginProbe
Plugins List / 2.6.1
Plugins List v2.6.1
trunk 0.2.1 0.2.2 1.0 2.0 2.1 2.2.7 2.3.2 2.4.4 2.5.2 2.6 2.6.1 2.7
← All changes | plugins-list.php +100 -54 2.5.22.6.1 View file →
@@ -8,9 +8,9 @@
8 8 *
9 9 * Plugin Name: Plugins List
10 10 * Plugin URI: https://wordpress.org/plugins/plugins-list/
11 11 * Description: 🔌 Allows you to insert a list of the WordPress plugins you are using into any post/page.
12 - * Version: 2.5.2
12 + * Version: 2.6.1
13 13 * Requires at least: 4.6
14 14 * Requires PHP: 7.4
15 15 * Author: David Artiss
16 16 * Author URI: https://artiss.blog
@@ -39,9 +39,9 @@
39 39 * @param string $links Current links.
40 40 * @param string $file File in use.
41 41 * @return string Links, now with settings added.
42 42 */
43 -function set_plugins_list_meta( $links, $file ) {
43 +function pll_set_plugins_meta( $links, $file ) {
44 44
45 45 if ( false !== strpos( $file, 'plugins-list.php' ) ) {
46 46
47 47 $links = array_merge( $links, array( '<a href="https://github.com/dartiss/plugins-list">' . __( 'Github', 'plugins-list' ) . '</a>' ) );
@@ -55,9 +55,9 @@
55 55
56 56 return $links;
57 57 }
58 58
59 -add_filter( 'plugin_row_meta', 'set_plugins_list_meta', 10, 2 );
59 +add_filter( 'plugin_row_meta', 'pll_set_plugins_meta', 10, 2 );
60 60
61 61 /**
62 62 * Main Shortcode Function
63 63 *
@@ -62,14 +62,14 @@
62 62 * Main Shortcode Function
63 63 *
64 64 * Extract shortcode parameters and call main function to output results
65 65 *
66 - * @uses get_plugins_list Get the list of plugins
66 + * @uses pll_get_plugins_list Get the list of plugins
67 67 *
68 - * @param string $paras Shortcode parameters.
69 - * @return stri Output.
68 + * @param string $paras Shortcode parameters.
69 + * @return string Output.
70 70 */
71 -function plugins_list_shortcode( $paras ) {
71 +function pll_add_shortcode( $paras ) {
72 72
73 73 $atts = shortcode_atts(
74 74 array(
75 75 'format' => '',
@@ -74,8 +74,9 @@
74 74 array(
75 75 'format' => '',
76 76 'show_inactive' => '',
77 77 'show_active' => '',
78 + 'show_recent' => '',
78 79 'cache' => '',
79 80 'nofollow' => '',
80 81 'target' => '',
81 82 'by_author' => '',
@@ -88,14 +89,14 @@
88 89 );
89 90
90 91 // Pass the shortcode parameters onto a function to generate the plugins list.
91 92
92 - $output = get_plugins_list( $atts['format'], $atts['show_inactive'], $atts['show_active'], $atts['cache'], $atts['nofollow'], $atts['target'], $atts['by_author'], $atts['chars'], $atts['words'], $atts['emoji'], $atts['end'] );
93 + $output = pll_get_plugins_list( $atts['format'], $atts['show_inactive'], $atts['show_active'], $atts['show_recent'], $atts['cache'], $atts['nofollow'], $atts['target'], $atts['by_author'], $atts['chars'], $atts['words'], $atts['emoji'], $atts['end'] );
93 94
94 95 return $output;
95 96 }
96 97
97 -add_shortcode( 'plugins_list', 'plugins_list_shortcode' );
98 +add_shortcode( 'plugins_list', 'pll_add_shortcode' );
98 99
99 100 /**
100 101 * Number of plugins shortcode
101 102 *
@@ -100,14 +101,14 @@
100 101 * Number of plugins shortcode
101 102 *
102 103 * Shortcode to return number of plugins
103 104 *
104 - * @uses get_plugin_number Get the number of plugins
105 + * @uses pll_get_plugin_number Get the number of plugins
105 106 *
106 - * @param string $paras Shortcode parameters.
107 - * @return string Output.
107 + * @param string $paras Shortcode parameters.
108 + * @return string Output.
108 109 */
109 -function plugin_number_shortcode( $paras ) {
110 +function pll_add_number_shortcode( $paras ) {
110 111
111 112 $atts = shortcode_atts(
112 113 array(
113 114 'active' => 'true',
@@ -116,14 +117,14 @@
116 117 ),
117 118 $paras
118 119 );
119 120
120 - $output = get_plugin_number( $atts['active'], $atts['inactive'], $atts['cache'] );
121 + $output = pll_get_plugin_number( $atts['active'], $atts['inactive'], $atts['cache'] );
121 122
122 123 return $output;
123 124 }
124 125
125 -add_shortcode( 'plugins_number', 'plugin_number_shortcode' );
126 +add_shortcode( 'plugins_number', 'add_add_number_shortcode' );
126 127
127 128 /**
128 129 * Get Plugins List
129 130 *
@@ -128,14 +129,15 @@
128 129 * Get Plugins List
129 130 *
130 131 * Get list of plugins and, optionally, format them
131 132 *
132 - * @uses format_plugin_list Format the plugin list
133 - * @uses get_plugin_list_data Get the plugin data
133 + * @uses pll_format_plugin_list Format the plugin list
134 + * @uses pll_get_data Get the plugin data
134 135 *
135 136 * @param string $format Requires format.
136 137 * @param string $show_inactive Whether to format or not.
137 138 * @param string $show_active Whether to show active or not.
139 + * @param string $show_recent Whether to show recenty active or not.
138 140 * @param string $cache Cache time.
139 141 * @param string $nofollow Whether to add nofollow to link.
140 142 * @param string $target Link target.
141 143 * @param string $by_author Which author.
@@ -144,9 +146,9 @@
144 146 * @param string $emoji True or false, whether to strip emoji from description.
145 147 * @param string $end When the description is truncated, what to place at the end of the string.
146 148 * @return string Output.
147 149 */
148 -function get_plugins_list( $format, $show_inactive, $show_active, $cache, $nofollow, $target, $by_author, $characters, $words, $emoji, $end ) {
150 +function pll_get_plugins_list( $format, $show_inactive, $show_active, $show_recent, $cache, $nofollow, $target, $by_author, $characters, $words, $emoji, $end ) {
149 151
150 152 // Set default values.
151 153
152 154 if ( '' === $format ) {
@@ -157,8 +159,11 @@
157 159 }
158 160 if ( '' === $show_active ) {
159 161 $show_active = 'true';
160 162 }
163 + if ( '' === $show_recent ) {
164 + $show_recent = 'true';
165 + }
161 166 if ( '' === $cache ) {
162 167 $cache = 5;
163 168 }
164 169 if ( $nofollow ) {
@@ -173,20 +178,20 @@
173 178 }
174 179 if ( '' !== $by_author ) {
175 180 $by_author = 'true';
176 181 }
177 - if ( 'false' == $emoji ) {
182 + if ( 'false' === $emoji ) {
178 183 $emoji = false;
179 184 } else {
180 185 $emoji = true;
181 186 }
182 - if ( '' == $end ) {
187 + if ( '' === $end ) {
183 188 $end = '&#8230;';
184 189 }
185 190
186 191 // Get plugin data.
187 192
188 - $plugins = get_plugin_list_data( $cache );
193 + $plugins = pll_get_data( $cache );
189 194
190 195 // Sort the plugin array if required in author sequence.
191 196
192 197 if ( 'true' === $by_author ) {
@@ -191,14 +196,22 @@
191 196
192 197 if ( 'true' === $by_author ) {
193 198 uasort(
194 199 $plugins,
195 - function( $a, $b ) {
200 + function ( $a, $b ) {
196 201 return strtoupper( $a['Author'] ) <=> strtoupper( $b['Author'] );
197 202 }
198 203 );
199 204 }
200 205
206 + // Get array of recently activate plugins.
207 +
208 + if ( is_network_admin() ) {
209 + $recently_activated = get_site_option( 'recently_activated', array() );
210 + } else {
211 + $recently_activated = get_option( 'recently_activated', array() );
212 + }
213 +
201 214 // Extract each plugin and format the output.
202 215
203 216 $output = '';
204 217
@@ -203,18 +216,33 @@
203 216 $output = '';
204 217
205 218 foreach ( $plugins as $plugin_file => $plugin_data ) {
206 219
207 - if ( ( is_plugin_active( $plugin_file ) && 'true' === $show_active ) || ( ! is_plugin_active( $plugin_file ) && 'true' === $show_inactive ) ) {
220 + // Work out whether plugin is active or not.
208 221
209 - $output .= format_plugin_list( $plugin_data, $format, $nofollow, $target, $characters, $words, $emoji, $end );
222 + $plugin_active = false;
223 + if ( is_plugin_active( $plugin_file ) ) {
224 + $plugin_active = true;
210 225 }
226 +
227 + // Was this recently active?
228 +
229 + $recently_active = false;
230 + if ( is_array( $recently_activated ) && array_key_exists( $plugin_file, $recently_activated ) ) {
231 + $recently_active = true;
232 + }
233 +
234 + // Depending on whhat was requested, format the current plugin for output.
235 +
236 + if ( ( $recently_active && 'true' === $show_recent ) || ( $plugin_active && 'true' === $show_active ) || ( ! $plugin_active && 'true' === $show_inactive ) ) {
237 +
238 + $output .= pll_format_plugin_list( $plugin_data, $format, $nofollow, $target, $characters, $words, $emoji, $end, $plugin_active );
239 + }
211 240 }
212 241
213 242 // Return the code, with HTML comments.
214 243
215 244 return "\n" . $output . "\n";
216 -
217 245 }
218 246
219 247 /**
220 248 * Get Plugin number
@@ -222,20 +250,20 @@
222 250 * Get number of plugins
223 251 *
224 252 * @since 2.2
225 253 *
226 - * @uses get_plugin_list_data Get the plugin data
254 + * @uses pll_get_data Get the plugin data
227 255 *
228 256 * @param string $show_active Whether to include active plugins or not.
229 257 * @param string $show_inactive Whether to include inactive plugins or not.
230 258 * @param string $cache Cache time.
231 - * @return string Plugin number.
259 + * @return string Plugin number.
232 260 */
233 -function get_plugin_number( $show_active, $show_inactive, $cache ) {
261 +function pll_get_plugin_number( $show_active, $show_inactive, $cache ) {
234 262
235 263 // Get plugin data.
236 264
237 - $plugins = get_plugin_list_data( $cache );
265 + $plugins = pll_get_data( $cache );
238 266
239 267 // Get count.
240 268
241 269 if ( 'true' === $show_inactive && 'true' === $show_active ) {
@@ -243,9 +271,9 @@
243 271 } else {
244 272 $output = 0;
245 273 foreach( $plugins as $plugin_file => $plugin_data ) { // @codingStandardsIgnoreLine -- require $plugin_data for array values but not doing anything with it
246 274 if ( is_plugin_active( $plugin_file ) ) {
247 - $output++;
275 + ++$output;
248 276 }
249 277 }
250 278 if ( 'true' === $show_inactive ) {
251 279 $output = count( $plugins ) - $output; }
@@ -258,14 +286,14 @@
258 286 * Get Plugins data
259 287 *
260 288 * Get plugin data and cache it
261 289 *
262 - * @uses format_plugin_list Format the plugin list.
290 + * @uses pll_format_plugin_list Format the plugin list.
263 291 *
264 292 * @param string $cache Cache time.
265 293 * @return string Plugin data.
266 294 */
267 -function get_plugin_list_data( $cache ) {
295 +function pll_get_data( $cache ) {
268 296
269 297 // Attempt to get plugin list from cache.
270 298
271 299 if ( ! $cache ) {
@@ -293,19 +321,20 @@
293 321 * Format the plugin list
294 322 *
295 323 * @uses replace_plugin_list_tags Replace the tags
296 324 *
297 - * @param string $plugin_data The plugin list.
298 - * @param string $format Format to use.
299 - * @param string $nofollow Nofollow text.
300 - * @param string $target Target text.
301 - * @param string $characters Maximum characters for description.
302 - * @param string $words Maximum words for description.
303 - * @param string $emoji True or false, whether to strip emoji from description.
304 - * @param string $end When the description is truncated, what to place at the end of the string.
305 - * @return string Output.
325 + * @param string $plugin_data The plugin list.
326 + * @param string $format Format to use.
327 + * @param string $nofollow Nofollow text.
328 + * @param string $target Target text.
329 + * @param string $characters Maximum characters for description.
330 + * @param string $words Maximum words for description.
331 + * @param string $emoji True or false, whether to strip emoji from description.
332 + * @param string $end When the description is truncated, what to place at the end of the string.
333 + * @param string $plugin_active True or false, whether the plugin is active or not.
334 + * @return string Output.
306 335 */
307 -function format_plugin_list( $plugin_data, $format, $nofollow, $target, $characters, $words, $emoji, $end ) {
336 +function pll_format_plugin_list( $plugin_data, $format, $nofollow, $target, $characters, $words, $emoji, $end, $plugin_active ) {
308 337
309 338 // Allowed tag.
310 339
311 340 $plugins_allowedtags = array(
@@ -321,16 +350,27 @@
321 350 );
322 351
323 352 // Sanitize all displayed data.
324 353
325 - $plugin_data['Title'] = wp_kses( $plugin_data['Title'], $plugins_allowedtags );
326 - $plugin_data['PluginURI'] = wp_kses( $plugin_data['PluginURI'], $plugins_allowedtags );
327 - $plugin_data['AuthorURI'] = wp_kses( $plugin_data['AuthorURI'], $plugins_allowedtags );
328 - $plugin_data['Version'] = wp_kses( $plugin_data['Version'], $plugins_allowedtags );
329 - $plugin_data['Author'] = wp_kses( $plugin_data['Author'], $plugins_allowedtags );
354 + $plugin_data['Title'] = wp_kses( $plugin_data['Title'], $plugins_allowedtags );
355 + $plugin_data['PluginURI'] = wp_kses( $plugin_data['PluginURI'], $plugins_allowedtags );
356 + $plugin_data['AuthorURI'] = wp_kses( $plugin_data['AuthorURI'], $plugins_allowedtags );
357 + $plugin_data['Version'] = wp_kses( $plugin_data['Version'], $plugins_allowedtags );
358 + $plugin_data['Author'] = wp_kses( $plugin_data['Author'], $plugins_allowedtags );
359 + $plugin_data['RequiresWP'] = wp_kses( $plugin_data['RequiresWP'], $plugins_allowedtags );
360 + $plugin_data['RequiresPHP'] = wp_kses( $plugin_data['RequiresPHP'], $plugins_allowedtags );
330 361
362 + // Get plugin activity status.
363 +
364 + if ( $plugin_active ) {
365 + $plugin_data['Active'] = __( 'Active', 'plugins-list' );
366 + } else {
367 + $plugin_data['Active'] = __( 'Inactive', 'plugins-list' );
368 + }
369 +
331 370 // Strip emoji, HTML and unnecessary space from the description.
332 - if ( false == $emoji ) {
371 +
372 + if ( false === $emoji ) {
333 373 $plugin_data['Description'] = remove_emoji_from_plugin_desc( $plugin_data['Description'] );
334 374 }
335 375 $plugin_data['Description'] = strip_spaces_from_plugin_desc( wp_strip_all_tags( $plugin_data['Description'] ) );
336 376
@@ -335,13 +375,13 @@
335 375 $plugin_data['Description'] = strip_spaces_from_plugin_desc( wp_strip_all_tags( $plugin_data['Description'] ) );
336 376
337 377 // Truncate the description, if required.
338 378
339 - if ( '' != $characters || '' != $words ) {
379 + if ( '' !== $characters || '' !== $words ) {
340 380
341 381 // Use WordPress function to truncate description at a set number of words (ellipsis added automatically).
342 382
343 - if ( '' != $words ) {
383 + if ( '' !== $words ) {
344 384 $word_limited = wp_trim_words( $plugin_data['Description'], $words, $end );
345 385 $plugin_data['Description'] = $word_limited;
346 386 }
347 387
@@ -347,15 +387,15 @@
347 387
348 388 // Manually truncate description to a set number of characters. This is done cleanly, however, by doing so to
349 389 // the previous space. Then an ellipsis is added.
350 390
351 - if ( '' != $characters ) {
391 + if ( '' !== $characters ) {
352 392 $character_limited = $plugin_data['Description'];
353 393 // Make sure the description is greater than the required length.
354 394 if ( strlen( $character_limited ) > $characters ) {
355 395 $space = strrpos( substr( $character_limited, 0, $characters + 1 ), ' ' );
356 396
357 - if ( false == $space ) {
397 + if ( false === $space ) {
358 398 // If there is no space before the truncation length, just truncate.
359 399 $character_limited = substr( $character_limited, 0, $characters );
360 400 } else {
361 401 // If there is a space within the truncated area, trim to that.
@@ -366,9 +406,9 @@
366 406 }
367 407
368 408 // If both words and character limits are used, take whichever results in the shortest result.
369 409
370 - if ( ( '' != $characters && '' != $words ) && ( $word_limited < $character_limited ) ) {
410 + if ( ( '' !== $characters && '' !== $words ) && ( $word_limited < $character_limited ) ) {
371 411 $plugin_data['Description'] = $word_limited;
372 412 }
373 413 }
374 414
@@ -400,8 +440,11 @@
400 440 '{{AuthorURI}}' => $plugin_data['AuthorURI'],
401 441 '{{Version}}' => $plugin_data['Version'],
402 442 '{{Description}}' => $plugin_data['Description'],
403 443 '{{Author}}' => $plugin_data['Author'],
444 + '{{RequiresWP}}' => $plugin_data['RequiresWP'],
445 + '{{RequiresPHP}}' => $plugin_data['RequiresPHP'],
446 + '{{Active}}' => $plugin_data['Active'],
404 447 '{{LinkedTitle}}' => "<a href='" . $plugin_data['PluginURI'] . "' title='" . $plugin_data['Title'] . "'" . $nofollow . $target . '>' . $plugin_data['Title'] . '</a>',
405 448 '{{LinkedAuthor}}' => "<a href='" . $plugin_data['AuthorURI'] . "' title='" . $plugin_data['Author'] . "'" . $nofollow . $target . '>' . $plugin_data['Author'] . '</a>',
406 449 '#Title#' => $plugin_data['Title'],
407 450 '#PluginURI#' => $plugin_data['PluginURI'],
@@ -408,8 +451,11 @@
408 451 '#AuthorURI#' => $plugin_data['AuthorURI'],
409 452 '#Version#' => $plugin_data['Version'],
410 453 '#Description#' => $plugin_data['Description'],
411 454 '#Author#' => $plugin_data['Author'],
455 + '#RequiresWP#' => $plugin_data['RequiresWP'],
456 + '#RequiresPHP#' => $plugin_data['RequiresPHP'],
457 + '#Active#' => $plugin_data['Active'],
412 458 '#LinkedTitle#' => "<a href='" . $plugin_data['PluginURI'] . "' title='" . $plugin_data['Title'] . "'" . $nofollow . $target . '>' . $plugin_data['Title'] . '</a>',
413 459 '#LinkedAuthor#' => "<a href='" . $plugin_data['AuthorURI'] . "' title='" . $plugin_data['Author'] . "'" . $nofollow . $target . '>' . $plugin_data['Author'] . '</a>',
414 460 '{{' => '<',
415 461 '}}' => '>',
@@ -637,9 +683,9 @@
637 683
638 684 $continue = true;
639 685 while ( true === $continue ) {
640 686 $replace = str_replace( ' ', ' ', $description );
641 - if ( $replace == $description ) {
687 + if ( $replace === $description ) {
642 688 $continue = false;
643 689 }
644 690 $description = $replace;
645 691 }