Created
June 19, 2012 20:00
Display the last updated date for all plugins from the WordPress.org plugins repo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Plugin Last Updated | |
Version: 1.0 | |
License: GPL | |
Author: Pete Mall, Range | |
Author URI: http://petemall.com/ | |
Description: Display the last updated date for all plugins from the <a href="http://wordpress.org/extend/plugins/">WordPress.org plugins repo</a>. | |
*/ | |
add_filter( 'plugin_row_meta', 'range_plu_plugin_meta', 10, 2 ); | |
function range_plu_plugin_meta( $plugin_meta, $plugin_file ) { | |
list( $slug ) = explode( '/', $plugin_file ); | |
$last_updated = get_transient( "range_plug_{$slug}_last_updated" ); | |
if ( false === $last_updated ) { | |
$last_updated = range_plu_get_last_updated( $slug ); | |
set_transient( "range_plug_{$slug}_last_updated", $last_updated, 86400 ); | |
} | |
if ( $last_updated ) | |
$plugin_meta['last_updated'] = 'Last Updated: ' . esc_html( $last_updated ); | |
return $plugin_meta; | |
} | |
function range_plu_get_last_updated( $slug ) { | |
$request = wp_remote_post( | |
'http://api.wordpress.org/plugins/info/1.0/', | |
array( | |
'body' => array( | |
'action' => 'plugin_information', | |
'request' => serialize( | |
(object) array( | |
'slug' => $slug, | |
'fields' => array( 'last_updated' => true ) | |
) | |
) | |
) | |
) | |
); | |
if ( 200 != wp_remote_retrieve_response_code( $request ) ) | |
return false; | |
$response = unserialize( wp_remote_retrieve_body( $request ) ); | |
if ( isset( $response->last_updated ) ) | |
return sanitize_text_field( $response->last_updated ); | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment