Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/worker
File: init.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
Plugin Name: ManageWP - Worker
[2] Fix | Delete
Plugin URI: https://managewp.com
[3] Fix | Delete
Description: We help you efficiently manage all your WordPress websites. <strong>Updates, backups, 1-click login, migrations, security</strong> and more, on one dashboard. This service comes in two versions: standalone <a href="https://managewp.com">ManageWP</a> service that focuses on website management, and <a href="https://godaddy.com/pro">GoDaddy Pro</a> that includes additional tools for hosting, client management, lead generation, and more.
[4] Fix | Delete
Version: 4.9.13
[5] Fix | Delete
Author: GoDaddy
[6] Fix | Delete
Author URI: https://godaddy.com
[7] Fix | Delete
License: GPL2
[8] Fix | Delete
Text Domain: worker
[9] Fix | Delete
Network: true
[10] Fix | Delete
*/
[11] Fix | Delete
[12] Fix | Delete
/*
[13] Fix | Delete
* This file is part of the ManageWP Worker plugin.
[14] Fix | Delete
*
[15] Fix | Delete
* (c) ManageWP LLC <contact@managewp.com>
[16] Fix | Delete
*
[17] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[18] Fix | Delete
* file that was distributed with this source code.
[19] Fix | Delete
*/
[20] Fix | Delete
[21] Fix | Delete
if (!defined('ABSPATH') && (!defined('MWP_SKIP_BOOTSTRAP') || !MWP_SKIP_BOOTSTRAP)) {
[22] Fix | Delete
exit;
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
if (!defined('MAX_PRIORITY_HOOK')) {
[26] Fix | Delete
define('MAX_PRIORITY_HOOK', 2147483647);
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* Handler for incomplete plugin installations.
[31] Fix | Delete
*/
[32] Fix | Delete
if (!function_exists('mwp_fail_safe')):
[33] Fix | Delete
/**
[34] Fix | Delete
* Reserved memory for fatal error handling execution context.
[35] Fix | Delete
*/
[36] Fix | Delete
$GLOBALS['mwp_reserved_memory'] = str_repeat(' ', 1024 * 20);
[37] Fix | Delete
/**
[38] Fix | Delete
* If we ever get only partially upgraded due to a server error or misconfiguration,
[39] Fix | Delete
* attempt to disable the plugin.
[40] Fix | Delete
*/
[41] Fix | Delete
function mwp_fail_safe()
[42] Fix | Delete
{
[43] Fix | Delete
$GLOBALS['mwp_reserved_memory'] = null;
[44] Fix | Delete
[45] Fix | Delete
$lastError = error_get_last();
[46] Fix | Delete
[47] Fix | Delete
$acceptedErrorTypes = array(
[48] Fix | Delete
E_ERROR,
[49] Fix | Delete
E_COMPILE_ERROR,
[50] Fix | Delete
);
[51] Fix | Delete
[52] Fix | Delete
if (!$lastError || !in_array($lastError['type'], $acceptedErrorTypes)) {
[53] Fix | Delete
return;
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
$activePlugins = get_option('active_plugins');
[57] Fix | Delete
$workerIndex = array_search(plugin_basename(__FILE__), $activePlugins);
[58] Fix | Delete
if ($workerIndex === false) {
[59] Fix | Delete
// Plugin is not yet enabled, possibly in activation context.
[60] Fix | Delete
return;
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
$errorSource = realpath($lastError['file']);
[64] Fix | Delete
// We might be in eval() context.
[65] Fix | Delete
if (!$errorSource) {
[66] Fix | Delete
return;
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
// The only fatal error that we would get would be a 'Class 'X' not found in ...', so look out only for those messages.
[70] Fix | Delete
if (!preg_match('/^(Uncaught Error: )?Class \'[^\']+\' not found/', $lastError['message']) &&
[71] Fix | Delete
!preg_match('/^(Uncaught Error: )?Call to undefined method /', $lastError['message']) &&
[72] Fix | Delete
!preg_match('/^require_once\(\): Failed opening required \'[^\']+\'/', $lastError['message'])
[73] Fix | Delete
) {
[74] Fix | Delete
return;
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
// Only look for files that belong to this plugin.
[78] Fix | Delete
$pluginBase = realpath(dirname(__FILE__));
[79] Fix | Delete
if (stripos($errorSource, $pluginBase) !== 0) {
[80] Fix | Delete
return;
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
// Signal ourselves that the installation is corrupt.
[84] Fix | Delete
update_option('mwp_recovering', time());
[85] Fix | Delete
[86] Fix | Delete
$siteUrl = get_option('siteurl');
[87] Fix | Delete
$path = (string)parse_url($siteUrl, PHP_URL_PATH);
[88] Fix | Delete
$title = sprintf("ManageWP Worker corrupt on %s", $siteUrl);
[89] Fix | Delete
$to = get_option('admin_email');
[90] Fix | Delete
$brand = get_option('mwp_worker_brand');
[91] Fix | Delete
if (!empty($brand['admin_email'])) {
[92] Fix | Delete
$to = $brand['admin_email'];
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
$fullError = print_r($lastError, 1);
[96] Fix | Delete
$serviceID = (string)get_option('mwp_service_key');
[97] Fix | Delete
$body = sprintf("Corrupt ManageWP Worker v%s installation detected. Site URL in question is %s. User email is %s (service ID: %s). Attempting recovery process at %s. The error that caused this:\n\n<pre>%s</pre>", $GLOBALS['MMB_WORKER_VERSION'], $siteUrl, $to, $serviceID, date('Y-m-d H:i:s'), $fullError);
[98] Fix | Delete
mail('recovery@managewp.com', $title, $body, "Content-Type: text/html");
[99] Fix | Delete
[100] Fix | Delete
// If we're inside a cron scope, don't attempt to hide this error.
[101] Fix | Delete
if (defined('DOING_CRON') && DOING_CRON) {
[102] Fix | Delete
return;
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
// If we're inside a normal request scope retry the request so user doesn't have to see an ugly error page.
[106] Fix | Delete
if (!empty($_SERVER['REQUEST_URI'])) {
[107] Fix | Delete
$siteUrl .= substr($_SERVER['REQUEST_URI'], strlen($path));
[108] Fix | Delete
}
[109] Fix | Delete
if (isset($_SERVER['HTTP_MWP_ACTION'])) {
[110] Fix | Delete
echo "\nMWP_RETRY_ME: 1\n", json_encode(array('error' => 'Worker recover started', 'exception' => array(
[111] Fix | Delete
'class' => 'Exception',
[112] Fix | Delete
'message' => 'Worker recover started',
[113] Fix | Delete
'code' => 10038,
[114] Fix | Delete
'file' => __FILE__,
[115] Fix | Delete
'line' => __LINE__,
[116] Fix | Delete
'traceString' => '',
[117] Fix | Delete
'context' => array(),
[118] Fix | Delete
'type' => 'WORKER_RECOVER_STARTED',
[119] Fix | Delete
))), "\n";
[120] Fix | Delete
exit;
[121] Fix | Delete
} elseif (headers_sent()) {
[122] Fix | Delete
// The headers are probably sent if the PHP configuration has the 'display_errors' directive enabled. In that case try a meta redirect.
[123] Fix | Delete
printf('<meta http-equiv="refresh" content="0; url=%s">', htmlspecialchars($siteUrl, ENT_QUOTES));
[124] Fix | Delete
} else {
[125] Fix | Delete
header('Location: '.htmlspecialchars($siteUrl, ENT_QUOTES));
[126] Fix | Delete
}
[127] Fix | Delete
exit;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
register_shutdown_function('mwp_fail_safe');
[131] Fix | Delete
endif;
[132] Fix | Delete
[133] Fix | Delete
if (!class_exists('MwpWorkerResponder', false)):
[134] Fix | Delete
/**
[135] Fix | Delete
* We're not allowed to use lambda functions because this is PHP 5.2, so use a responder
[136] Fix | Delete
* class that's able to access the service container.
[137] Fix | Delete
*/
[138] Fix | Delete
class MwpWorkerResponder
[139] Fix | Delete
{
[140] Fix | Delete
[141] Fix | Delete
private $container;
[142] Fix | Delete
[143] Fix | Delete
private $responseSent = false;
[144] Fix | Delete
[145] Fix | Delete
function __construct(MWP_ServiceContainer_Interface $container)
[146] Fix | Delete
{
[147] Fix | Delete
$this->container = $container;
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
/**
[151] Fix | Delete
* @param Exception|Error $e
[152] Fix | Delete
* @param MWP_Http_ResponseInterface|null $response
[153] Fix | Delete
*
[154] Fix | Delete
* @throws null
[155] Fix | Delete
*/
[156] Fix | Delete
function callback($e = null, MWP_Http_ResponseInterface $response = null)
[157] Fix | Delete
{
[158] Fix | Delete
if ($response !== null) {
[159] Fix | Delete
$responseEvent = new MWP_Event_MasterResponse($response);
[160] Fix | Delete
$this->container->getEventDispatcher()->dispatch(MWP_Event_Events::MASTER_RESPONSE, $responseEvent);
[161] Fix | Delete
$lastResponse = $responseEvent->getResponse();
[162] Fix | Delete
[163] Fix | Delete
if ($lastResponse !== null) {
[164] Fix | Delete
if (!$this->responseSent) {
[165] Fix | Delete
// This looks pretty ugly, but the "execute PHP" function handles fatal errors and wraps them
[166] Fix | Delete
// in a valid action response. That fatal error may also be handled by the global fatal error
[167] Fix | Delete
// handler, which also wraps the error in a response. We keep the state in this class, so we
[168] Fix | Delete
// don't send a worker response twice, first time as an action response, second time as a
[169] Fix | Delete
// global response.
[170] Fix | Delete
// If this is to be removed, simply remove fatal error handling from the "execute PHP" action.
[171] Fix | Delete
$lastResponse->send();
[172] Fix | Delete
$this->responseSent = true;
[173] Fix | Delete
}
[174] Fix | Delete
exit;
[175] Fix | Delete
}
[176] Fix | Delete
} elseif ($e !== null) {
[177] Fix | Delete
// Exception is thrown and the response is empty. This should never happen, so don't try to hide it.
[178] Fix | Delete
throw $e;
[179] Fix | Delete
}
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
/**
[183] Fix | Delete
* @return callable
[184] Fix | Delete
*/
[185] Fix | Delete
public function getCallback()
[186] Fix | Delete
{
[187] Fix | Delete
return array($this, 'callback');
[188] Fix | Delete
}
[189] Fix | Delete
}
[190] Fix | Delete
endif;
[191] Fix | Delete
[192] Fix | Delete
if (!function_exists('mwp_container')):
[193] Fix | Delete
/**
[194] Fix | Delete
* @return MWP_ServiceContainer_Interface
[195] Fix | Delete
*/
[196] Fix | Delete
function mwp_container()
[197] Fix | Delete
{
[198] Fix | Delete
static $container;
[199] Fix | Delete
[200] Fix | Delete
if ($container === null) {
[201] Fix | Delete
$parameters = (array)get_option('mwp_container_parameters', array()) + (array)get_option('mwp_container_site_parameters', array());
[202] Fix | Delete
$requestId = isset($_GET['mwprid']) && is_string($_GET['mwprid']) ? $_GET['mwprid'] : null;
[203] Fix | Delete
$container = new MWP_ServiceContainer_Production(array(
[204] Fix | Delete
'worker_realpath' => __FILE__,
[205] Fix | Delete
'worker_basename' => 'worker/init.php',
[206] Fix | Delete
'worker_version' => $GLOBALS['MMB_WORKER_VERSION'],
[207] Fix | Delete
'worker_revision' => $GLOBALS['MMB_WORKER_REVISION'],
[208] Fix | Delete
'request_id' => $requestId,
[209] Fix | Delete
) + $parameters);
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
return $container;
[213] Fix | Delete
}
[214] Fix | Delete
endif;
[215] Fix | Delete
[216] Fix | Delete
if (!class_exists('MwpRecoveryKit', false)):
[217] Fix | Delete
/**
[218] Fix | Delete
* This class must be isolated from the rest of the ManageWP Worker library, because
[219] Fix | Delete
* we're counting that we have only this file and WordPress bootstrapped.
[220] Fix | Delete
*/
[221] Fix | Delete
class MwpRecoveryKit
[222] Fix | Delete
{
[223] Fix | Delete
const MAX_LOGGED_ERRORS = 5;
[224] Fix | Delete
[225] Fix | Delete
private static $errorLog = array();
[226] Fix | Delete
[227] Fix | Delete
private static function requestJson($url)
[228] Fix | Delete
{
[229] Fix | Delete
$response = wp_remote_get($url, array('timeout' => 60));
[230] Fix | Delete
if ($response instanceof WP_Error) {
[231] Fix | Delete
throw new Exception('Unable to download checksum.json: '.$response->get_error_message());
[232] Fix | Delete
}
[233] Fix | Delete
if ($response['response']['code'] !== 200) {
[234] Fix | Delete
throw new Exception('Unable to download checksum.json: invalid status code ('.$response['response']['code'].')');
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
$responseJson = json_decode($response['body'], true);
[238] Fix | Delete
[239] Fix | Delete
if (empty($responseJson) || !is_array($responseJson)) {
[240] Fix | Delete
throw new Exception('Error while parsing checksum.json.');
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
return $responseJson;
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
public function recover($version)
[247] Fix | Delete
{
[248] Fix | Delete
global $wpdb;
[249] Fix | Delete
$lockTime = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'mwp_incremental_recover_lock' LIMIT 1");
[250] Fix | Delete
[251] Fix | Delete
[252] Fix | Delete
if ($lockTime && time() - (int)$lockTime < 1200) { // lock for 20 minutes
[253] Fix | Delete
throw new Exception('Another incremental update or recovery process is already active', 1337);
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
register_shutdown_function(array($this, 'releaseLock'));
[257] Fix | Delete
[258] Fix | Delete
update_option('mwp_incremental_recover_lock', time());
[259] Fix | Delete
[260] Fix | Delete
ignore_user_abort(true);
[261] Fix | Delete
$dirName = realpath(dirname(__FILE__));
[262] Fix | Delete
$filesAndChecksums = $this->requestJson(sprintf('http://s3-us-west-2.amazonaws.com/mwp-orion-public/worker/raw/%s/checksum.json', $version));
[263] Fix | Delete
[264] Fix | Delete
try {
[265] Fix | Delete
$files = $this->recoverFiles($dirName, $filesAndChecksums, $version);
[266] Fix | Delete
} catch (Exception $e) {
[267] Fix | Delete
$this->releaseLock();
[268] Fix | Delete
throw $e;
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
$this->releaseLock();
[272] Fix | Delete
[273] Fix | Delete
return $files;
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
public function releaseLock()
[277] Fix | Delete
{
[278] Fix | Delete
delete_option('mwp_incremental_recover_lock');
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
public static function selfUpdate()
[282] Fix | Delete
{
[283] Fix | Delete
if (get_option('mwp_recovering')) {
[284] Fix | Delete
return false;
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
try {
[288] Fix | Delete
$response = self::requestJson('http://s3-us-west-2.amazonaws.com/mwp-orion-public/worker/latest.json');
[289] Fix | Delete
$response += array('version' => '0.0.0', 'schedule' => 86400, 'autoUpdate' => false, 'checksum' => array());
[290] Fix | Delete
wp_clear_scheduled_hook('mwp_auto_update');
[291] Fix | Delete
wp_schedule_single_event(current_time('timestamp') + $response['schedule'], 'mwp_auto_update');
[292] Fix | Delete
if (!$response['autoUpdate']) {
[293] Fix | Delete
return false;
[294] Fix | Delete
}
[295] Fix | Delete
if (version_compare($response['version'], $GLOBALS['MMB_WORKER_VERSION'], '<')) {
[296] Fix | Delete
return false;
[297] Fix | Delete
}
[298] Fix | Delete
self::recoverFiles(dirname(__FILE__), $response['checksum'], $response['version']);
[299] Fix | Delete
} catch (Exception $e) {
[300] Fix | Delete
mwp_logger()->error("Self-update failed.", array('exception' => $e));
[301] Fix | Delete
[302] Fix | Delete
return false;
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
return true;
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
private static function clearUnknownFiles($filesAndChecksums, $fs)
[309] Fix | Delete
{
[310] Fix | Delete
/** @var WP_Filesystem_Base $fs */
[311] Fix | Delete
$base = dirname(__FILE__);
[312] Fix | Delete
if (version_compare(phpversion(), '5.3', '<')) {
[313] Fix | Delete
$directory = new RecursiveDirectoryIterator($base);
[314] Fix | Delete
} else {
[315] Fix | Delete
/** @handled constant */
[316] Fix | Delete
$directory = new RecursiveDirectoryIterator($base, RecursiveDirectoryIterator::SKIP_DOTS);
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
$ignoreDelete = array(
[320] Fix | Delete
'log.html' => 1,
[321] Fix | Delete
'worker.json' => 1,
[322] Fix | Delete
'init.php' => 1, // safe-guard
[323] Fix | Delete
'functions.php' => 1, // safe-guard
[324] Fix | Delete
);
[325] Fix | Delete
[326] Fix | Delete
$files = array_keys(iterator_to_array(new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD)));
[327] Fix | Delete
[328] Fix | Delete
foreach ($files as $file) {
[329] Fix | Delete
$file = preg_replace('/^'.preg_quote($base, '/').'/', '', $file, 1, $count);
[330] Fix | Delete
[331] Fix | Delete
if (!$count) {
[332] Fix | Delete
continue;
[333] Fix | Delete
}
[334] Fix | Delete
[335] Fix | Delete
$file = strtr($file, '\\', '/');
[336] Fix | Delete
$file = ltrim($file, '/');
[337] Fix | Delete
[338] Fix | Delete
if (isset($filesAndChecksums[$file]) || isset($ignoreDelete[$file])) {
[339] Fix | Delete
continue;
[340] Fix | Delete
}
[341] Fix | Delete
[342] Fix | Delete
$fs->delete($fs->find_folder(WP_PLUGIN_DIR).'worker/'.$file, false, 'f');
[343] Fix | Delete
}
[344] Fix | Delete
}
[345] Fix | Delete
[346] Fix | Delete
public static function recoverFiles($dirName, array $filesAndChecksums, $version)
[347] Fix | Delete
{
[348] Fix | Delete
set_error_handler(array(__CLASS__, 'logError'));
[349] Fix | Delete
require_once ABSPATH.'wp-admin/includes/file.php';
[350] Fix | Delete
require_once ABSPATH.'wp-admin/includes/template.php';
[351] Fix | Delete
[352] Fix | Delete
$options = array();
[353] Fix | Delete
[354] Fix | Delete
$fsMethod = get_filesystem_method();
[355] Fix | Delete
if ($fsMethod !== 'direct') {
[356] Fix | Delete
ob_start();
[357] Fix | Delete
$options = request_filesystem_credentials('');
[358] Fix | Delete
ob_end_clean();
[359] Fix | Delete
}
[360] Fix | Delete
[361] Fix | Delete
/** @var WP_Filesystem_Base $fs */
[362] Fix | Delete
WP_Filesystem($options);
[363] Fix | Delete
$fs = $GLOBALS['wp_filesystem'];
[364] Fix | Delete
[365] Fix | Delete
if (!$fs->connect()) {
[366] Fix | Delete
$lastError = error_get_last();
[367] Fix | Delete
$errorMessage = $lastError ? $lastError['message'] : '(no error logged)';
[368] Fix | Delete
throw new Exception('Unable to connect to the file system: '.$errorMessage);
[369] Fix | Delete
}
[370] Fix | Delete
[371] Fix | Delete
$cachedFilesAndChecksums = $filesAndChecksums;
[372] Fix | Delete
[373] Fix | Delete
// First create directories and remove them from the array.
[374] Fix | Delete
// Must be done before shuffling because of nesting.
[375] Fix | Delete
foreach ($filesAndChecksums as $relativePath => $checksum) {
[376] Fix | Delete
if ($checksum !== '') {
[377] Fix | Delete
continue;
[378] Fix | Delete
}
[379] Fix | Delete
unset ($filesAndChecksums[$relativePath]);
[380] Fix | Delete
$absolutePath = $dirName.'/'.$relativePath;
[381] Fix | Delete
// Directories are ordered first.
[382] Fix | Delete
if (!is_dir($absolutePath)) {
[383] Fix | Delete
$fs->mkdir($fs->find_folder(WP_PLUGIN_DIR).'worker/'.$relativePath);
[384] Fix | Delete
}
[385] Fix | Delete
}
[386] Fix | Delete
[387] Fix | Delete
// Check and recreate files. Shuffle them so multiple running instances have a smaller collision.
[388] Fix | Delete
$recoveredFiles = array();
[389] Fix | Delete
$filesAndChecksums = self::shuffleAssoc($filesAndChecksums);
[390] Fix | Delete
$retryCount = 0;
[391] Fix | Delete
$retryUpTo = 5;
[392] Fix | Delete
$lastError = null;
[393] Fix | Delete
while ($checksum = current($filesAndChecksums)) {
[394] Fix | Delete
if ($retryCount >= $retryUpTo) {
[395] Fix | Delete
restore_error_handler();
[396] Fix | Delete
throw new Exception($lastError);
[397] Fix | Delete
}
[398] Fix | Delete
$relativePath = key($filesAndChecksums);
[399] Fix | Delete
$absolutePath = $dirName.'/'.$relativePath;
[400] Fix | Delete
if (file_exists($absolutePath) && md5_file($absolutePath) === $checksum) {
[401] Fix | Delete
next($filesAndChecksums);
[402] Fix | Delete
continue;
[403] Fix | Delete
}
[404] Fix | Delete
$fileUrl = sprintf('http://s3-us-west-2.amazonaws.com/mwp-orion-public/worker/raw/%s/%s', $version, $relativePath);
[405] Fix | Delete
$response = wp_remote_get($fileUrl, array('timeout' => 60));
[406] Fix | Delete
if ($response instanceof WP_Error) {
[407] Fix | Delete
$lastError = 'Unable to download file '.$fileUrl.': '.$response->get_error_message();
[408] Fix | Delete
$retryCount++;
[409] Fix | Delete
continue;
[410] Fix | Delete
}
[411] Fix | Delete
if ($response['response']['code'] !== 200) {
[412] Fix | Delete
$lastError = 'Unable to download file '.$fileUrl.': invalid status code ('.$response['response']['code'].')';
[413] Fix | Delete
$retryCount++;
[414] Fix | Delete
continue;
[415] Fix | Delete
}
[416] Fix | Delete
$saved = $fs->put_contents($fs->find_folder(WP_PLUGIN_DIR).'worker/'.$relativePath, $response['body']);
[417] Fix | Delete
[418] Fix | Delete
if (!$saved) {
[419] Fix | Delete
if (is_callable(array($fs, '__destruct'))) {
[420] Fix | Delete
$fs->__destruct();
[421] Fix | Delete
}
[422] Fix | Delete
$fs->connect();
[423] Fix | Delete
$lastError = 'File saving failed.';
[424] Fix | Delete
if (count(self::$errorLog)) {
[425] Fix | Delete
$lastError .= sprintf(" Last %d logged errors:%s", min(self::MAX_LOGGED_ERRORS, count(self::$errorLog)), "\n - ".implode("\n - ", self::$errorLog));
[426] Fix | Delete
}
[427] Fix | Delete
$retryCount++;
[428] Fix | Delete
continue;
[429] Fix | Delete
}
[430] Fix | Delete
[431] Fix | Delete
$lastError = null;
[432] Fix | Delete
$retryCount = 0;
[433] Fix | Delete
$recoveredFiles[] = $relativePath;
[434] Fix | Delete
next($filesAndChecksums);
[435] Fix | Delete
}
[436] Fix | Delete
[437] Fix | Delete
self::clearUnknownFiles($cachedFilesAndChecksums, $fs);
[438] Fix | Delete
[439] Fix | Delete
if (function_exists('opcache_reset')) {
[440] Fix | Delete
@opcache_reset();
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
restore_error_handler();
[444] Fix | Delete
[445] Fix | Delete
return $recoveredFiles;
[446] Fix | Delete
}
[447] Fix | Delete
[448] Fix | Delete
public static function logError($code, $message, $file = 'Unknown', $line = 0)
[449] Fix | Delete
{
[450] Fix | Delete
self::$errorLog[] = sprintf('Error [%d]: %s in %s on line %d', $code, $message, $file, $line);
[451] Fix | Delete
[452] Fix | Delete
if (count(self::$errorLog) > self::MAX_LOGGED_ERRORS) {
[453] Fix | Delete
array_shift(self::$errorLog);
[454] Fix | Delete
}
[455] Fix | Delete
}
[456] Fix | Delete
[457] Fix | Delete
private static function shuffleAssoc($array)
[458] Fix | Delete
{
[459] Fix | Delete
$keys = array_keys($array);
[460] Fix | Delete
shuffle($keys);
[461] Fix | Delete
$shuffled = array();
[462] Fix | Delete
foreach ($keys as $key) {
[463] Fix | Delete
$shuffled[$key] = $array[$key];
[464] Fix | Delete
}
[465] Fix | Delete
[466] Fix | Delete
return $shuffled;
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
public function selfDeactivate($reason)
[470] Fix | Delete
{
[471] Fix | Delete
if (isset($_SERVER['MWP2_VERSION_ID'])) {
[472] Fix | Delete
return;
[473] Fix | Delete
}
[474] Fix | Delete
[475] Fix | Delete
$activePlugins = get_option('active_plugins');
[476] Fix | Delete
$workerIndex = array_search(plugin_basename(__FILE__), $activePlugins);
[477] Fix | Delete
if ($workerIndex === false) {
[478] Fix | Delete
// Plugin is not yet enabled, possibly in activation context.
[479] Fix | Delete
return;
[480] Fix | Delete
}
[481] Fix | Delete
unset($activePlugins[$workerIndex]);
[482] Fix | Delete
// Reset indexes.
[483] Fix | Delete
$activePlugins = array_values($activePlugins);
[484] Fix | Delete
[485] Fix | Delete
delete_option('mwp_recovering');
[486] Fix | Delete
update_option('active_plugins', $activePlugins);
[487] Fix | Delete
[488] Fix | Delete
$lastErrorMessage = '';
[489] Fix | Delete
if ($lastError = error_get_last()) {
[490] Fix | Delete
$lastErrorMessage = "\n\nLast error: ".$lastError['message'];
[491] Fix | Delete
}
[492] Fix | Delete
mail('recovery@managewp.com', sprintf("ManageWP Worker recovery aborted on %s", get_option('siteurl')), sprintf("ManageWP Worker v%s. Reason: %s%s", $GLOBALS['MMB_WORKER_VERSION'], $reason, $lastErrorMessage));
[493] Fix | Delete
}
[494] Fix | Delete
}
[495] Fix | Delete
endif;
[496] Fix | Delete
[497] Fix | Delete
if (!function_exists('mwp_activation_hook')) {
[498] Fix | Delete
function mwp_activation_hook()
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function