protected function prepare() { include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; try { $this->api = $api = Sputnik::get_plugin($this->id); } catch (Exception $e) { status_header(500); $this->header(); echo '<p>' . $e->getMessage() . '</p>'; $this->footer(); return; } if (!Sputnik::is_purchased($this->api->slug)) { wp_redirect(Sputnik_Admin::build_url(array('buy' => $this->id))); die; } if (!current_user_can('install_plugins')) { wp_die(__('You do not have sufficient permissions to install plugins for this site.', 'sputnik')); } check_admin_referer($this->nonce_prefix . $this->api->slug); include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $title = sprintf($this->title_format, $this->api->name . ' ' . $this->api->version); $nonce = $this->nonce_prefix . $this->id; $url = 'update.php?action=install-plugin&plugin=' . $this->id; if (isset($_GET['from'])) { $url .= '&from=' . urlencode(stripslashes($_GET['from'])); } $type = 'web'; //Install plugin type, From Web or an Upload. if ($this->api->is_theme) { $this->upgrader = new Sputnik_ThemeUpgrader(new Sputnik_View_Install_Skin(compact('title', 'url', 'nonce', 'plugin', 'api'))); } else { $this->upgrader = new Sputnik_Upgrader(new Sputnik_View_Install_Skin(compact('title', 'url', 'nonce', 'plugin', 'api'))); } }
protected static function upgrade($file) { include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; try { $data = Sputnik::get_from_file($file); if ($data === null) { throw new Exception(__('Plugin not found', 'wpsc')); } $id = $data['Sputnik ID']; $api = Sputnik::get_plugin($id); } catch (Exception $e) { status_header(500); iframe_header(__('Update Plugin', 'wpsc')); echo $e->getMessage(); iframe_footer(); die; } if (!Sputnik::is_purchased($id)) { wp_redirect(self::build_url(array('buy' => $id))); die; } if (!current_user_can('install_plugins')) { wp_die(__('You do not have sufficient permissions to install plugins for this site.', 'wpsc')); } include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; check_admin_referer('sputnik_upgrade-plugin_' . $file); global $body_id; $body_id = 'sputnik-upgrade'; iframe_header(__('Update Plugin', 'wpsc')); $title = sprintf(__('Updating Plugin: %s', 'wpsc'), $api->name . ' ' . $api->version); $nonce = 'sputnik_upgrade-plugin_' . $id; $url = 'update.php?action=upgrade-plugin&plugin=' . $id; if (isset($_GET['from'])) { $url .= '&from=' . urlencode(stripslashes($_GET['from'])); } $type = 'web'; //Install plugin type, From Web or an Upload. $plugin = $id; if ($api->is_theme) { $upgrader = new Sputnik_ThemeUpgrader(new Sputnik_Upgrader_Skin(compact('title', 'url', 'nonce', 'plugin', 'api'))); } else { $upgrader = new Sputnik_Upgrader(new Sputnik_Upgrader_Skin(compact('title', 'url', 'nonce', 'plugin', 'api'))); } $upgrader->upgrade($file); iframe_footer(); die; }