Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/worker/src/MWP/Action
File: ClearTransient.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
* This file is part of the ManageWP Worker plugin.
[2] Fix | Delete
*
[3] Fix | Delete
* (c) ManageWP LLC <contact@managewp.com>
[4] Fix | Delete
*
[5] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[6] Fix | Delete
* file that was distributed with this source code.
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
class MWP_Action_ClearTransient extends MWP_Action_Abstract
[10] Fix | Delete
{
[11] Fix | Delete
public function execute(array $params = array())
[12] Fix | Delete
{
[13] Fix | Delete
$total = array(
[14] Fix | Delete
'deletedTransients' => 0,
[15] Fix | Delete
'deletedTransientTimeouts' => 0,
[16] Fix | Delete
);
[17] Fix | Delete
[18] Fix | Delete
if (is_array($params['transient'])) {
[19] Fix | Delete
foreach ($params['transient'] as $transient) {
[20] Fix | Delete
$cleared = $this->clearTransients($params['prefix'], $transient['name'], $transient['suffix'], $transient['timeout'], $transient['mask'], $transient['limit']);
[21] Fix | Delete
$total['deletedTransients'] += $cleared['deletedTransients'];
[22] Fix | Delete
$total['deletedTransientTimeouts'] += $cleared['deletedTransientTimeouts'];
[23] Fix | Delete
}
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
return $total;
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
private function clearTransients($prefix, $transientType, $suffix, $timeout, $mask, $limit)
[30] Fix | Delete
{
[31] Fix | Delete
$wpdb = $this->container->getWordPressContext()->getDb();
[32] Fix | Delete
[33] Fix | Delete
$timeoutName = $transientType.$suffix;
[34] Fix | Delete
$subStrLength = strlen($timeoutName) + 1;
[35] Fix | Delete
[36] Fix | Delete
$escapedTimeoutName = str_replace('_', '\_', $timeoutName);
[37] Fix | Delete
[38] Fix | Delete
$selectTimeOutedTransients = <<<SQL
[39] Fix | Delete
SELECT SUBSTR(option_name, {$subStrLength}) AS transient_name FROM {$prefix}options WHERE option_name LIKE '{$escapedTimeoutName}{$mask}' AND option_value < {$timeout} LIMIT {$limit}
[40] Fix | Delete
SQL;
[41] Fix | Delete
[42] Fix | Delete
$transientsToDelete = $wpdb->get_col($selectTimeOutedTransients);
[43] Fix | Delete
$timeoutsToDelete = array();
[44] Fix | Delete
[45] Fix | Delete
if (count($transientsToDelete) === 0) {
[46] Fix | Delete
return array(
[47] Fix | Delete
'deletedTransients' => 0,
[48] Fix | Delete
'deletedTransientTimeouts' => 0,
[49] Fix | Delete
);
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
foreach ($transientsToDelete as &$transient) {
[53] Fix | Delete
$timeoutsToDelete[] = "'".$timeoutName.$transient."'";
[54] Fix | Delete
$transient = "'".$transientType.$transient."'";
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
$deleteQuery = implode(',', $transientsToDelete);
[58] Fix | Delete
[59] Fix | Delete
$deleteTransients = <<<SQL
[60] Fix | Delete
DELETE FROM {$prefix}options WHERE option_name IN ({$deleteQuery})
[61] Fix | Delete
SQL;
[62] Fix | Delete
[63] Fix | Delete
$deletedTransients = $wpdb->query($deleteTransients);
[64] Fix | Delete
[65] Fix | Delete
$deleteQuery = implode(',', $timeoutsToDelete);
[66] Fix | Delete
[67] Fix | Delete
$deleteTransients = <<<SQL
[68] Fix | Delete
DELETE FROM {$prefix}options WHERE option_name IN ({$deleteQuery})
[69] Fix | Delete
SQL;
[70] Fix | Delete
[71] Fix | Delete
$deletedTransientTimeouts = $wpdb->query($deleteTransients);
[72] Fix | Delete
[73] Fix | Delete
return array(
[74] Fix | Delete
'deletedTransients' => $deletedTransients,
[75] Fix | Delete
'deletedTransientTimeouts' => $deletedTransientTimeouts,
[76] Fix | Delete
);
[77] Fix | Delete
}
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function