Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp...
File: updraftplus.php
<?php
[0] Fix | Delete
// @codingStandardsIgnoreStart
[1] Fix | Delete
/*
[2] Fix | Delete
Plugin Name: UpdraftPlus - Backup/Restore
[3] Fix | Delete
Plugin URI: https://updraftplus.com
[4] Fix | Delete
Description: Backup and restore: take backups locally, or backup to Amazon S3, Dropbox, Google Drive, Rackspace, (S)FTP, WebDAV & email, on automatic schedules.
[5] Fix | Delete
Author: UpdraftPlus.Com, DavidAnderson
[6] Fix | Delete
Version: 1.22.3
[7] Fix | Delete
Update URI: https://wordpress.org/plugins/updraftplus/
[8] Fix | Delete
Donate link: https://david.dw-perspective.org.uk/donate
[9] Fix | Delete
License: GPLv3 or later
[10] Fix | Delete
Text Domain: updraftplus
[11] Fix | Delete
Domain Path: /languages
[12] Fix | Delete
Author URI: https://updraftplus.com
[13] Fix | Delete
*/
[14] Fix | Delete
// @codingStandardsIgnoreEnd
[15] Fix | Delete
[16] Fix | Delete
/*
[17] Fix | Delete
Portions copyright 2011-22 David Anderson
[18] Fix | Delete
Portions copyright 2010 Paul Kehrer
[19] Fix | Delete
Other portions copyright as indicated by authors in the relevant files
[20] Fix | Delete
[21] Fix | Delete
This program is free software; you can redistribute it and/or modify
[22] Fix | Delete
it under the terms of the GNU General Public License as published by
[23] Fix | Delete
the Free Software Foundation; either version 3 of the License, or
[24] Fix | Delete
(at your option) any later version.
[25] Fix | Delete
[26] Fix | Delete
This program is distributed in the hope that it will be useful,
[27] Fix | Delete
but WITHOUT ANY WARRANTY; without even the implied warranty of
[28] Fix | Delete
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
[29] Fix | Delete
GNU General Public License for more details.
[30] Fix | Delete
[31] Fix | Delete
You should have received a copy of the GNU General Public License
[32] Fix | Delete
along with this program; if not, write to the Free Software
[33] Fix | Delete
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
[34] Fix | Delete
*/
[35] Fix | Delete
[36] Fix | Delete
if (!defined('ABSPATH')) die('No direct access allowed');
[37] Fix | Delete
[38] Fix | Delete
if ((isset($updraftplus) && is_object($updraftplus) && is_a($updraftplus, 'UpdraftPlus')) || function_exists('updraftplus_modify_cron_schedules')) return; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
[39] Fix | Delete
[40] Fix | Delete
define('UPDRAFTPLUS_DIR', dirname(__FILE__));
[41] Fix | Delete
define('UPDRAFTPLUS_URL', plugins_url('', __FILE__));
[42] Fix | Delete
define('UPDRAFT_DEFAULT_OTHERS_EXCLUDE', 'upgrade,cache,updraft,backup*,*backups,mysql.sql,debug.log');
[43] Fix | Delete
define('UPDRAFT_DEFAULT_UPLOADS_EXCLUDE', 'backup*,*backups,backwpup*,wp-clone,snapshots');
[44] Fix | Delete
[45] Fix | Delete
// The following can go in your wp-config.php
[46] Fix | Delete
// Tables whose data can be skipped without significant loss, if (and only if) the attempt to back them up fails (e.g. bwps_log, from WordPress Better Security, is log data; but individual entries can be huge and cause out-of-memory fatal errors on low-resource environments). Comma-separate the table names (without the WordPress table prefix).
[47] Fix | Delete
if (!defined('UPDRAFTPLUS_DATA_OPTIONAL_TABLES')) define('UPDRAFTPLUS_DATA_OPTIONAL_TABLES', 'bwps_log,statpress,slim_stats,redirection_logs,Counterize,Counterize_Referers,Counterize_UserAgents,wbz404_logs,wbz404_redirects,tts_trafficstats,tts_referrer_stats,wponlinebackup_generations,svisitor_stat,simple_feed_stats,itsec_log,relevanssi_log,blc_instances,wysija_email_user_stat,woocommerce_sessions,et_bloom_stats,redirection_404,lbakut_activity_log,stream_meta,wfFileMods,wffilemods,wfBlockedIPLog,wfblockediplog,page_visit_history,strack_st');
[48] Fix | Delete
if (!defined('UPDRAFTPLUS_ZIP_EXECUTABLE')) define('UPDRAFTPLUS_ZIP_EXECUTABLE', "/usr/bin/zip,/bin/zip,/usr/local/bin/zip,/usr/sfw/bin/zip,/usr/xdg4/bin/zip,/opt/bin/zip");
[49] Fix | Delete
if (!defined('UPDRAFTPLUS_MYSQLDUMP_EXECUTABLE')) define('UPDRAFTPLUS_MYSQLDUMP_EXECUTABLE', updraftplus_build_mysqldump_list());
[50] Fix | Delete
// If any individual file size is greater than this, then a warning is given
[51] Fix | Delete
if (!defined('UPDRAFTPLUS_WARN_FILE_SIZE')) define('UPDRAFTPLUS_WARN_FILE_SIZE', 1024*1024*250);
[52] Fix | Delete
// On a test on a Pentium laptop, 100,000 rows needed ~ 1 minute to write out - so 150,000 is around the CPanel default of 90 seconds execution time.
[53] Fix | Delete
if (!defined('UPDRAFTPLUS_WARN_DB_ROWS')) define('UPDRAFTPLUS_WARN_DB_ROWS', 150000);
[54] Fix | Delete
[55] Fix | Delete
// The smallest value (in megabytes) that the "split zip files at" setting is allowed to be set to
[56] Fix | Delete
if (!defined('UPDRAFTPLUS_SPLIT_MIN')) define('UPDRAFTPLUS_SPLIT_MIN', 25);
[57] Fix | Delete
[58] Fix | Delete
// The maximum number of files to batch at one time when writing to the backup archive. You'd only be likely to want to raise (not lower) this.
[59] Fix | Delete
if (!defined('UPDRAFTPLUS_MAXBATCHFILES')) define('UPDRAFTPLUS_MAXBATCHFILES', 1000);
[60] Fix | Delete
[61] Fix | Delete
// If any individual email attachment is greater than this, then a warning is given (and then removed if the email actually succeeds)
[62] Fix | Delete
if (!defined('UPDRAFTPLUS_WARN_EMAIL_SIZE')) define('UPDRAFTPLUS_WARN_EMAIL_SIZE', 20*1048576);
[63] Fix | Delete
[64] Fix | Delete
// Filetypes that should be stored inside the zip without any attempt at further compression. By default, we mark several extensions that refer to filetypes that are already compressed as not needing further compression - which saves time/resources. This option only applies to zip engines that support varying the compression method. Specify in lower-case, and upper-case variants (and for some zip engines, all variants) will automatically be included.
[65] Fix | Delete
if (!defined('UPDRAFTPLUS_ZIP_NOCOMPRESS')) define('UPDRAFTPLUS_ZIP_NOCOMPRESS', '.jpg,.jpeg,.png,.gif,.zip,.gz,.bz2,.xz,.rar,.mp3,.mp4,.mpeg,.avi,.mov');
[66] Fix | Delete
[67] Fix | Delete
// This is passed to set_time_limit() at various points, to try to maximise run-time. (UD resumes if it gets killed, but more in one stretch always helps). The effect of this varies according to the hosting setup - it can't necessarily always be controlled.
[68] Fix | Delete
if (!defined('UPDRAFTPLUS_SET_TIME_LIMIT')) define('UPDRAFTPLUS_SET_TIME_LIMIT', 900);
[69] Fix | Delete
[70] Fix | Delete
// Options to pass to the zip binary (if that method happens to be used). By default, we mark the extensions specified in UPDRAFTPLUS_ZIP_NOCOMPRESS for non-compression via the -n flag
[71] Fix | Delete
if (!defined('UPDRAFTPLUS_BINZIP_OPTS')) {
[72] Fix | Delete
$zip_nocompress = array_map('trim', explode(',', UPDRAFTPLUS_ZIP_NOCOMPRESS));
[73] Fix | Delete
$zip_binzip_opts = '';
[74] Fix | Delete
foreach ($zip_nocompress as $ext) {
[75] Fix | Delete
if (empty($zip_binzip_opts)) {
[76] Fix | Delete
$zip_binzip_opts = "-n $ext:".strtoupper($ext);
[77] Fix | Delete
} else {
[78] Fix | Delete
$zip_binzip_opts .= ':'.$ext.':'.strtoupper($ext);
[79] Fix | Delete
}
[80] Fix | Delete
}
[81] Fix | Delete
define('UPDRAFTPLUS_BINZIP_OPTS', $zip_binzip_opts);
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
// Load add-ons and files that may or may not be present, depending on where the plugin was distributed
[85] Fix | Delete
if (is_file(UPDRAFTPLUS_DIR.'/autoload.php')) require_once(UPDRAFTPLUS_DIR.'/autoload.php');
[86] Fix | Delete
[87] Fix | Delete
if (!function_exists('updraftplus_modify_cron_schedules')) :
[88] Fix | Delete
/**
[89] Fix | Delete
* wp-cron only has hourly, daily and twicedaily, so we need to add some of our own
[90] Fix | Delete
*
[91] Fix | Delete
* @param array $schedules an array of schedule types
[92] Fix | Delete
* @return array
[93] Fix | Delete
*/
[94] Fix | Delete
function updraftplus_modify_cron_schedules($schedules) {
[95] Fix | Delete
$schedules['weekly'] = array('interval' => 604800, 'display' => 'Once Weekly');
[96] Fix | Delete
$schedules['fortnightly'] = array('interval' => 1209600, 'display' => 'Once Each Fortnight');
[97] Fix | Delete
$schedules['monthly'] = array('interval' => 2592000, 'display' => 'Once Monthly');
[98] Fix | Delete
$schedules['everyhour'] = array('interval' => 3600, 'display' => __('Every hour', 'updraftplus'));
[99] Fix | Delete
$schedules['every2hours'] = array('interval' => 7200, 'display' => sprintf(__('Every %s hours', 'updraftplus'), 2));
[100] Fix | Delete
$schedules['every4hours'] = array('interval' => 14400, 'display' => sprintf(__('Every %s hours', 'updraftplus'), 4));
[101] Fix | Delete
$schedules['every8hours'] = array('interval' => 28800, 'display' => sprintf(__('Every %s hours', 'updraftplus'), 8));
[102] Fix | Delete
return $schedules;
[103] Fix | Delete
}
[104] Fix | Delete
endif;
[105] Fix | Delete
// http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules. Raised priority because some plugins wrongly over-write all prior schedule changes (including BackupBuddy!)
[106] Fix | Delete
add_filter('cron_schedules', 'updraftplus_modify_cron_schedules', 30);
[107] Fix | Delete
[108] Fix | Delete
// The checks here before loading are for performance only - unless one of those conditions is met, then none of the hooks will ever be used
[109] Fix | Delete
if (!is_admin() && (!defined('DOING_CRON') || !DOING_CRON) && (!defined('XMLRPC_REQUEST') || !XMLRPC_REQUEST) && empty($_SERVER['SHELL']) && empty($_POST['udrpc_message']) && empty($_GET['udcentral_action']) && (defined('UPDRAFTPLUS_THIS_IS_CLONE') && '1' != UPDRAFTPLUS_THIS_IS_CLONE) && empty($_GET['uc_auto_login']) && (empty($_SERVER['REQUEST_METHOD']) || 'OPTIONS' != $_SERVER['REQUEST_METHOD']) && (!defined('WP_CLI') || !WP_CLI)) {
[110] Fix | Delete
// There is no good way to work out if the cron event is likely to be called under the ALTERNATE_WP_CRON system, other than re-running the calculation
[111] Fix | Delete
// If ALTERNATE_WP_CRON is not active (and a few other things), then we are done
[112] Fix | Delete
if (!defined('ALTERNATE_WP_CRON') || !ALTERNATE_WP_CRON || !empty($_POST) || defined('DOING_AJAX') || isset($_GET['doing_wp_cron'])) return;
[113] Fix | Delete
[114] Fix | Delete
// The check below is the one used by spawn_cron() to decide whether cron events should be run
[115] Fix | Delete
$gmt_time = microtime(true);
[116] Fix | Delete
$lock = get_transient('doing_cron');
[117] Fix | Delete
if ($lock > $gmt_time + 10 * 60) $lock = 0;
[118] Fix | Delete
if ((defined('WP_CRON_LOCK_TIMEOUT') && $lock + WP_CRON_LOCK_TIMEOUT > $gmt_time) || (!defined('WP_CRON_LOCK_TIMEOUT') && $lock + 60 > $gmt_time)) return;
[119] Fix | Delete
if (function_exists('_get_cron_array')) {
[120] Fix | Delete
$crons = _get_cron_array();
[121] Fix | Delete
} else {
[122] Fix | Delete
$crons = get_option('cron');
[123] Fix | Delete
}
[124] Fix | Delete
if (!is_array($crons)) return;
[125] Fix | Delete
[126] Fix | Delete
$keys = array_keys($crons);
[127] Fix | Delete
if (isset($keys[0]) && $keys[0] > $gmt_time) return;
[128] Fix | Delete
// If we got this far, then cron is going to be fired, so we do want to load all our hooks
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
$updraftplus_have_addons = 0;
[132] Fix | Delete
if (is_dir(UPDRAFTPLUS_DIR.'/addons') && $dir_handle = opendir(UPDRAFTPLUS_DIR.'/addons')) {
[133] Fix | Delete
while (false !== ($e = readdir($dir_handle))) {
[134] Fix | Delete
if (is_file(UPDRAFTPLUS_DIR.'/addons/'.$e) && preg_match('/\.php$/', $e)) {
[135] Fix | Delete
// We used to have 1024 bytes here - but this meant that if someone's site was hacked and a lot of code added at the top, and if they were running a too-low PHP version, then they might just see the symptom rather than the cause - and raise the support request with us.
[136] Fix | Delete
$header = file_get_contents(UPDRAFTPLUS_DIR.'/addons/'.$e, false, null, 0, 16384);
[137] Fix | Delete
$phprequires = preg_match("/RequiresPHP: (\d[\d\.]+)/", $header, $matches) ? $matches[1] : false;
[138] Fix | Delete
$phpinclude = preg_match("/IncludePHP: (\S+)/", $header, $matches) ? $matches[1] : false;
[139] Fix | Delete
if (false === $phprequires || version_compare(PHP_VERSION, $phprequires, '>=')) {
[140] Fix | Delete
$updraftplus_have_addons++;
[141] Fix | Delete
if ($phpinclude) include_once(UPDRAFTPLUS_DIR.'/'.$phpinclude);
[142] Fix | Delete
include_once(UPDRAFTPLUS_DIR.'/addons/'.$e);
[143] Fix | Delete
}
[144] Fix | Delete
}
[145] Fix | Delete
}
[146] Fix | Delete
@closedir($dir_handle);// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
if (is_file(UPDRAFTPLUS_DIR.'/udaddons/updraftplus-addons.php')) require_once(UPDRAFTPLUS_DIR.'/udaddons/updraftplus-addons.php');
[150] Fix | Delete
[151] Fix | Delete
if (!file_exists(UPDRAFTPLUS_DIR.'/class-updraftplus.php') || !file_exists(UPDRAFTPLUS_DIR.'/options.php')) {
[152] Fix | Delete
/**
[153] Fix | Delete
* Warn if they've not got the whole plugin - can happen if WP crashes (e.g. out of disk space) when upgrading the plugin
[154] Fix | Delete
*/
[155] Fix | Delete
function updraftplus_incomplete_install_warning() {
[156] Fix | Delete
echo '<div class="updraftmessage error"><p><strong>'.__('Error', 'updraftplus').':</strong> '.__("You do not have UpdraftPlus completely installed - please de-install and install it again. Most likely, WordPress malfunctioned when copying the plugin files.", 'updraftplus').' <a href="https://updraftplus.com/faqs/wordpress-crashed-when-updating-updraftplus-what-can-i-do/">'.__('Go here for more information.', 'updraftplus').'</a></p></div>';
[157] Fix | Delete
}
[158] Fix | Delete
add_action('all_admin_notices', 'updraftplus_incomplete_install_warning');
[159] Fix | Delete
} else {
[160] Fix | Delete
[161] Fix | Delete
include_once(UPDRAFTPLUS_DIR.'/class-updraftplus.php');
[162] Fix | Delete
$updraftplus = new UpdraftPlus();
[163] Fix | Delete
$GLOBALS['updraftplus'] = $updraftplus;
[164] Fix | Delete
$updraftplus->have_addons = $updraftplus_have_addons;
[165] Fix | Delete
[166] Fix | Delete
if (!$updraftplus->memory_check(192)) {
[167] Fix | Delete
// Experience appears to show that the memory limit is only likely to be hit (unless it is very low) by single files that are larger than available memory (when compressed)
[168] Fix | Delete
// Add sanity checks - found someone who'd set WP_MAX_MEMORY_LIMIT to 256K !
[169] Fix | Delete
if (!$updraftplus->memory_check($updraftplus->memory_check_current(WP_MAX_MEMORY_LIMIT))) {
[170] Fix | Delete
$new = absint($updraftplus->memory_check_current(WP_MAX_MEMORY_LIMIT));
[171] Fix | Delete
if ($new>32 && $new<100000) {
[172] Fix | Delete
@ini_set('memory_limit', $new.'M');// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
[173] Fix | Delete
}
[174] Fix | Delete
}
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
// Blocking updates during restore; placed here so that it still runs e.g. under WP-CLI
[178] Fix | Delete
$updraftplus->block_updates_during_restore_progress();
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
// Ubuntu bug - https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1315888
[182] Fix | Delete
if (!function_exists('gzopen') && function_exists('gzopen64')) {
[183] Fix | Delete
function gzopen($filename, $mode, $use_include_path = 0) {
[184] Fix | Delete
return gzopen64($filename, $mode, $use_include_path);
[185] Fix | Delete
}
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
/**
[189] Fix | Delete
* For finding mysqldump. Added to include Windows locations.
[190] Fix | Delete
*/
[191] Fix | Delete
function updraftplus_build_mysqldump_list() {
[192] Fix | Delete
if ('win' == strtolower(substr(PHP_OS, 0, 3)) && function_exists('glob')) {
[193] Fix | Delete
$drives = array('C', 'D', 'E');
[194] Fix | Delete
[195] Fix | Delete
if (!empty($_SERVER['DOCUMENT_ROOT'])) {
[196] Fix | Delete
// Get the drive that this is running on
[197] Fix | Delete
$current_drive = strtoupper(substr($_SERVER['DOCUMENT_ROOT'], 0, 1));
[198] Fix | Delete
if (!in_array($current_drive, $drives)) array_unshift($drives, $current_drive);
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
$directories = array();
[202] Fix | Delete
[203] Fix | Delete
foreach ($drives as $drive_letter) {
[204] Fix | Delete
$dir = glob("$drive_letter:\\{Program Files\\MySQL\\{,MySQL*,etc}{,\\bin,\\?},mysqldump}\\mysqldump*", GLOB_BRACE);
[205] Fix | Delete
if (is_array($dir)) $directories = array_merge($directories, $dir);
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
$drive_string = implode(',', $directories);
[209] Fix | Delete
return $drive_string;
[210] Fix | Delete
[211] Fix | Delete
} else {
[212] Fix | Delete
return "/usr/bin/mysqldump,/bin/mysqldump,/usr/local/bin/mysqldump,/usr/sfw/bin/mysqldump,/usr/xdg4/bin/mysqldump,/opt/bin/mysqldump";
[213] Fix | Delete
}
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
// Do this even if the missing files detection above fired, as the "missing files" detection above has a greater chance of showing the user useful info
[217] Fix | Delete
if (!class_exists('UpdraftPlus_Options')) require_once(UPDRAFTPLUS_DIR.'/options.php');
[218] Fix | Delete
[219] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function