diff --git a/plugins-list.php b/plugins-list.php index d9e8412..7e9e86a 100755 --- a/plugins-list.php +++ b/plugins-list.php @@ -9,7 +9,7 @@ * Plugin Name: Plugins List * Plugin URI: https://wordpress.org/plugins/plugins-list/ * Description: 🔌 Allows you to insert a list of the WordPress plugins you are using into any post/page. - * Version: 2.5.2 + * Version: 2.6 * Requires at least: 4.6 * Requires PHP: 7.4 * Author: David Artiss @@ -75,6 +75,7 @@ function plugins_list_shortcode( $paras ) { 'format' => '', 'show_inactive' => '', 'show_active' => '', + 'show_recent' => '', 'cache' => '', 'nofollow' => '', 'target' => '', @@ -89,7 +90,7 @@ function plugins_list_shortcode( $paras ) { // Pass the shortcode parameters onto a function to generate the plugins list. - $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'] ); + $output = 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'] ); return $output; } @@ -135,6 +136,7 @@ function plugin_number_shortcode( $paras ) { * @param string $format Requires format. * @param string $show_inactive Whether to format or not. * @param string $show_active Whether to show active or not. + * @param string $show_recent Whether to show recenty active or not. * @param string $cache Cache time. * @param string $nofollow Whether to add nofollow to link. * @param string $target Link target. @@ -145,7 +147,7 @@ function plugin_number_shortcode( $paras ) { * @param string $end When the description is truncated, what to place at the end of the string. * @return string Output. */ -function get_plugins_list( $format, $show_inactive, $show_active, $cache, $nofollow, $target, $by_author, $characters, $words, $emoji, $end ) { +function get_plugins_list( $format, $show_inactive, $show_active, $show_recent, $cache, $nofollow, $target, $by_author, $characters, $words, $emoji, $end ) { // Set default values. @@ -158,6 +160,9 @@ function get_plugins_list( $format, $show_inactive, $show_active, $cache, $nofol if ( '' === $show_active ) { $show_active = 'true'; } + if ( '' === $show_recent ) { + $show_recent = 'true'; + } if ( '' === $cache ) { $cache = 5; } @@ -198,15 +203,39 @@ function( $a, $b ) { ); } + // Get array of recently activate plugins. + + if ( is_network_admin() ) { + $recently_activated = get_site_option( 'recently_activated', array() ); + } else { + $recently_activated = get_option( 'recently_activated', array() ); + } + // Extract each plugin and format the output. $output = ''; foreach ( $plugins as $plugin_file => $plugin_data ) { - if ( ( is_plugin_active( $plugin_file ) && 'true' === $show_active ) || ( ! is_plugin_active( $plugin_file ) && 'true' === $show_inactive ) ) { + // Work out whether plugin is active or not. - $output .= format_plugin_list( $plugin_data, $format, $nofollow, $target, $characters, $words, $emoji, $end ); + $plugin_active = false; + if ( is_plugin_active( $plugin_file ) ) { + $plugin_active = true; + } + + // Was this recently active? + + $recently_active = false; + if ( is_array( $recently_activated ) && array_key_exists( $plugin_file, $recently_activated ) ) { + $recently_active = true; + } + + // Depending on whhat was requested, format the current plugin for output. + + if ( ( $recently_active && 'true' === $show_recent ) || ( $plugin_active && 'true' === $show_active ) || ( ! $plugin_active && 'true' === $show_inactive ) ) { + + $output .= format_plugin_list( $plugin_data, $format, $nofollow, $target, $characters, $words, $emoji, $end, $plugin_active ); } } @@ -302,9 +331,10 @@ function get_plugin_list_data( $cache ) { * @param string $words Maximum words for description. * @param string $emoji True or false, whether to strip emoji from description. * @param string $end When the description is truncated, what to place at the end of the string. + * @param string $plugin_active True or false, whether the plugin is active or not. * @return string Output. */ -function format_plugin_list( $plugin_data, $format, $nofollow, $target, $characters, $words, $emoji, $end ) { +function format_plugin_list( $plugin_data, $format, $nofollow, $target, $characters, $words, $emoji, $end, $plugin_active ) { // Allowed tag. @@ -322,13 +352,24 @@ function format_plugin_list( $plugin_data, $format, $nofollow, $target, $charact // Sanitize all displayed data. - $plugin_data['Title'] = wp_kses( $plugin_data['Title'], $plugins_allowedtags ); - $plugin_data['PluginURI'] = wp_kses( $plugin_data['PluginURI'], $plugins_allowedtags ); - $plugin_data['AuthorURI'] = wp_kses( $plugin_data['AuthorURI'], $plugins_allowedtags ); - $plugin_data['Version'] = wp_kses( $plugin_data['Version'], $plugins_allowedtags ); - $plugin_data['Author'] = wp_kses( $plugin_data['Author'], $plugins_allowedtags ); + $plugin_data['Title'] = wp_kses( $plugin_data['Title'], $plugins_allowedtags ); + $plugin_data['PluginURI'] = wp_kses( $plugin_data['PluginURI'], $plugins_allowedtags ); + $plugin_data['AuthorURI'] = wp_kses( $plugin_data['AuthorURI'], $plugins_allowedtags ); + $plugin_data['Version'] = wp_kses( $plugin_data['Version'], $plugins_allowedtags ); + $plugin_data['Author'] = wp_kses( $plugin_data['Author'], $plugins_allowedtags ); + $plugin_data['RequiresWP'] = wp_kses( $plugin_data['RequiresWP'], $plugins_allowedtags ); + $plugin_data['RequiresPHP'] = wp_kses( $plugin_data['RequiresPHP'], $plugins_allowedtags ); + + // Get plugin activity status. + + if ( $plugin_active ) { + $plugin_data['Active'] = __( 'Active', 'plugins-list' ); + } else { + $plugin_data['Active'] = __( 'Inactive', 'plugins-list' ); + } // Strip emoji, HTML and unnecessary space from the description. + if ( false == $emoji ) { $plugin_data['Description'] = remove_emoji_from_plugin_desc( $plugin_data['Description'] ); } @@ -401,6 +442,9 @@ function replace_plugin_list_tags( $plugin_data, $format, $nofollow, $target ) { '{{Version}}' => $plugin_data['Version'], '{{Description}}' => $plugin_data['Description'], '{{Author}}' => $plugin_data['Author'], + '{{RequiresWP}}' => $plugin_data['RequiresWP'], + '{{RequiresPHP}}' => $plugin_data['RequiresPHP'], + '{{Active}}' => $plugin_data['Active'], '{{LinkedTitle}}' => "' . $plugin_data['Title'] . '', '{{LinkedAuthor}}' => "' . $plugin_data['Author'] . '', '#Title#' => $plugin_data['Title'], @@ -409,6 +453,9 @@ function replace_plugin_list_tags( $plugin_data, $format, $nofollow, $target ) { '#Version#' => $plugin_data['Version'], '#Description#' => $plugin_data['Description'], '#Author#' => $plugin_data['Author'], + '#RequiresWP#' => $plugin_data['RequiresWP'], + '#RequiresPHP#' => $plugin_data['RequiresPHP'], + '#Active#' => $plugin_data['Active'], '#LinkedTitle#' => "' . $plugin_data['Title'] . '', '#LinkedAuthor#' => "' . $plugin_data['Author'] . '', '{{' => '<', diff --git a/readme.txt b/readme.txt index bc07f05..a99d729 100755 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: plugin, list, show, installed, display Requires at least: 4.6 Tested up to: 6.3 Requires PHP: 7.4 -Stable tag: 2.5.2 +Stable tag: 2.6 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -51,8 +51,11 @@ The tags are as follows, all defined within double braces... * `AuthorURI` - the author's URL * `Version` - plugin version number * `Description` - the plugin description +* `RequiresWP` - the minimum required level of WordPress +* `RequiresPHP` - the minimum required level of PHP * `LinkedTitle` - the title but automatically linked to the corresponding URL * `LinkedAuthor` - the author, linking to their profile +* `Active` - shows 'Active' or 'Inactive', depending on the status of the plugin The plugins list can be freely styled with css, just place any *class* or *id* attribute on the `format` string, or on the elements surrounding it. @@ -70,11 +73,21 @@ If you're using the block editor and need to wrap HTML around the outside of the == Additional Parameters == -**Inactive Plugins** +**Active & Inactive Plugins** + +By default, only active plugins are shown, but by using the `show_active`, `show_inactive` and `show_recent` parameters you can change this. -If you want to list also the plug-ins you have installed but are not using, here's the formula: +For example, this will show both active and inactive... + +`[plugins_list format="{{LinkedTitle}} ({{LinkedAuthor}}) - {{Description}}{{br/}}" show_inactive=true]` + +If you wanted to show just inactive, you'd put.. -`[plugins_list format="{{LinkedTitle}} ({{LinkedAuthor}}) - {{Description}}{{br/}}" show_inactive=true]` +`[plugins_list format="{{LinkedTitle}} ({{LinkedAuthor}}) - {{Description}}{{br/}}" show_inactive=true show_active=false]` + +If you wanted to show just plugins that are inactive but were recently acive, you'd put... + +`[plugins_list format="{{LinkedTitle}} ({{LinkedAuthor}}) - {{Description}}{{br/}}" show_inactive=false show_active=false show_recent=true]` **Link Targets & No Follow** @@ -179,6 +192,12 @@ The full of allowed tags are: , , ,
,
, ,