/** * upgrade function * * @return void **/ function upgrade() { // continue only if user can update plugins if (!current_user_can('update_plugins')) { wp_die(__('You do not have sufficient permissions to update plugins for this site.')); } $package_url = Ai1ec_Meta::get_option('ai1ec_package_url'); $plugin_name = Ai1ec_Meta::get_option('ai1ec_plugin_name'); if (empty($package_url) || empty($plugin_name)) { wp_die(__('Download package is needed and was not supplied. Visit <a href="http://time.ly/" target="_blank">time.ly</a> to download the newest version of the plugin.')); } // use our custom class $upgrader = new Ai1ec_Updater(); // update the plugin $upgrader->upgrade($plugin_name, $package_url); // clear update notification update_option('ai1ec_update_available', 0); update_option('ai1ec_update_message', ''); update_option('ai1ec_package_url', ''); update_option('ai1ec_plugin_name', ''); }
/** * upgrade-to-pro function * * @return void **/ function upgrade_to_pro() { // continue only if user can update plugins if (!current_user_can('update_plugins')) { wp_die(__('You do not have sufficient permissions to update plugins for this site.')); } // include our CA Root certificate // in curl requests to the api add_action('http_api_curl', array(&$this, 'http_api_curl')); $response = wp_remote_get(sprintf(AI1EC_API_VERIFY_LICENSE_KEY, $_REQUEST['ai1ec_license_key'], AI1EC_VERSION)); if (!is_wp_error($response) && isset($response['response']) && isset($response['response']['code']) && $response['response']['code'] == 200 && isset($response['body']) && !empty($response['body'])) { // continue only if there is a result $resp = json_decode($response['body']); if ((bool) $resp->valid === TRUE) { // use our custom class $upgrader = new Ai1ec_Updater(); // update the plugin $upgrader->upgrade($resp->plugin_name, $resp->package_url); } else { $errmsg = __('The license key you entered is not valid. Please try again.', AI1EC_PLUGIN_NAME); } } else { $errmsg = __('A system error has occurred. Please try again.', AI1EC_PLUGIN_NAME); } if (!empty($errmsg)) { global $ai1ec_view_helper; wp_die($ai1ec_view_helper->get_admin_view('admin_notices.php', array('label' => __('All-in-One Event Calendar: Error processing license key', AI1EC_PLUGIN_NAME), 'msg' => '<p>' . $errmsg . '</p>')), '', array('back_link' => true)); } }