Shortcode to display plugins info for their author

Featured Image

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 different name, as long as it does not conflict with anything ), with the following content:

<?php
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 .= "&nbsp;";
				$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. Now you can use it, in you 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 xcloner

XCloner – Backup and Restore (4.0.8)

by Liuta Ovidiu
Author's Profile: xcloner
Downloaded: 829,539
Added: 2010-09-28
Updated: 2018-06-25 10:25am GMT
 

XCloner Google Drive (1.0.3)

by Liuta Ovidiu
Author's Profile: xcloner
Downloaded: 9,014
Added: 2017-03-07
Updated: 2018-06-21 11:22am GMT
 

Total downloads: 838,553

One thought on “Shortcode to display plugins info for their author”

  1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *