Last active
June 1, 2016 15:32
-
-
Save elhardoum/153249b988906cfb0c690873d5696df3 to your computer and use it in GitHub Desktop.
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 | |
add_action('admin_init', function() { | |
// Specify here the plugin name and that's all | |
$requested_name = 'AJAX File Upload'; | |
function se_plugin_has_update( $name ) { | |
if ( ! function_exists( 'get_plugin_updates' ) ) { | |
require_once ABSPATH . 'wp-admin/includes/update.php'; | |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
} | |
$list = get_plugin_updates(); | |
$data = array(); | |
foreach( $list as $i => $item ) { | |
if( strtolower( $name ) == strtolower( $item->Name ) ) { | |
$data = $list[$i]; | |
} | |
} | |
if( ! empty( $data ) ) { | |
$data = array( | |
'name' => $data->Name, | |
'version' => $data->Version, | |
'new_version' => $data->update->new_version, | |
'url' => $data->update->url, | |
'package' => $data->update->package | |
); | |
} else { | |
$data = array(); | |
} | |
return $data; | |
} | |
$update_data = se_plugin_has_update( $requested_name ); | |
// var_dump( $update_data ) or print_r( $update_data ) for debugging | |
if( ! empty( $update_data ) ) { // has update avail | |
// You can avoid for specific versions (current: $update_data['version'] and latest: $update_data['new_version']) | |
$GLOBALS['se_plugin_has_update_data'] = $update_data; | |
add_action( 'admin_notices', function() { | |
global $se_plugin_has_update_data; | |
$update_data = $se_plugin_has_update_data; | |
?> | |
<div id="updated" class="error notice is-dismissible"> | |
<p><?php echo sprintf( | |
"\"%s\" plugin has updates available. You are running v. %s while the latest version is %s", | |
$update_data['name'], | |
$update_data['version'], | |
$update_data['new_version'] | |
); ?></p> | |
</div> | |
<?php | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment