Skip to content

Instantly share code, notes, and snippets.

@wvega
Created August 9, 2014 18:01
Show Gist options
  • Save wvega/cf5668af5f03ec3060ba to your computer and use it in GitHub Desktop.
Save wvega/cf5668af5f03ec3060ba to your computer and use it in GitHub Desktop.
Updated function pre_set_site_transient_update_plugins_filter for EDD_SL_Plugin_Updater 1.2
<?php
/**
* Check for Updates at the defined API endpoint and modify the update array.
*
* This function dives into the update API just when WordPress creates its update array,
* then adds a custom API call and injects the custom plugin data retrieved from the API.
* It is reassembled from parts of the native WordPress plugin update code.
* See wp-includes/update.php line 121 for the original wp_update_plugins() function.
*
* @uses api_request()
*
* @param array $_transient_data Update array build by WordPress.
* @return array Modified update array with custom plugin data.
*/
function pre_set_site_transient_update_plugins_filter( $_transient_data ) {
static $api_response = null;
if( empty( $_transient_data ) ) {
return $_transient_data;
}
if ( is_null( $api_response ) || $api_response === false || is_wp_error( $api_response ) ) {
$to_send = array( 'slug' => $this->slug );
$api_response = $this->api_request( 'plugin_latest_version', $to_send );
}
if( false !== $api_response && is_object( $api_response ) && isset( $api_response->new_version ) ) {
if( version_compare( $this->version, $api_response->new_version, '<' ) ) {
$_transient_data->response[$this->name] = $api_response;
}
}
return $_transient_data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment