function getWPFilesystem() { global $wp_filesystem; if (empty($wp_filesystem)) { ob_start(); // if (file_exists(ABSPATH . '/wp-admin/includes/deprecated.php')) include_once(ABSPATH . '/wp-admin/includes/deprecated.php'); if (file_exists(ABSPATH . '/wp-admin/includes/screen.php')) { include_once ABSPATH . '/wp-admin/includes/screen.php'; } if (file_exists(ABSPATH . '/wp-admin/includes/template.php')) { include_once ABSPATH . '/wp-admin/includes/template.php'; } $creds = request_filesystem_credentials('test', '', false, false, $extra_fields = null); ob_end_clean(); if (empty($creds)) { define('FS_METHOD', 'direct'); } WP_Filesystem($creds); } if (empty($wp_filesystem)) { MainWPHelper::error($this->FTP_ERROR); } else { if (is_wp_error($wp_filesystem->errors)) { $errorCodes = $wp_filesystem->errors->get_error_codes(); if (!empty($errorCodes)) { MainWPHelper::error(__('Wordpress Filesystem error: ', 'mainwp-child') . $wp_filesystem->errors->get_error_message()); } } } return $wp_filesystem; }
/** * Create full backup */ public function createFullBackup($excludes, $filePrefix = '', $addConfig = false, $includeCoreFiles = false, $file_descriptors = 0, $fileSuffix = false, $excludezip = false, $excludenonwp = false, $loadFilesBeforeZip = true, $ext = 'zip', $pid = false, $append = false) { $this->file_descriptors = $file_descriptors; $this->loadFilesBeforeZip = $loadFilesBeforeZip; $dirs = MainWPHelper::getMainWPDir('backup'); $backupdir = $dirs[0]; if (!defined('PCLZIP_TEMPORARY_DIR')) { define('PCLZIP_TEMPORARY_DIR', $backupdir); } if ($pid !== false) { $pid = trailingslashit($backupdir) . 'backup-' . $pid . '.pid'; } //Verify if another backup is running, if so, return an error $files = glob($backupdir . '*.pid'); foreach ($files as $file) { if (basename($file) == basename($pid)) { continue; } if (time() - filemtime($file) < 160) { MainWPHelper::error('Another backup process is running, try again later'); } } $timestamp = time(); if ($filePrefix != '') { $filePrefix .= '-'; } if ($ext == 'zip') { $this->archiver = null; $ext = '.zip'; } else { $this->archiver = new TarArchiver($this, $ext, $pid); $ext = $this->archiver->getExtension(); } // throw new Exception('Test 1 2 : ' . print_r($append,1)); if ($fileSuffix !== false && !empty($fileSuffix)) { $file = $fileSuffix . ($append === true ? '' : $ext); //Append already contains extension! } else { $file = 'backup-' . $filePrefix . $timestamp . $ext; } $filepath = $backupdir . $file; $fileurl = $file; // if (!$append) // { // if ($dh = opendir($backupdir)) // { // while (($file = readdir($dh)) !== false) // { // if ($file != '.' && $file != '..' && preg_match('/(.*).(zip|tar|tar.gz|tar.bz2|pid|done)$/', $file)) // { // @unlink($backupdir . $file); // } // } // closedir($dh); // } // } if (!$addConfig) { if (!in_array(str_replace(ABSPATH, '', WP_CONTENT_DIR), $excludes) && !in_array('wp-admin', $excludes) && !in_array(WPINC, $excludes)) { $addConfig = true; $includeCoreFiles = true; } } $this->timeout = 20 * 60 * 60; /*20 minutes*/ $mem = '512M'; @ini_set('memory_limit', $mem); @set_time_limit($this->timeout); @ini_set('max_execution_time', $this->timeout); if ($this->archiver != null) { $success = $this->archiver->createFullBackup($filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp, $append); } else { if ($this->checkZipSupport()) { $success = $this->createZipFullBackup($filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp); } else { if ($this->checkZipConsole()) { $success = $this->createZipConsoleFullBackup($filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp); } else { $success = $this->createZipPclFullBackup2($filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp); } } } return $success ? array('timestamp' => $timestamp, 'file' => $fileurl, 'filesize' => filesize($filepath)) : false; }