Skip to content

Commit

Permalink
Merge pull request #52 from dartiss/develop
Browse files Browse the repository at this point in the history
Version 2.6
  • Loading branch information
dartiss authored Aug 13, 2023
2 parents 40341f9 + fc118d7 commit 5d0ffeb
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 15 deletions.
69 changes: 58 additions & 11 deletions plugins-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -75,6 +75,7 @@ function plugins_list_shortcode( $paras ) {
'format' => '',
'show_inactive' => '',
'show_active' => '',
'show_recent' => '',
'cache' => '',
'nofollow' => '',
'target' => '',
Expand All @@ -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;
}
Expand Down Expand Up @@ -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.
Expand All @@ -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.

Expand All @@ -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;
}
Expand Down Expand Up @@ -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 );
}
}

Expand Down Expand Up @@ -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.

Expand All @@ -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'] );
}
Expand Down Expand Up @@ -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}}' => "<a href='" . $plugin_data['PluginURI'] . "' title='" . $plugin_data['Title'] . "'" . $nofollow . $target . '>' . $plugin_data['Title'] . '</a>',
'{{LinkedAuthor}}' => "<a href='" . $plugin_data['AuthorURI'] . "' title='" . $plugin_data['Author'] . "'" . $nofollow . $target . '>' . $plugin_data['Author'] . '</a>',
'#Title#' => $plugin_data['Title'],
Expand All @@ -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#' => "<a href='" . $plugin_data['PluginURI'] . "' title='" . $plugin_data['Title'] . "'" . $nofollow . $target . '>' . $plugin_data['Title'] . '</a>',
'#LinkedAuthor#' => "<a href='" . $plugin_data['AuthorURI'] . "' title='" . $plugin_data['Author'] . "'" . $nofollow . $target . '>' . $plugin_data['Author'] . '</a>',
'{{' => '<',
Expand Down
27 changes: 23 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand All @@ -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**

Expand Down Expand Up @@ -179,6 +192,12 @@ The full of allowed tags are: <a>, <b>, <big>, <blockquote>, <br>, <caption>, <c

I use semantic versioning, with the first release being 1.0.

= 2.6 =
* Enhancement: Added a new tag named `Active` that allows you to display whether the plugin is, well, active or not
* Enhancement: Added tags to display the "Required PHP" and "Required WordPress" details
* Enhancement: Back in 2.4 I added the ability to turn off the display of active plugins, to completement the paramter for inactive plugins. However, I forgot to document it, so I've now done that
* Enhancement: Added new parameter `show_recent`, which allows you to decide whether to show recently active plugins

= 2.5.2 =
* Bug: What can I say? I certainly made the plugin secure in the last release. Mainly by stopping things from working. Sorry. Hopefully that's now fixed now. I've also taken the opportunity to review which HTML tags I'm allowing - the full list is in the FAQ.

Expand Down

0 comments on commit 5d0ffeb

Please sign in to comment.