diff --git a/README.md b/README.md index 27adc2e..bc65368 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Plugins List -This is a simple Wordpress plugin aimed at giving credit where credit is due. +This is a simple community Wordpress plugin aimed at giving credit where credit is due. The plugin inserts an XHTML list into any post/page through a shortcode. If you're into customization, you can specify a format argument and indicate the exact output you are after. There's also an option to display inactive plugins as well. @@ -10,6 +10,7 @@ Features include... * Template tags are available for automatically linked items as well as simple text * Choose from a number of pieces of plugin data to be output * Display inactive plugins as well as active plugins if you wish +* Automatically limit long descriptions to specific lengths, and even remove emojis from the output * Output is cached to provide a super-quick response * A separate shortcode allows you to display how many plugins you have! diff --git a/plugins-list.php b/plugins-list.php index 5a90bb7..1977c6f 100755 --- a/plugins-list.php +++ b/plugins-list.php @@ -1,14 +1,29 @@ {{LinkedTitle}} by {{LinkedAuthor}}.' ); @@ -64,11 +79,15 @@ function plugins_list_shortcode( $paras ) { 'nofollow' => '', 'target' => '', 'by_author' => '', + 'chars' => '', + 'words' => '', + 'emoji' => '', + 'end' => '', ), $paras ); - $output = get_plugins_list( $atts['format'], $atts['show_inactive'], $atts['show_active'], $atts['cache'], $atts['nofollow'], $atts['target'], $atts['by_author'] ); + $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'] ); return $output; } @@ -118,9 +137,13 @@ function plugin_number_shortcode( $paras ) { * @param string $nofollow Whether to add nofollow to link. * @param string $target Link target. * @param string $by_author Which author. + * @param string $characters Maximum characters for description. + * @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. * @return string Output. */ -function get_plugins_list( $format, $show_inactive, $show_active, $cache, $nofollow, $target, $by_author ) { +function get_plugins_list( $format, $show_inactive, $show_active, $cache, $nofollow, $target, $by_author, $characters, $words, $emoji, $end ) { // Set default values. @@ -149,6 +172,14 @@ function get_plugins_list( $format, $show_inactive, $show_active, $cache, $nofol if ( '' !== $by_author ) { $by_author = 'true'; } + if ( 'false' == $emoji ) { + $emoji = false; + } else { + $emoji = true; + } + if ( '' == $end ) { + $end = '…'; + } // Get plugin data. @@ -173,7 +204,7 @@ function( $a, $b ) { if ( ( is_plugin_active( $plugin_file ) && 'true' === $show_active ) || ( ! is_plugin_active( $plugin_file ) && 'true' === $show_inactive ) ) { - $output .= format_plugin_list( $plugin_data, $format, $nofollow, $target ); + $output .= format_plugin_list( $plugin_data, $format, $nofollow, $target, $characters, $words, $emoji, $end ); } } @@ -265,9 +296,13 @@ function get_plugin_list_data( $cache ) { * @param string $format Format to use. * @param string $nofollow Nofollow text. * @param string $target Target text. + * @param string $characters Maximum characters for description. + * @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. * @return string Output. */ -function format_plugin_list( $plugin_data, $format, $nofollow, $target ) { +function format_plugin_list( $plugin_data, $format, $nofollow, $target, $characters, $words, $emoji, $end ) { // Allowed tag. @@ -291,6 +326,50 @@ function format_plugin_list( $plugin_data, $format, $nofollow, $target ) { $plugin_data['Version'] = wp_kses( $plugin_data['Version'], $plugins_allowedtags ); $plugin_data['Author'] = wp_kses( $plugin_data['Author'], $plugins_allowedtags ); + // Strip emoji, HTML and unnecessary space from the description. + if ( false == $emoji ) { + $plugin_data['Description'] = remove_emoji_from_plugin_desc( $plugin_data['Description'] ); + } + $plugin_data['Description'] = strip_spaces_from_plugin_desc( wp_strip_all_tags( $plugin_data['Description'] ) ); + + // Truncate the description, if required. + + if ( '' != $characters || '' != $words ) { + + // Use WordPress function to truncate description at a set number of words (ellipsis added automatically). + + if ( '' != $words ) { + $word_limited = wp_trim_words( $plugin_data['Description'], $words, $end ); + $plugin_data['Description'] = $word_limited; + } + + // Manually truncate description to a set number of characters. This is done cleanly, however, by doing so to + // the previous space. Then an ellipsis is added. + + if ( '' != $characters ) { + $character_limited = $plugin_data['Description']; + // Make sure the description is greater than the required length. + if ( strlen( $character_limited ) > $characters ) { + $space = strrpos( substr( $character_limited, 0, $characters + 1 ), ' ' ); + + if ( false == $space ) { + // If there is no space before the truncation length, just truncate. + $character_limited = substr( $character_limited, 0, $characters ); + } else { + // If there is a space within the truncated area, trim to that. + $character_limited = substr( $character_limited, 0, $space ); + } + $plugin_data['Description'] = rtrim( $character_limited ) . $end; + } + } + + // If both words and character limits are used, take whichever results in the shortest result. + + if ( ( '' != $characters && '' != $words ) && ( $word_limited < $character_limited ) ) { + $plugin_data['Description'] = $word_limited; + } + } + // Replace the tags. $format = replace_plugin_list_tags( $plugin_data, $format, $nofollow, $target ); @@ -339,3 +418,47 @@ function replace_plugin_list_tags( $plugin_data, $format, $nofollow, $target ) { return $format; } + +/** + * Remove emoji + * + * Function to strip emoji from the plugin description. + * + * @param string $description The plugin description. + * @return string Stripped description. + */ +function remove_emoji_from_plugin_desc( $description ) { + + $symbols = "\x{1F100}-\x{1F1FF}" // Enclosed Alphanumeric Supplement. + . "\x{1F300}-\x{1F5FF}" // Miscellaneous Symbols and Pictographs. + . "\x{1F600}-\x{1F64F}" // Emoticons. + . "\x{1F680}-\x{1F6FF}" // Transport And Map Symbols. + . "\x{1F900}-\x{1F9FF}" // Supplemental Symbols and Pictographs. + . "\x{2600}-\x{26FF}" // Miscellaneous Symbols. + . "\x{2700}-\x{27BF}"; // Dingbats. + + $description = preg_replace( '/[' . $symbols . ']+/u', '', $description ); + + return $description; +} + +/** + * Strip spaces + * + * Function to strip extra spaces from the plugin description. + * + * @param string $description The plugin description. + * @return string Stripped description. + */ +function strip_spaces_from_plugin_desc( $description ) { + + $continue = true; + while ( true === $continue ) { + $replace = str_replace( ' ', ' ', $description ); + if ( $replace == $description ) { + $continue = false; + } + $description = $replace; + } + return trim( $description ); +} diff --git a/readme.txt b/readme.txt index da1ac0f..3867d77 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.1 Requires PHP: 7.4 -Stable tag: 2.4.4 +Stable tag: 2.5 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -13,7 +13,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.html == Description == -This is a simple Wordpress plugin aimed at giving credit where credit is due. +This is a simple community Wordpress plugin aimed at giving credit where credit is due. The plugin inserts an XHTML list into any post/page through a shortcode. If you're into customization, you can specify a format argument and indicate the exact output you are after. There's also an option to display inactive plugins as well. @@ -22,7 +22,8 @@ Key features include... * A simple template system allows you to format how you'd like the plugin information to be shown * Template tags are available for automatically linked items as well as simple text * Choose from a number of pieces of plugin data to be output -* Display inactive plugins as well as active plugins if you wish +* Display inactive plugins as well as active plugins if you wish +* Automatically limit long descriptions to specific lengths, and even remove emojis from the output * Output is cached to provide a super-quick response * A separate shortcode allows you to display how many plugins you have! @@ -32,36 +33,29 @@ Iconography is courtesy of the very talented [Janki Rathod](https://www.fiverr.c 👉 Please visit the [Github page](https://github.com/dartiss/plugins-list "Github") for the latest code development, planned enhancements and known issues 👈 -== Instructions on use == +== Getting Started == To get a list of the plugins that are installed and activated in your website, insert the following into any post or page: -`` +`` You can customise the output specifying the `format` argument and a number of pre-defined `tags`. Here's an example: + +`[plugins_list format="{{LinkedTitle}} ({{LinkedAuthor}}) - {{Description}}{{br/}}"]` -`[plugins_list format="{{LinkedTitle}} - {{LinkedAuthor}}
"]` - -The tags are: `Title`, `PluginURI`, `Author` ,`AuthorURI`, `Version`, `Description`, `LinkedTitle`, `LinkedAuthor`. All are defined within double braces. - -If you want to list also the plug-ins you have installed but are not using, here's the formula: - -`` - -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. - -By default links will be followed but you can make these "nofollow" by simply adding the parameter of `nofollow=true`. For example... - -`` - -You can also specify the link target too. For example... - -`` +The tags are as follows, all defined within double braces... -Finally, want so sort the output by author and not plugin name? Just use the parameter `by_author`. For example... +* `Title` - the plugin title +* `PluginURI` - the URL of the plugin +* `Author` - the plugin author +* `AuthorURI` - the author's URL +* `Version` - plugin version number +* `Description` - the plugin description +* `LinkedTitle` - the title but automatically linked to the corresponding URL +* `LinkedAuthor` - the author, linking to their profile + +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. -`` - == Using HTML == If you wish to put HTML in your format then you can. However, this can cause havoc in the Visual editor and even causes extra characters to be passed into the output (rogue paragraph tags, for instance). I therefore highly recommend that, if you wish to add HTML, use double braces instead of < and > around your HTML tags - this plugin will correct this before output but it means the visual editor doesn't try and interpret the HTML. @@ -70,29 +64,87 @@ For example... `` -The characters will be corrected upon output and you will get a lovely, bulleted, un-ordered list as output. +The characters will be corrected upon output and you will get a lovely, bulleted, un-ordered list as output. + +If you're using the block editor and need to wrap HTML around the outside of the short code, please see the details further below on the best way to do this. + +== Additional Parameters == + +**Inactive Plugins** -== Cache == +If you want to list also the plug-ins you have installed but are not using, here's the formula: + +`[plugins_list format="{{LinkedTitle}} ({{LinkedAuthor}}) - {{Description}}{{br/}}" show_inactive=true]` + +**Link Targets & No Follow** -By default your plugin list will be cached for 5 minutes, ensuring that performance is impacted as little as possible. Use the parameter `cache` to change the number of minutes. Set this to false to switch off caching. +By default links will be followed but you can make these "nofollow" by simply adding the parameter of `nofollow=true`. For example... + +`[plugins_list format="{{LinkedTitle}} ({{LinkedAuthor}}) - {{Description}}{{br/}}" nofollow=true]` -For example... +You can also specify the link target too. For example... + +`[plugins_list format="{{LinkedTitle}} ({{LinkedAuthor}}) - {{Description}}{{br/}}" target="_blank"]` + +**Truncate the Description** + +Two parameters exist to truncate the description, so it doesn't get too long unwieldy. You can specify a maximum number of words or a maximum number of characters using `words` or `chars`. Here's an example of each... + +`[plugins_list format="{{LinkedTitle}} ({{LinkedAuthor}}) - {{Description}}{{br/}}" words=20]` + +`[plugins_list format="{{LinkedTitle}} ({{LinkedAuthor}}) - {{Description}}{{br/}}" chars=80]` + +You shouldn't do this but if you specify both then the shortest one will be used. + +By default, if a truncation occurs, ellipsis will be added to the end. However, you can change this by using the `end` parameter and specifying your own ending. For example... + +`[plugins_list format="{{LinkedTitle}} ({{LinkedAuthor}}) - {{Description}}{{br/}}" chars=80 end=" [More]"]` + +**Remove Emoji** + +If you want to remove emoji from the description, use the `emoji` parameter to achieve this. By default this is `true` but set to `false` to have them removed. For example... + +`[plugins_list format="{{LinkedTitle}} ({{LinkedAuthor}}) - {{Description}}{{br/}}" emoji=false]` + +**Sort by Author** + +Want so sort the output by author and not plugin name? Just use the parameter `by_author`. For example... + +`[plugins_list format="{{LinkedTitle}} ({{LinkedAuthor}}) - {{Description}}{{br/}}" by_author=true]` -`` +**Cache** -This will cache for 1 hour. The following will switch the cache off... +By default your plugin list will be cached for 5 minutes, ensuring that performance is impacted as little as possible. Use the parameter `cache` to change the number of minutes. Set this to false to switch off caching. + +For example... + +`[plugins_list format="{{LinkedTitle}} ({{LinkedAuthor}}) - {{Description}}{{br/}}" cache=60]` -`` +This will cache for 1 hour. The following will switch the cache off... + +`[plugins_list format="{{LinkedTitle}} ({{LinkedAuthor}}) - {{Description}}{{br/}}" cache=false]` + +== Using with the block editor == + +You can insert shortcodes directly into the block editor without an issue and it will be automatically added to a shortcode block. However, if you need to wrap HTML around it then this will cause issues. The solution here is to add a shortcode block first and then add the whole line into that. The HTML then works just fine. == Plugin Count == A shortcode also exists to allow you to display the number of plugins that you have. Simply add `[plugins_number]` to your post or page and it will return the number of active plugins. -To display the number of active AND inactive plugins use `[plugins_number inactive=true]`. You can also display the number of inactive plugins by specifying `[plugins_number inactive=true active=false]`. +To display the number of active AND inactive plugins use... + +`[plugins_number inactive=true]` + +You can also display the number of inactive plugins by specifying... + +`[plugins_number inactive=true active=false]` -As with the other shortcode results will be cached by default. To change the number of hours simply use the `cache` parameter. Set it to `false` to switch off caching. For example... +As with the other shortcode results will be cached by default. To change the number of minutes simply use the `cache` parameter. Set it to `false` to switch off caching. For example... -`[plugins_number inactive=true cache=2]` +`[plugins_number inactive=true cache=120]` + +This will set the cache to 2 hours. == Reviews & Mentions == @@ -121,6 +173,15 @@ Using double braces (i.e. {{ and {{) for templates is pretty standard so somethi I use semantic versioning, with the first release being 1.0. += 2.5 = +* Enhancement: New header, inc. GPL information, added to the plugin. A bit boring, I know, but a change is a change. +* Enhancement: New parameters added allowing you to limit the description length to either a certain number of words or characters. The latter is intelligent, not chopping the sentence off in the middle of a wo +* Enhancement: Extra spacing and HTML is now stripped from the plugin description by default. HTML in a plugin description? I'm looking at you Jetpack... +* Enhancement: A new parameter allows you to have emoji removed from the description as well. Nothing wrong with emojis, mind you, but they're not for everyone +* Enhancement: To support the length truncation, I've also added a new parameter to that you can specify what happens at the end of the sentence when this happens +* Enhancement: Finally, I updated this README with improved formatting and better examples. Oh, and I better explain how to use this plugin with the block editor too. +* Maintenance: Tested under PHP 8.2. No changes required for this, but I can confirm that it works without issue /wipes sweat from brow/ + = 2.4.4 = * Enhancement: To reduce the plugin's output footprint, I've removed the HTML comments - they were useful for the rare case of debugging but adding un-needed content to each page load for the 99.99999% rest of the time * Enhancement: Now follows the best code standards - not just the official WordPress standards but also the strictest WordPress VIP standards too @@ -211,5 +272,5 @@ I use semantic versioning, with the first release being 1.0. == Upgrade Notice == -= 2.4.4 = -* Nothing major - just a tidy up of the code \ No newline at end of file += 2.5 = +* Lots of new options for controlling the output of the plugin descriptions \ No newline at end of file diff --git a/uninstall.php b/uninstall.php index bd43008..f1edc2e 100755 --- a/uninstall.php +++ b/uninstall.php @@ -1,20 +1,19 @@