| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Plugins List |
| 4 |
Plugin URI: https://wordpress.org/plugins/plugins-list/ |
| 5 |
Description: Allows you to insert a list of the Wordpress plugins you are using into any post/page. |
| 6 |
Version: 2.3.2 |
| 7 |
Author: David Artiss |
| 8 |
Author URI: https://artiss.blog |
| 9 |
Text Domain: plugins-list |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* Artiss Plugins List |
| 14 |
* |
| 15 |
* Main code - include various functions |
| 16 |
* |
| 17 |
* @package Artiss-Plugins-List |
| 18 |
* @since 2.1 |
| 19 |
*/ |
| 20 |
|
| 21 |
define( 'plugins_list_version', '2.3.1' ); |
| 22 |
|
| 23 |
define( 'APL_DEFAULT_PLUGIN_FORMAT', '<li>#LinkedTitle# by #LinkedAuthor#.</li>' ); |
| 24 |
|
| 25 |
if ( !function_exists( 'get_plugins' ) ) { require_once ( ABSPATH . 'wp-admin/includes/plugin.php' ); } |
| 26 |
|
| 27 |
/** |
| 28 |
* Add meta to plugin details |
| 29 |
* |
| 30 |
* Add options to plugin meta line |
| 31 |
* |
| 32 |
* @since 2.0 |
| 33 |
* |
| 34 |
* @param string $links Current links |
| 35 |
* @param string $file File in use |
| 36 |
* @return string Links, now with settings added |
| 37 |
*/ |
| 38 |
|
| 39 |
function apl_set_plugin_meta( $links, $file ) { |
| 40 |
|
| 41 |
if ( false !== strpos( $file, 'plugins-list.php' ) ) { $links = array_merge( $links, array( '<a href="http://wordpress.org/support/plugin/plugins-list">' . __( 'Support', 'plugins-list' ) . '</a>' ) ); } |
| 42 |
|
| 43 |
return $links; |
| 44 |
} |
| 45 |
|
| 46 |
add_filter( 'plugin_row_meta', 'apl_set_plugin_meta', 10, 2 ); |
| 47 |
|
| 48 |
/** |
| 49 |
* Main Shortcode Function |
| 50 |
* |
| 51 |
* Extract shortcode parameters and call main function to output results |
| 52 |
* |
| 53 |
* @since 1.0 |
| 54 |
* |
| 55 |
* @uses get_plugins_list Get the list of plugins |
| 56 |
* |
| 57 |
* @param string $paras Shortcode parameters |
| 58 |
* @return string Output |
| 59 |
*/ |
| 60 |
|
| 61 |
function apl_plugins_list_shortcode( $paras ) { |
| 62 |
|
| 63 |
extract( shortcode_atts( array( 'format' => '', 'show_inactive' => '', 'cache' => '', 'nofollow' => '', 'target' => '' ), $paras ) ); |
| 64 |
|
| 65 |
$output = get_plugins_list( $format, $show_inactive, $cache, $nofollow, $target ); |
| 66 |
|
| 67 |
return $output; |
| 68 |
} |
| 69 |
|
| 70 |
add_shortcode( 'plugins_list', 'apl_plugins_list_shortcode' ); |
| 71 |
|
| 72 |
/** |
| 73 |
* Number of plugins shortcode |
| 74 |
* |
| 75 |
* Shortcode to return number of plugins |
| 76 |
* |
| 77 |
* @since 2.2 |
| 78 |
* |
| 79 |
* @uses get_plugin_number Get the number of plugins |
| 80 |
* |
| 81 |
* @param string $paras Shortcode parameters |
| 82 |
* @return string Output |
| 83 |
*/ |
| 84 |
|
| 85 |
function apl_plugin_number_shortcode( $paras ) { |
| 86 |
|
| 87 |
extract( shortcode_atts( array( 'inactive' => '', 'cache' => '' ), $paras ) ); |
| 88 |
|
| 89 |
$output = get_plugin_number( $inactive, $cache ); |
| 90 |
|
| 91 |
return $output; |
| 92 |
} |
| 93 |
|
| 94 |
add_shortcode( 'plugins_number', 'apl_plugin_number_shortcode' ); |
| 95 |
|
| 96 |
/** |
| 97 |
* Get Plugins List |
| 98 |
* |
| 99 |
* Get list of plugins and, optionally, format them |
| 100 |
* |
| 101 |
* @since 1.0 |
| 102 |
* |
| 103 |
* @uses apl_format_plugin_list Format the plugin list |
| 104 |
* @uses apl_get_plugin_data Get the plugin data |
| 105 |
* |
| 106 |
* @param string $format Requires format |
| 107 |
* @param string $show_inactive Whether to format or not |
| 108 |
* @param string $cache Cache time |
| 109 |
* @param string $nofollow Whether to add nofollow to link |
| 110 |
* @param string $target Link target |
| 111 |
* @return string Output |
| 112 |
*/ |
| 113 |
|
| 114 |
function get_plugins_list( $format = '', $show_inactive = false, $cache = 1, $nofollow = false, $target = '' ) { |
| 115 |
|
| 116 |
if ( '' == $format ) { $format = APL_DEFAULT_PLUGIN_FORMAT; } |
| 117 |
|
| 118 |
// Generate NOFOLLOW and TARGET text |
| 119 |
|
| 120 |
if ( $nofollow ) { $nofollow = ' rel="nofollow"'; } else { $nofollow = ''; } |
| 121 |
if ( '' != $target ) { $target = ' target="' . $target . '"'; } else { $target = ''; } |
| 122 |
|
| 123 |
// Get plugin data |
| 124 |
|
| 125 |
$plugins = apl_get_plugin_data( $cache ); |
| 126 |
|
| 127 |
// Extract each plugin and format the output |
| 128 |
|
| 129 |
$output = ''; |
| 130 |
|
| 131 |
foreach( $plugins as $plugin_file => $plugin_data ) { |
| 132 |
|
| 133 |
if ( $show_inactive || is_plugin_active( $plugin_file ) ) { |
| 134 |
$output .= apl_format_plugin_list( $plugin_data, $format, $nofollow, $target ); |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
// Return the code, with HTML comments |
| 139 |
|
| 140 |
return "\n<!-- Plugins List v" . plugins_list_version . " -->\n" . $output . "\n<!-- End of Plugins List -->\n"; |
| 141 |
|
| 142 |
} |
| 143 |
|
| 144 |
/** |
| 145 |
* Get Plugin number |
| 146 |
* |
| 147 |
* Get number of plugins |
| 148 |
* |
| 149 |
* @since 2.2 |
| 150 |
* |
| 151 |
* @uses apl_get_plugin_data Get the plugin data |
| 152 |
* |
| 153 |
* @param string $show_inactive Whether to include inactive plugins or not |
| 154 |
* @param string $cache Cache time |
| 155 |
* @return string Plugin number |
| 156 |
*/ |
| 157 |
|
| 158 |
function get_plugin_number( $show_inactive = false, $cache = 1 ) { |
| 159 |
|
| 160 |
// Get plugin data |
| 161 |
|
| 162 |
$plugins = apl_get_plugin_data( $cache ); |
| 163 |
|
| 164 |
// Get count |
| 165 |
|
| 166 |
if ( $show_inactive ) { |
| 167 |
$output = count( $plugins ); |
| 168 |
} else { |
| 169 |
$output = 0; |
| 170 |
foreach( $plugins as $plugin_file => $plugin_data ) { |
| 171 |
if ( is_plugin_active( $plugin_file ) ) { $output++; } |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
return $output; |
| 176 |
} |
| 177 |
|
| 178 |
/** |
| 179 |
* Get Plugins data |
| 180 |
* |
| 181 |
* Get plugin data and cache it |
| 182 |
* |
| 183 |
* @since 2.2 |
| 184 |
* |
| 185 |
* @uses apl_format_plugin_list Format the plugin list |
| 186 |
* |
| 187 |
* @param string $cache Cache time |
| 188 |
* @return string Plugin data |
| 189 |
*/ |
| 190 |
|
| 191 |
function apl_get_plugin_data( $cache ) { |
| 192 |
|
| 193 |
// Attempt to get plugin list from cache |
| 194 |
|
| 195 |
if ( !$cache ) { $cache = 'no'; } |
| 196 |
|
| 197 |
$plugins = false; |
| 198 |
$cache_key = 'artiss_plugins_list'; |
| 199 |
if ( is_numeric( $cache ) ) { $plugins = get_transient( $cache_key ); } |
| 200 |
|
| 201 |
// If not using cache, generate a new list and cache that |
| 202 |
|
| 203 |
if ( !$plugins ) { |
| 204 |
$plugins = get_plugins(); |
| 205 |
if ( ( '' != $plugins ) && ( is_numeric( $cache ) ) ) { set_transient( $cache_key, $plugins, 3600 * $cache ); } |
| 206 |
} |
| 207 |
|
| 208 |
return $plugins; |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* Format Plugin List |
| 213 |
* |
| 214 |
* Format the plugin list |
| 215 |
* |
| 216 |
* @since 1.0 |
| 217 |
* |
| 218 |
* @uses apl_replace_tags Replace the tags |
| 219 |
* |
| 220 |
* @param string $plugin_data The plugin list |
| 221 |
* @param string $format Format to use |
| 222 |
* @param string $nofollow Nofollow text |
| 223 |
* @param string $target Target text |
| 224 |
* @return string Output |
| 225 |
*/ |
| 226 |
|
| 227 |
function apl_format_plugin_list( $plugin_data, $format, $nofollow, $target ) { |
| 228 |
|
| 229 |
// Allowed tag |
| 230 |
|
| 231 |
$plugins_allowedtags1 = array( 'a' => array( 'href' => array(), 'title' => array() ), 'abbr' => array( 'title' => array() ), 'acronym' => array( 'title' => array() ), 'code' => array(), 'em' => array(), 'strong' => array() ); |
| 232 |
|
| 233 |
$plugins_allowedtags2 = array( 'abbr' => array( 'title' => array() ), 'acronym' => array( 'title' => array() ), 'code' => array(), 'em' => array(), 'strong' => array() ); |
| 234 |
|
| 235 |
// Sanitize all displayed data |
| 236 |
|
| 237 |
$plugin_data[ 'Title' ] = wp_kses( $plugin_data[ 'Title' ], $plugins_allowedtags1 ); |
| 238 |
$plugin_data[ 'PluginURI' ] = wp_kses( $plugin_data[ 'PluginURI' ], $plugins_allowedtags1 ); |
| 239 |
$plugin_data[ 'AuthorURI' ] = wp_kses( $plugin_data[ 'AuthorURI' ], $plugins_allowedtags1 ); |
| 240 |
$plugin_data[ 'Version' ] = wp_kses( $plugin_data[ 'Version' ], $plugins_allowedtags1 ); |
| 241 |
$plugin_data[ 'Author' ] = wp_kses( $plugin_data[ 'Author' ], $plugins_allowedtags1 ); |
| 242 |
|
| 243 |
// Replace the tags |
| 244 |
|
| 245 |
$format = apl_replace_tags( $plugin_data, $format, $nofollow, $target ); |
| 246 |
|
| 247 |
return $format; |
| 248 |
} |
| 249 |
|
| 250 |
/** |
| 251 |
* Replace tags |
| 252 |
* |
| 253 |
* Replace the tags in the provided format |
| 254 |
* |
| 255 |
* @since 2.1 |
| 256 |
* |
| 257 |
* @param string $plugin_data The plugin list |
| 258 |
* @param string $format Format to use |
| 259 |
* @param string $nofollow Nofollow text |
| 260 |
* @param string $target Target text |
| 261 |
* @return string Output |
| 262 |
*/ |
| 263 |
|
| 264 |
function apl_replace_tags( $plugin_data, $format, $nofollow, $target ) { |
| 265 |
|
| 266 |
$format = strtr( $format, array( '{' => '<', '}' => '>' ) ); |
| 267 |
|
| 268 |
$format = strtr ( $format, |
| 269 |
array( |
| 270 |
'#Title#' => $plugin_data[ 'Title' ], |
| 271 |
'#PluginURI#' => $plugin_data[ 'PluginURI' ], |
| 272 |
'#AuthorURI#' => $plugin_data[ 'AuthorURI' ], |
| 273 |
'#Version#' => $plugin_data[ 'Version' ], |
| 274 |
'#Description#' => $plugin_data[ 'Description' ], |
| 275 |
'#Author#' => $plugin_data[ 'Author' ], |
| 276 |
'#LinkedTitle#' => "<a href='" . $plugin_data[ 'PluginURI' ] . "' title='" . $plugin_data[ 'Title' ] . "'" . $nofollow . $target . ">" . $plugin_data[ 'Title' ] . "</a>", |
| 277 |
'#LinkedAuthor#' => "<a href='" . $plugin_data[ 'AuthorURI' ] . "' title='" . $plugin_data[ 'Author' ] . "'" . $nofollow . $target . ">" . $plugin_data[ 'Author' ] . "</a>", |
| 278 |
) ); |
| 279 |
|
| 280 |
return $format; |
| 281 |
} |
| 282 |
?> |
| 283 |
|