Created
May 20, 2018 22:23
-
-
Save BrookeDot/39d22d713717a19998786d3cc999b7f4 to your computer and use it in GitHub Desktop.
Update WP Plugin data plugin to use new Plugin URL
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
Index: trunk/fergcorp_wp-plugin-data.php | |
=================================================================== | |
--- trunk/fergcorp_wp-plugin-data.php (revision 1878124) | |
+++ trunk/fergcorp_wp-plugin-data.php (working copy) | |
@@ -26,6 +26,9 @@ | |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
*/ | |
+if ( ! defined( 'ABSPATH' ) ) { | |
+ exit; // Exit if accessed directly | |
+ } | |
/** | |
* Returns the data for a specific plugin | |
@@ -36,12 +39,12 @@ | |
* @author Andrew Ferguson | |
* @return Object Plugin Object | |
*/ | |
-function fergcorp_wppd_getPluginData($slug){ | |
+function fergcorp_wppd_getPluginData( $slug ){ | |
require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); | |
- | |
+ | |
$slug = sanitize_title( $slug ); | |
$plugin = plugins_api( 'plugin_information', array( 'slug' => $slug ) ); | |
- | |
+ | |
return $plugin; | |
} | |
@@ -56,9 +59,9 @@ | |
* @author Andrew Ferguson | |
* @return string Requested data of a particular plugin | |
*/ | |
-function fergcorp_wppd_getInfo($slug, $param, $content = NULL){ | |
+function fergcorp_wppd_getInfo( $slug, $param, $content = NULL ){ | |
- $plugin = fergcorp_wppd_checkPlugin($slug); | |
+ $plugin = fergcorp_wppd_checkPlugin( $slug ); | |
$info = array(); | |
$attributes = array( | |
'name' => 'name', | |
@@ -80,17 +83,17 @@ | |
'homepage_url' => 'homepage', | |
'tags' => 'tags' | |
); | |
- | |
+ | |
foreach ( $attributes as $name => $key ) { | |
- | |
- if(is_array($key)){ | |
+ | |
+ if( is_array( $key ) ){ | |
$_key = $plugin->$key[0]; | |
$info[$name] = $_key[$key[1]]; | |
}else{ | |
$info[$name] = $plugin->$key; | |
} | |
- | |
- if(is_array($info[$name])){ | |
+ | |
+ if( is_array( $info[$name] ) ){ | |
$info[$name] = implode( ', ', $info[$name] ); | |
} | |
} | |
@@ -97,7 +100,7 @@ | |
$info['downloaded'] = number_format( $info['downloaded_raw'] ); | |
$info['rating'] = ceil( 0.05 * $info['rating_raw'] ); | |
- $info['link_url'] = "http://wordpress.org/extend/plugins/{$info['slug']}/"; | |
+ $info['link_url'] = "https://wordpress.org/plugins/{$info['slug']}/"; | |
$info['last_updated'] = date( get_option('date_format'), strtotime( $info['last_updated_raw'] ) ); | |
$info['last_updated_ago'] = sprintf( __('%s ago'), human_time_diff( strtotime( $info['last_updated_raw'] ) ) ); | |
$info['download'] = '<a href="' . $info['download_url'] . '">' . $content . '</a>'; | |
@@ -112,10 +115,10 @@ | |
$info['author_name'] = $matches[1]; | |
else | |
$info['author_name'] = $info['author']; | |
- | |
+ | |
return $info[$param]; | |
- | |
+ | |
} | |
/** | |
@@ -128,19 +131,17 @@ | |
* @author Andrew Ferguson | |
* @return string The result of fergcorp_wppd_getInfo | |
*/ | |
-function fergcorp_wppd_shortcode($atts, $content=NULL) { | |
+function fergcorp_wppd_shortcode( $atts, $content=NULL ) { | |
extract(shortcode_atts(array( | |
0 => 'countdown-timer', | |
1 => 'name', | |
), $atts)); | |
- | |
- $content = do_shortcode($content); | |
- | |
- return fergcorp_wppd_getInfo($atts[0], $atts[1], $content); | |
+ | |
+ return fergcorp_wppd_getInfo( $atts[0], $atts[1], $content ); | |
} | |
-add_shortcode('wppd', 'fergcorp_wppd_shortcode'); | |
-add_shortcode('wppdlink', 'fergcorp_wppd_shortcode'); | |
+add_shortcode( 'wppd', 'fergcorp_wppd_shortcode' ); | |
+add_shortcode( 'wppdlink', 'fergcorp_wppd_shortcode' ); | |
/** | |
@@ -152,35 +153,35 @@ | |
* @author Andrew Ferguson | |
* @return Object Plugin Object | |
*/ | |
-function fergcorp_wppd_checkPlugin($slug){ | |
+function fergcorp_wppd_checkPlugin( $slug ) { | |
- $fergcorp_wppd_cache = get_option('fergcorp_wppd_cache'); | |
+ $fergcorp_wppd_cache = get_option( 'fergcorp_wppd_cache' ); | |
+ | |
//If the cache is not found | |
- if(!$fergcorp_wppd_cache){ | |
+ if( ! $fergcorp_wppd_cache ){ | |
$fergcorp_wppd_cache = array(); | |
- $fergcorp_wppd_cache[$slug] = fergcorp_wppd_getPluginData($slug); | |
+ $fergcorp_wppd_cache[$slug] = fergcorp_wppd_getPluginData( $slug ); | |
$fergcorp_wppd_cache[$slug.'-fetchTime'] = time(); | |
- update_option('fergcorp_wppd_cache', $fergcorp_wppd_cache); | |
+ update_option( 'fergcorp_wppd_cache', $fergcorp_wppd_cache ); | |
return $fergcorp_wppd_cache[$slug]; | |
} | |
//If the cache is found, and the slug exists in the cache | |
- elseif(array_key_exists($slug, $fergcorp_wppd_cache)){ | |
+ elseif( array_key_exists( $slug, $fergcorp_wppd_cache) ){ | |
//If the slug in the cache is over 3600 seconds (1 hour) old, get a new copy. | |
- if($fergcorp_wppd_cache[$slug.'-fetchTime'] < (time()-3600)){ | |
- $fergcorp_wppd_cache[$slug] = fergcorp_wppd_getPluginData($slug); | |
+ if( $fergcorp_wppd_cache[$slug.'-fetchTime'] < ( time()-3600 ) ){ | |
+ $fergcorp_wppd_cache[$slug] = fergcorp_wppd_getPluginData( $slug ); | |
$fergcorp_wppd_cache[$slug.'-fetchTime'] = time(); | |
- update_option('fergcorp_wppd_cache', $fergcorp_wppd_cache); | |
+ update_option( 'fergcorp_wppd_cache', $fergcorp_wppd_cache ); | |
return $fergcorp_wppd_cache[$slug]; | |
- } | |
+ } | |
return $fergcorp_wppd_cache[$slug]; | |
} | |
//If the cache is found, but the slug was not in the cache | |
else{ | |
- $fergcorp_wppd_cache[$slug] = fergcorp_wppd_getPluginData($slug); | |
+ $fergcorp_wppd_cache[$slug] = fergcorp_wppd_getPluginData( $slug ); | |
$fergcorp_wppd_cache[$slug.'-fetchTime'] = time(); | |
- update_option('fergcorp_wppd_cache', $fergcorp_wppd_cache); | |
+ update_option( 'fergcorp_wppd_cache', $fergcorp_wppd_cache ); | |
return $fergcorp_wppd_cache[$slug]; | |
} | |
} | |
-?> | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment