Advertisement
websupporter

Hook into the plugin update process of WordPress part I

Jun 3rd, 2015
788
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. function auv_check_for_updates( $transient ){
  2.     if ( empty( $transient->checked ) ) {
  3.             return $transient;
  4.     }
  5.  
  6.     //Get the current version available
  7.     $url = 'http://websupporter.net/current-version.txt';
  8.     $response = wp_remote_get( $url );
  9.     $version = (float) $response['body'];
  10.  
  11.     //Get information about the installed version
  12.     if( ! function_exists( 'get_plugin_data' ) )
  13.         require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
  14.  
  15.     $plugin_data = get_plugin_data( __FILE__, false, false );
  16.  
  17.     //If update is needed
  18.     if( version_compare( $version, $plugin_data['Version'], '>' ) ){
  19.  
  20.         //add our information
  21.         $update_info = array(
  22.             'plugin'        => plugin_basename( __FILE__ ),
  23.             'slug'          => plugin_basename( __FILE__ ),
  24.             'new_version'   => $version,
  25.             'url'           => 'http://websupporter.net/',
  26.             'package'       => 'http://websupporter.net/current-version.zip',
  27.         );     
  28.         $transient->response[ plugin_basename( __FILE__ ) ] = (object) $update_info;
  29.  
  30.     }
  31.     return $transient;
  32. }
  33. add_action( 'pre_set_site_transient_update_plugins', 'auv_check_for_updates' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement