
With this shortcode, getting information about plugins of an author, is easy. To add this shortcode, and make it theme independent, we'll use a small plugin. First, create a PHP file fpw-shortcodes.php
(it can have a different name, if it does not conflict with anything), with the following content:
if(!is_admin()) {
function fpwPluginsInfo($atts) {
$a = shortcode_atts(array(
'author' => 'frankpw',
'expire' => 5,
), $atts);
$cache = get_transient(md5('fpw'.serialize($atts)));
if($cache)
return $cache;
$options = array(
'timeout' => 15,
'body' => array(
'action' => 'query_plugins',
'request' => array(
'author' => $a['author'],
'fields' => array(
'banners',
'icons',
)
)
)
);
$response = wp_remote_post('https://api.wordpress.org/plugins/info/1.1/', $options);
$display = '';
if (!is_wp_error($response)) {
$display .= "<h2 class=\"byAuthor\">by {$a['author']}</h2>";
$plugins = json_decode($response['body'])->plugins;
$totalDownloads = 0;
$found = false;
foreach($plugins as $plugin) {
$found = true;
$plugin->icons = (array)$plugin->icons;
$display .= '<div class="flexContainer">';
$display .= '<div class="columnLeft">';
$display .= "<img src=\"{$plugin->icons[ '1x' ]}\" width=\"96\" class=\"pluginIcon\">";
$display .= '</div>';
$display .= '<div class="columnMiddle">';
$display .= "<h3 style=\"margin-bottom: 5px; padding-top: 20px;\">{$plugin->name} ({$plugin->version})</h3>";
$display .= "by {$plugin->author}";
$display .= '</div>';
$display .= '<div class="columnRight">';
$display .= "<a class=\"button\" href=\"{$plugin->download_link}\">Download</a>";
$display .= '</div>';
$display .= '</div>';
$profile = substr( $plugin->author_profile, strrpos( $plugin->author_profile, '/' ) + 1 );
$display .= '<div class="flexContainer">';
$display .= '<div class="columnLeft">';
$display .= "Author's Profile: <a href=\"{$plugin->author_profile}\">{$profile}</a><br>";
$totalDownloads += $plugin->downloaded;
$display .= 'Downloaded: ' . number_format( $plugin->downloaded );
$display .= '</div>';
$display .= '<div class="columnMiddle">';
$display .= "Added: {$plugin->added}<br>";
$display .= "Updated: {$plugin->last_updated}";
$display .= '</div>';
$display .= '<div class="columnRight">';
$display .= " ";
$display .= '</div>';
$display .= '</div>';
$display .= '<hr>';
}
if(!$found) {
$display .= "No plugins for author '<em>{$a['author']}</em>'";
} else {
$display .= "Total downloads: " . number_format($totalDownloads);
}
} else {
$errorCodes = $response->get_error_codes();
foreach($errorCodes as $code) {
$errorMessage = $response->get_error_message($code);
$display .= "Error : <strong>{$code}</strong> : <em>{$errorMessage}</em><br>";
}
}
$display .= '<hr>';
set_transient(md5('fpw'.serialize($atts)), $display, $a['expire'] * 60);
return $display;
}
add_shortcode('fpw_plugins_info', 'fpwPluginsInfo');
function fpw_hook_css() {
?><style>
.flexContainer {
display:flex;
}
.columnLeft,
.columnRight {
flex:2;
}
.columnRight {
text-align:right;
}
.columnMiddle {
flex:3;
}
.columnLeft,
.columnMiddle,
.columnright {
line-height: 1.714285714;
}
.button {
background-color:darkcyan;
border: none;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 20px 2px;
cursor: pointer;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
}
a.button {
color:white !important;
}
.button:hover {
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);
}
img.pluginIcon {
padding-bottom:15px;
}
.byAuthor {
margin-bottom: 1em;
}
</style><?php
}
add_action('wp_head', 'fpw_hook_css');
}
Place this file in /wp-content/mu-plugins/
folder. you
can use it, in your posts/pages, by inserting [fpw-plugins-info author="...author's slug in wordpress.org..." expire="10"]
. Both parameters are optional, and will default to - frankpw
, and 5
, respectively. The expire
parameter defines cache expiration in minutes.
Example
by frankpw
Total downloads: 44,704
If you’re plugins developer, and you want to see info about your plugins, by default, you can change line 005 of the code, replacing ‘frankpw’ with your author’s slug.