/** * Remove a theme * * @since 2.8.0 * * @param string $template Template directory of the theme to delete * @param string $redirect Redirect to page when complete. * @return mixed */ function delete_theme($template, $redirect = '') { global $nxt_filesystem; if (empty($template)) { return false; } ob_start(); if (empty($redirect)) { $redirect = nxt_nonce_url('themes.php?action=delete&template=' . $template, 'delete-theme_' . $template); } if (false === ($credentials = request_filesystem_credentials($redirect))) { $data = ob_get_contents(); ob_end_clean(); if (!empty($data)) { include_once ABSPATH . 'nxt-admin/admin-header.php'; echo $data; include ABSPATH . 'nxt-admin/admin-footer.php'; exit; } return; } if (!nxt_Filesystem($credentials)) { request_filesystem_credentials($url, '', true); // Failed to connect, Error and request again $data = ob_get_contents(); ob_end_clean(); if (!empty($data)) { include_once ABSPATH . 'nxt-admin/admin-header.php'; echo $data; include ABSPATH . 'nxt-admin/admin-footer.php'; exit; } return; } if (!is_object($nxt_filesystem)) { return new nxt_Error('fs_unavailable', __('Could not access filesystem.')); } if (is_nxt_error($nxt_filesystem->errors) && $nxt_filesystem->errors->get_error_code()) { return new nxt_Error('fs_error', __('Filesystem error.'), $nxt_filesystem->errors); } //Get the base plugin folder $themes_dir = $nxt_filesystem->nxt_themes_dir(); if (empty($themes_dir)) { return new nxt_Error('fs_no_themes_dir', __('Unable to locate NXTClass theme directory.')); } $themes_dir = trailingslashit($themes_dir); $theme_dir = trailingslashit($themes_dir . $template); $deleted = $nxt_filesystem->delete($theme_dir, true); if (!$deleted) { return new nxt_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s.'), $template)); } // Force refresh of theme update information delete_site_transient('update_themes'); return true; }
function fs_connect($directories = array()) { global $nxt_filesystem; if (false === ($credentials = $this->skin->request_filesystem_credentials())) { return false; } if (!nxt_Filesystem($credentials)) { $error = true; if (is_object($nxt_filesystem) && $nxt_filesystem->errors->get_error_code()) { $error = $nxt_filesystem->errors; } $this->skin->request_filesystem_credentials($error); //Failed to connect, Error and request again return false; } if (!is_object($nxt_filesystem)) { return new nxt_Error('fs_unavailable', $this->strings['fs_unavailable']); } if (is_nxt_error($nxt_filesystem->errors) && $nxt_filesystem->errors->get_error_code()) { return new nxt_Error('fs_error', $this->strings['fs_error'], $nxt_filesystem->errors); } foreach ((array) $directories as $dir) { switch ($dir) { case ABSPATH: if (!$nxt_filesystem->abspath()) { return new nxt_Error('fs_no_root_dir', $this->strings['fs_no_root_dir']); } break; case nxt_CONTENT_DIR: if (!$nxt_filesystem->nxt_content_dir()) { return new nxt_Error('fs_no_content_dir', $this->strings['fs_no_content_dir']); } break; case nxt_PLUGIN_DIR: if (!$nxt_filesystem->nxt_plugins_dir()) { return new nxt_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']); } break; case nxt_CONTENT_DIR . '/themes': if (!$nxt_filesystem->find_folder(nxt_CONTENT_DIR . '/themes')) { return new nxt_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']); } break; default: if (!$nxt_filesystem->find_folder($dir)) { return new nxt_Error('fs_no_folder', sprintf($this->strings['fs_no_folder'], $dir)); } break; } } return true; }
/** * Upgrade NXTClass core display. * * @since 2.7 * * @return null */ function do_core_upgrade($reinstall = false) { global $nxt_filesystem; if ($reinstall) { $url = 'update-core.php?action=do-core-reinstall'; } else { $url = 'update-core.php?action=do-core-upgrade'; } $url = nxt_nonce_url($url, 'upgrade-core'); if (false === ($credentials = request_filesystem_credentials($url, '', false, ABSPATH))) { return; } $version = isset($_POST['version']) ? $_POST['version'] : false; $locale = isset($_POST['locale']) ? $_POST['locale'] : 'en_US'; $update = find_core_update($version, $locale); if (!$update) { return; } if (!nxt_Filesystem($credentials, ABSPATH)) { request_filesystem_credentials($url, '', true, ABSPATH); //Failed to connect, Error and request again return; } ?> <div class="wrap"> <?php screen_icon('tools'); ?> <h2><?php _e('Update NXTClass'); ?> </h2> <?php if ($nxt_filesystem->errors->get_error_code()) { foreach ($nxt_filesystem->errors->get_error_messages() as $message) { show_message($message); } echo '</div>'; return; } if ($reinstall) { $update->response = 'reinstall'; } $result = nxt_update_core($update, 'show_message'); if (is_nxt_error($result)) { show_message($result); if ('up_to_date' != $result->get_error_code()) { show_message(__('Installation Failed')); } echo '</div>'; return; } show_message(__('NXTClass updated successfully')); show_message('<span class="hide-if-no-js">' . sprintf(__('Welcome to NXTClass %1$s. You will be redirected to the About NXTClass screen. If not, click <a href="%s">here</a>.'), $result, esc_url(admin_url('about.php?updated'))) . '</span>'); show_message('<span class="hide-if-js">' . sprintf(__('Welcome to NXTClass %1$s. <a href="%2$s">Learn more</a>.'), $result, esc_url(admin_url('about.php?updated'))) . '</span>'); ?> </div> <script type="text/javascript"> window.location = '<?php echo admin_url('about.php?upgraded'); ?> '; </script> <?php }
function woothemes_framework_update_head() { if (isset($_REQUEST['page'])) { // Sanitize page being requested. $_page = strtolower(strip_tags(trim($_REQUEST['page']))); if ($_page == 'woothemes_framework_update') { //Setup Filesystem $method = get_filesystem_method(); if (isset($_POST['woo_ftp_cred'])) { $cred = unserialize($_POST['woo_ftp_cred']); $filesystem = nxt_Filesystem($cred); } else { $filesystem = nxt_Filesystem(); } if ($filesystem == false && $_POST['upgrade'] != 'Proceed') { function woothemes_framework_update_filesystem_warning() { $method = get_filesystem_method(); echo "<div id='filesystem-warning' class='updated fade'><p>Failed: Filesystem preventing downloads. ( " . $method . ")</p></div>"; } add_action('admin_notices', 'woothemes_framework_update_filesystem_warning'); return; } if (isset($_REQUEST['woo_update_save'])) { // Sanitize action being requested. $_action = strtolower(trim(strip_tags($_REQUEST['woo_update_save']))); if ($_action == 'save') { $temp_file_addr = download_url('http://www.woothemes.com/updates/framework.zip'); if (is_nxt_error($temp_file_addr)) { $error = $temp_file_addr->get_error_code(); if ($error == 'http_no_url') { //The source file was not found or is invalid function woothemes_framework_update_missing_source_warning() { echo "<div id='source-warning' class='updated fade'><p>Failed: Invalid URL Provided</p></div>"; } add_action('admin_notices', 'woothemes_framework_update_missing_source_warning'); } else { function woothemes_framework_update_other_upload_warning() { echo "<div id='source-warning' class='updated fade'><p>Failed: Upload - {$error}</p></div>"; } add_action('admin_notices', 'woothemes_framework_update_other_upload_warning'); } return; } //Unzip it global $nxt_filesystem; $to = $nxt_filesystem->nxt_content_dir() . "/themes/" . get_option('template') . "/functions/"; $dounzip = unzip_file($temp_file_addr, $to); unlink($temp_file_addr); // Delete Temp File if (is_nxt_error($dounzip)) { //DEBUG $error = $dounzip->get_error_code(); $data = $dounzip->get_error_data($error); //echo $error. ' - '; //print_r($data); if ($error == 'incompatible_archive') { //The source file was not found or is invalid function woothemes_framework_update_no_archive_warning() { echo "<div id='woo-no-archive-warning' class='updated fade'><p>Failed: Incompatible archive</p></div>"; } add_action('admin_notices', 'woothemes_framework_update_no_archive_warning'); } if ($error == 'empty_archive') { function woothemes_framework_update_empty_archive_warning() { echo "<div id='woo-empty-archive-warning' class='updated fade'><p>Failed: Empty Archive</p></div>"; } add_action('admin_notices', 'woothemes_framework_update_empty_archive_warning'); } if ($error == 'mkdir_failed') { function woothemes_framework_update_mkdir_warning() { echo "<div id='woo-mkdir-warning' class='updated fade'><p>Failed: mkdir Failure</p></div>"; } add_action('admin_notices', 'woothemes_framework_update_mkdir_warning'); } if ($error == 'copy_failed') { function woothemes_framework_update_copy_fail_warning() { echo "<div id='woo-copy-fail-warning' class='updated fade'><p>Failed: Copy Failed</p></div>"; } add_action('admin_notices', 'woothemes_framework_update_copy_fail_warning'); } return; } function woothemes_framework_updated_success() { echo "<div id='framework-upgraded' class='updated fade'><p>New framework successfully downloaded, extracted and updated.</p></div>"; } add_action('admin_notices', 'woothemes_framework_updated_success'); } } } //End user input save part of the update } }
/** * Remove directory and files of a plugin for a single or list of plugin(s). * * If the plugins parameter list is empty, false will be returned. True when * completed. * * @since 2.6.0 * * @param array $plugins List of plugin * @param string $redirect Redirect to page when complete. * @return mixed */ function delete_plugins($plugins, $redirect = '') { global $nxt_filesystem; if (empty($plugins)) { return false; } $checked = array(); foreach ($plugins as $plugin) { $checked[] = 'checked[]=' . $plugin; } ob_start(); $url = nxt_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-plugins'); if (false === ($credentials = request_filesystem_credentials($url))) { $data = ob_get_contents(); ob_end_clean(); if (!empty($data)) { include_once ABSPATH . 'nxt-admin/admin-header.php'; echo $data; include ABSPATH . 'nxt-admin/admin-footer.php'; exit; } return; } if (!nxt_Filesystem($credentials)) { request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again $data = ob_get_contents(); ob_end_clean(); if (!empty($data)) { include_once ABSPATH . 'nxt-admin/admin-header.php'; echo $data; include ABSPATH . 'nxt-admin/admin-footer.php'; exit; } return; } if (!is_object($nxt_filesystem)) { return new nxt_Error('fs_unavailable', __('Could not access filesystem.')); } if (is_nxt_error($nxt_filesystem->errors) && $nxt_filesystem->errors->get_error_code()) { return new nxt_Error('fs_error', __('Filesystem error.'), $nxt_filesystem->errors); } //Get the base plugin folder $plugins_dir = $nxt_filesystem->nxt_plugins_dir(); if (empty($plugins_dir)) { return new nxt_Error('fs_no_plugins_dir', __('Unable to locate NXTClass Plugin directory.')); } $plugins_dir = trailingslashit($plugins_dir); $errors = array(); foreach ($plugins as $plugin_file) { // Run Uninstall hook if (is_uninstallable_plugin($plugin_file)) { uninstall_plugin($plugin_file); } $this_plugin_dir = trailingslashit(dirname($plugins_dir . $plugin_file)); // If plugin is in its own directory, recursively delete the directory. if (strpos($plugin_file, '/') && $this_plugin_dir != $plugins_dir) { //base check on if plugin includes directory separator AND that its not the root plugin folder $deleted = $nxt_filesystem->delete($this_plugin_dir, true); } else { $deleted = $nxt_filesystem->delete($plugins_dir . $plugin_file); } if (!$deleted) { $errors[] = $plugin_file; } } if (!empty($errors)) { return new nxt_Error('could_not_remove_plugin', sprintf(__('Could not fully remove the plugin(s) %s.'), implode(', ', $errors))); } // Force refresh of plugin update information if ($current = get_site_transient('update_plugins')) { unset($current->response[$plugin_file]); set_site_transient('update_plugins', $current); } return true; }