title = __("Update plugin","dagsopt");
$this->pluginname = $ns->pluginname;
$this->file = $ns->file;
$this->ns = $ns;
$this->status="";
$this->possible=false;
}
function start(){
register_activation_hook ( plugin_basename($this->file), array ( &$this, 'activatePlugin' ) );
register_deactivation_hook ( plugin_basename($this->file), array ( &$this, 'deactivatePlugin' ) );
add_action($this->pluginname.'UpdateCheck', array(&$this,'check_update'));
add_filter( 'http_request_args', array(&$this,'updates_exclude'), 5, 2 );
if(isset($_REQUEST["checkforupdates"])){
$this->check_update();
}
}
function activatePlugin() {
wp_schedule_event(time(), 'hourly', $this->pluginname.'UpdateCheck' );
}
function deactivatePlugin() {
wp_clear_scheduled_hook ( $this->pluginname.'UpdateCheck');
}
/*SELF UPDATE*/
function check_update() {
global $wp_version;
$plugin_folder = plugin_basename( dirname( $this->file ) );
$plugin_file = basename( ( $this->file ) );
if ( defined( 'WP_INSTALLING' ) ) return false;
$response = wp_remote_get( $this->ns->update_check_url );
list($version, $url) = explode('|', $response['body']);
$version = trim($version);
$urlx = "https://git.tum.dk/tum.dk/dagsplug/archive/".$version.".zip";
$this->status = 'Remote version: '.$version." URL: ".$url."::: ".$urlx.":::";
$this->possible = false;
if($this->plugin_get("Version") == $version) return false;
$this->possible = true;
$plugin_transient = get_site_transient('update_plugins');
$a = array(
'slug' => $plugin_folder,
'new_version' => $version,
'url' => $this->plugin_get("AuthorURI"),
'package' => $urlx
);
$o = (object) $a;
$plugin_transient->response[$plugin_folder.'/'.$plugin_file] = $o;
set_site_transient('update_plugins', $plugin_transient);
}
function updates_exclude( $r, $url ) {
if ( 0 !== strpos( $url, 'http://api.wordpress.org/plugins/update-check' ) )
return $r; // Not a plugin update request. Bail immediately.
$plugins = unserialize( $r['body']['plugins'] );
unset( $plugins->plugins[ plugin_basename( $this->file ) ] );
unset( $plugins->active[ array_search( plugin_basename( $this->file ), $plugins->active ) ] );
$r['body']['plugins'] = serialize( $plugins );
return $r;
}
function plugin_get($i) {
if ( ! function_exists( 'get_plugins' ) )
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
$plugin_folder = get_plugins( '/' . plugin_basename( dirname( $this->file ) ) );
$plugin_file = basename( ( $this->file ) );
return $plugin_folder[$plugin_file][$i];
}
function admin_line(){
?>
status); ?>
possible) {
$url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $this->ns->filename), 'upgrade-plugin_' .$this->ns->filename);
echo(''.__("Update","dagsopt").'');
}
?>
dagsopt['plug_update_plugin'] = $plug_update_plugin;
}