Edit File by line
/home/barbar84/www/wp-conte.../plugins/worker/src/MMB
File: Installer.php
[500] Fix | Delete
$update_core = update_core($working_dir, $wp_dir);
[501] Fix | Delete
ob_end_clean();
[502] Fix | Delete
[503] Fix | Delete
$this->mmb_maintenance_mode(false);
[504] Fix | Delete
if (is_wp_error($update_core)) {
[505] Fix | Delete
return array(
[506] Fix | Delete
'error' => $this->mmb_get_error($update_core),
[507] Fix | Delete
);
[508] Fix | Delete
}
[509] Fix | Delete
ob_end_flush();
[510] Fix | Delete
[511] Fix | Delete
return array(
[512] Fix | Delete
'upgraded' => 'updated',
[513] Fix | Delete
);
[514] Fix | Delete
} else {
[515] Fix | Delete
return array(
[516] Fix | Delete
'error' => 'failed',
[517] Fix | Delete
);
[518] Fix | Delete
}
[519] Fix | Delete
}
[520] Fix | Delete
} else {
[521] Fix | Delete
return array(
[522] Fix | Delete
'error' => 'failed',
[523] Fix | Delete
);
[524] Fix | Delete
}
[525] Fix | Delete
}
[526] Fix | Delete
[527] Fix | Delete
public function upgrade_plugins($plugins = false)
[528] Fix | Delete
{
[529] Fix | Delete
if (!$plugins || empty($plugins)) {
[530] Fix | Delete
return array(
[531] Fix | Delete
'error' => 'No plugin files for upgrade.',
[532] Fix | Delete
);
[533] Fix | Delete
}
[534] Fix | Delete
[535] Fix | Delete
if (!function_exists('wp_update_plugins')) {
[536] Fix | Delete
include_once ABSPATH.'wp-includes/update.php';
[537] Fix | Delete
}
[538] Fix | Delete
[539] Fix | Delete
$return = array();
[540] Fix | Delete
[541] Fix | Delete
if (class_exists('Plugin_Upgrader')) {
[542] Fix | Delete
/** @handled class */
[543] Fix | Delete
$upgrader = new Plugin_Upgrader(mwp_container()->getUpdaterSkin());
[544] Fix | Delete
$result = $upgrader->bulk_upgrade(array_keys($plugins));
[545] Fix | Delete
[546] Fix | Delete
if (!empty($result)) {
[547] Fix | Delete
foreach ($result as $plugin_slug => $plugin_info) {
[548] Fix | Delete
if (!$plugin_info || is_wp_error($plugin_info)) {
[549] Fix | Delete
$return[$plugin_slug] = $this->mmb_get_error($plugin_info);
[550] Fix | Delete
continue;
[551] Fix | Delete
}
[552] Fix | Delete
[553] Fix | Delete
$return[$plugin_slug] = 1;
[554] Fix | Delete
}
[555] Fix | Delete
[556] Fix | Delete
return array(
[557] Fix | Delete
'upgraded' => $return,
[558] Fix | Delete
'additional_updates' => $this->get_additional_plugin_updates($result),
[559] Fix | Delete
);
[560] Fix | Delete
} else {
[561] Fix | Delete
return array(
[562] Fix | Delete
'error' => 'Upgrade failed.',
[563] Fix | Delete
);
[564] Fix | Delete
}
[565] Fix | Delete
} else {
[566] Fix | Delete
return array(
[567] Fix | Delete
'error' => 'WordPress update required first.',
[568] Fix | Delete
);
[569] Fix | Delete
}
[570] Fix | Delete
}
[571] Fix | Delete
[572] Fix | Delete
private function get_additional_plugin_updates($plugin_upgrades)
[573] Fix | Delete
{
[574] Fix | Delete
if (empty($plugin_upgrades)) {
[575] Fix | Delete
return array();
[576] Fix | Delete
}
[577] Fix | Delete
[578] Fix | Delete
$additional_updates = array();
[579] Fix | Delete
[580] Fix | Delete
if (array_key_exists('woocommerce/woocommerce.php', $plugin_upgrades) && is_plugin_active('woocommerce/woocommerce.php') && $this->has_woocommerce_db_update()) {
[581] Fix | Delete
$additional_updates['woocommerce/woocommerce.php'] = 1;
[582] Fix | Delete
}
[583] Fix | Delete
[584] Fix | Delete
return $additional_updates;
[585] Fix | Delete
}
[586] Fix | Delete
[587] Fix | Delete
private function has_woocommerce_db_update()
[588] Fix | Delete
{
[589] Fix | Delete
$current_db_version = get_option('woocommerce_db_version', null);
[590] Fix | Delete
$current_wc_version = get_option('woocommerce_version');
[591] Fix | Delete
if (version_compare($current_wc_version, '3.0.0', '<')) {
[592] Fix | Delete
return true;
[593] Fix | Delete
}
[594] Fix | Delete
[595] Fix | Delete
$latestUpdate = $this->get_wc_db_latest_update();
[596] Fix | Delete
[597] Fix | Delete
return !is_null($current_db_version) && !is_null($latestUpdate) &&
[598] Fix | Delete
version_compare($current_db_version, $latestUpdate, '<');
[599] Fix | Delete
}
[600] Fix | Delete
[601] Fix | Delete
private function get_wc_db_latest_update()
[602] Fix | Delete
{
[603] Fix | Delete
$regexp = "{'(\d+\.)(\d+\.)(\d+)'}"; // version in single quote '1.0.0', '2.1.3', '3.1.22' etc
[604] Fix | Delete
$fileName = WP_PLUGIN_DIR.'/woocommerce/includes/class-wc-install.php';
[605] Fix | Delete
[606] Fix | Delete
if (file_exists($fileName)) {
[607] Fix | Delete
$fileContent = file_get_contents($fileName);
[608] Fix | Delete
preg_match_all($regexp, $fileContent, $matches);
[609] Fix | Delete
[610] Fix | Delete
if (!empty($matches[0])) {
[611] Fix | Delete
$latestUpdate = trim(end($matches[0]), "'");
[612] Fix | Delete
return $latestUpdate;
[613] Fix | Delete
}
[614] Fix | Delete
}
[615] Fix | Delete
return null;
[616] Fix | Delete
}
[617] Fix | Delete
[618] Fix | Delete
public function upgrade_themes($themes = false)
[619] Fix | Delete
{
[620] Fix | Delete
if (!$themes || empty($themes)) {
[621] Fix | Delete
return array(
[622] Fix | Delete
'error' => 'No theme files for upgrade.',
[623] Fix | Delete
);
[624] Fix | Delete
}
[625] Fix | Delete
[626] Fix | Delete
if (!function_exists('wp_update_themes')) {
[627] Fix | Delete
include_once ABSPATH.'wp-includes/update.php';
[628] Fix | Delete
}
[629] Fix | Delete
[630] Fix | Delete
if (class_exists('Theme_Upgrader')) {
[631] Fix | Delete
/** @handled class */
[632] Fix | Delete
$upgrader = new Theme_Upgrader(mwp_container()->getUpdaterSkin());
[633] Fix | Delete
$result = $upgrader->bulk_upgrade($themes);
[634] Fix | Delete
[635] Fix | Delete
$return = array();
[636] Fix | Delete
if (!empty($result)) {
[637] Fix | Delete
foreach ($result as $theme_tmp => $theme_info) {
[638] Fix | Delete
if (is_wp_error($theme_info) || empty($theme_info)) {
[639] Fix | Delete
$return[$theme_tmp] = $this->mmb_get_error($theme_info);
[640] Fix | Delete
continue;
[641] Fix | Delete
}
[642] Fix | Delete
[643] Fix | Delete
$return[$theme_tmp] = 1;
[644] Fix | Delete
}
[645] Fix | Delete
[646] Fix | Delete
return array(
[647] Fix | Delete
'upgraded' => $return,
[648] Fix | Delete
);
[649] Fix | Delete
} else {
[650] Fix | Delete
return array(
[651] Fix | Delete
'error' => 'Upgrade failed.',
[652] Fix | Delete
);
[653] Fix | Delete
}
[654] Fix | Delete
} else {
[655] Fix | Delete
return array(
[656] Fix | Delete
'error' => 'WordPress update required first',
[657] Fix | Delete
);
[658] Fix | Delete
}
[659] Fix | Delete
}
[660] Fix | Delete
[661] Fix | Delete
public function upgrade_translations()
[662] Fix | Delete
{
[663] Fix | Delete
include_once ABSPATH.'wp-admin/includes/class-wp-upgrader.php';
[664] Fix | Delete
[665] Fix | Delete
if (class_exists('Language_Pack_Upgrader')) {
[666] Fix | Delete
/** @handled class */
[667] Fix | Delete
$upgrader = new Language_Pack_Upgrader(mwp_container()->getUpdaterSkin());
[668] Fix | Delete
$result = $upgrader->bulk_upgrade();
[669] Fix | Delete
[670] Fix | Delete
if (!empty($result)) {
[671] Fix | Delete
$return = 1;
[672] Fix | Delete
[673] Fix | Delete
if (is_array($result)) {
[674] Fix | Delete
foreach ($result as $translate_tmp => $translate_info) {
[675] Fix | Delete
if (is_wp_error($translate_info) || empty($translate_info)) {
[676] Fix | Delete
$return = $this->mmb_get_error($translate_info);
[677] Fix | Delete
break;
[678] Fix | Delete
}
[679] Fix | Delete
}
[680] Fix | Delete
}
[681] Fix | Delete
[682] Fix | Delete
return array('upgraded' => $return);
[683] Fix | Delete
} else {
[684] Fix | Delete
return array(
[685] Fix | Delete
'error' => 'Upgrade failed.',
[686] Fix | Delete
);
[687] Fix | Delete
}
[688] Fix | Delete
} else {
[689] Fix | Delete
return array(
[690] Fix | Delete
'error' => 'WordPress update required first',
[691] Fix | Delete
);
[692] Fix | Delete
}
[693] Fix | Delete
}
[694] Fix | Delete
[695] Fix | Delete
public function get_upgradable_plugins()
[696] Fix | Delete
{
[697] Fix | Delete
$current = $this->mmb_get_transient('update_plugins');
[698] Fix | Delete
[699] Fix | Delete
$upgradable_plugins = array();
[700] Fix | Delete
if (!empty($current->response)) {
[701] Fix | Delete
if (!function_exists('get_plugin_data')) {
[702] Fix | Delete
include_once ABSPATH.'wp-admin/includes/plugin.php';
[703] Fix | Delete
}
[704] Fix | Delete
foreach ($current->response as $plugin_path => $plugin_data) {
[705] Fix | Delete
$data = get_plugin_data(WP_PLUGIN_DIR.'/'.$plugin_path, false, false);
[706] Fix | Delete
[707] Fix | Delete
if (strlen($data['Name']) > 0 && strlen($data['Version']) > 0) {
[708] Fix | Delete
$current->response[$plugin_path]->name = $data['Name'];
[709] Fix | Delete
$current->response[$plugin_path]->old_version = $data['Version'];
[710] Fix | Delete
$current->response[$plugin_path]->file = $plugin_path;
[711] Fix | Delete
unset($current->response[$plugin_path]->upgrade_notice);
[712] Fix | Delete
$upgradable_plugins[] = $current->response[$plugin_path];
[713] Fix | Delete
}
[714] Fix | Delete
}
[715] Fix | Delete
[716] Fix | Delete
return $upgradable_plugins;
[717] Fix | Delete
} else {
[718] Fix | Delete
return array();
[719] Fix | Delete
}
[720] Fix | Delete
}
[721] Fix | Delete
[722] Fix | Delete
public function get_upgradable_themes()
[723] Fix | Delete
{
[724] Fix | Delete
if (function_exists('wp_get_themes')) {
[725] Fix | Delete
$all_themes = wp_get_themes();
[726] Fix | Delete
$upgrade_themes = array();
[727] Fix | Delete
[728] Fix | Delete
$current = $this->mmb_get_transient('update_themes');
[729] Fix | Delete
[730] Fix | Delete
if (empty($current->response)) {
[731] Fix | Delete
return $upgrade_themes;
[732] Fix | Delete
}
[733] Fix | Delete
[734] Fix | Delete
foreach ((array)$all_themes as $theme_template => $theme_data) {
[735] Fix | Delete
foreach ($current->response as $current_themes => $theme) {
[736] Fix | Delete
if ($theme_data->Stylesheet !== $current_themes) {
[737] Fix | Delete
continue;
[738] Fix | Delete
}
[739] Fix | Delete
[740] Fix | Delete
if (strlen($theme_data->Name) === 0 || strlen($theme_data->Version) === 0) {
[741] Fix | Delete
continue;
[742] Fix | Delete
}
[743] Fix | Delete
[744] Fix | Delete
$current->response[$current_themes]['name'] = $theme_data->Name;
[745] Fix | Delete
$current->response[$current_themes]['old_version'] = $theme_data->Version;
[746] Fix | Delete
$current->response[$current_themes]['theme_tmp'] = $theme_data->Stylesheet;
[747] Fix | Delete
[748] Fix | Delete
$upgrade_themes[] = $current->response[$current_themes];
[749] Fix | Delete
}
[750] Fix | Delete
}
[751] Fix | Delete
} else {
[752] Fix | Delete
$all_themes = get_themes();
[753] Fix | Delete
[754] Fix | Delete
$upgrade_themes = array();
[755] Fix | Delete
[756] Fix | Delete
$current = $this->mmb_get_transient('update_themes');
[757] Fix | Delete
if (!empty($current->response)) {
[758] Fix | Delete
foreach ((array)$all_themes as $theme_template => $theme_data) {
[759] Fix | Delete
if (isset($theme_data['Parent Theme']) && !empty($theme_data['Parent Theme'])) {
[760] Fix | Delete
continue;
[761] Fix | Delete
}
[762] Fix | Delete
[763] Fix | Delete
if (isset($theme_data['Name']) && in_array($theme_data['Name'], $filter)) {
[764] Fix | Delete
continue;
[765] Fix | Delete
}
[766] Fix | Delete
[767] Fix | Delete
foreach ($current->response as $current_themes => $theme) {
[768] Fix | Delete
if ($theme_data['Template'] == $current_themes) {
[769] Fix | Delete
if (strlen($theme_data['Name']) > 0 && strlen($theme_data['Version']) > 0) {
[770] Fix | Delete
$current->response[$current_themes]['name'] = $theme_data['Name'];
[771] Fix | Delete
$current->response[$current_themes]['old_version'] = $theme_data['Version'];
[772] Fix | Delete
$current->response[$current_themes]['theme_tmp'] = $theme_data['Template'];
[773] Fix | Delete
$upgrade_themes[] = $current->response[$current_themes];
[774] Fix | Delete
}
[775] Fix | Delete
}
[776] Fix | Delete
}
[777] Fix | Delete
}
[778] Fix | Delete
}
[779] Fix | Delete
}
[780] Fix | Delete
[781] Fix | Delete
return $upgrade_themes;
[782] Fix | Delete
}
[783] Fix | Delete
[784] Fix | Delete
public function get_upgradable_translations()
[785] Fix | Delete
{
[786] Fix | Delete
$updates = array(
[787] Fix | Delete
'core' => array(),
[788] Fix | Delete
'plugins' => array(),
[789] Fix | Delete
'themes' => array(),
[790] Fix | Delete
);
[791] Fix | Delete
[792] Fix | Delete
$transients = array('update_core' => 'core', 'update_plugins' => 'plugins', 'update_themes' => 'themes');
[793] Fix | Delete
[794] Fix | Delete
foreach ($transients as $transient => $type) {
[795] Fix | Delete
$transient = get_site_transient($transient);
[796] Fix | Delete
[797] Fix | Delete
if (empty($transient->translations)) {
[798] Fix | Delete
continue;
[799] Fix | Delete
}
[800] Fix | Delete
[801] Fix | Delete
foreach ($transient->translations as $translation) {
[802] Fix | Delete
$updates[$type][] = (object)$translation;
[803] Fix | Delete
}
[804] Fix | Delete
}
[805] Fix | Delete
[806] Fix | Delete
return $updates;
[807] Fix | Delete
}
[808] Fix | Delete
[809] Fix | Delete
public function edit($args)
[810] Fix | Delete
{
[811] Fix | Delete
extract($args);
[812] Fix | Delete
$return = array();
[813] Fix | Delete
if ($type == 'plugins') {
[814] Fix | Delete
$return['plugins'] = $this->edit_plugins($args);
[815] Fix | Delete
} elseif ($type == 'themes') {
[816] Fix | Delete
$return['themes'] = $this->edit_themes($args);
[817] Fix | Delete
}
[818] Fix | Delete
[819] Fix | Delete
return $return;
[820] Fix | Delete
}
[821] Fix | Delete
[822] Fix | Delete
public function edit_plugins($args)
[823] Fix | Delete
{
[824] Fix | Delete
extract($args);
[825] Fix | Delete
$return = array();
[826] Fix | Delete
foreach ($items as $item) {
[827] Fix | Delete
switch ($items_edit_action) {
[828] Fix | Delete
case 'activate':
[829] Fix | Delete
$result = activate_plugin($item['path'], '', $item['networkWide']);
[830] Fix | Delete
break;
[831] Fix | Delete
case 'deactivate':
[832] Fix | Delete
$result = deactivate_plugins(
[833] Fix | Delete
array(
[834] Fix | Delete
$item['path'],
[835] Fix | Delete
),
[836] Fix | Delete
false,
[837] Fix | Delete
$item['networkWide']
[838] Fix | Delete
);
[839] Fix | Delete
break;
[840] Fix | Delete
case 'delete':
[841] Fix | Delete
$result = delete_plugins(
[842] Fix | Delete
array(
[843] Fix | Delete
$item['path'],
[844] Fix | Delete
)
[845] Fix | Delete
);
[846] Fix | Delete
break;
[847] Fix | Delete
default:
[848] Fix | Delete
break;
[849] Fix | Delete
}
[850] Fix | Delete
[851] Fix | Delete
if (is_wp_error($result)) {
[852] Fix | Delete
$result = array(
[853] Fix | Delete
'error' => $result->get_error_message(),
[854] Fix | Delete
);
[855] Fix | Delete
} elseif ($result === false) {
[856] Fix | Delete
$result = array(
[857] Fix | Delete
'error' => "Failed to perform action.",
[858] Fix | Delete
);
[859] Fix | Delete
} else {
[860] Fix | Delete
$result = "OK";
[861] Fix | Delete
}
[862] Fix | Delete
$return[$item['name']] = $result;
[863] Fix | Delete
}
[864] Fix | Delete
[865] Fix | Delete
return $return;
[866] Fix | Delete
}
[867] Fix | Delete
[868] Fix | Delete
public function edit_themes($args)
[869] Fix | Delete
{
[870] Fix | Delete
extract($args);
[871] Fix | Delete
$return = array();
[872] Fix | Delete
foreach ($items as $item) {
[873] Fix | Delete
switch ($items_edit_action) {
[874] Fix | Delete
case 'activate':
[875] Fix | Delete
switch_theme($item['path'], $item['stylesheet']);
[876] Fix | Delete
break;
[877] Fix | Delete
case 'delete':
[878] Fix | Delete
$result = delete_theme($item['stylesheet']);
[879] Fix | Delete
break;
[880] Fix | Delete
default:
[881] Fix | Delete
break;
[882] Fix | Delete
}
[883] Fix | Delete
[884] Fix | Delete
if (is_wp_error($result)) {
[885] Fix | Delete
$result = array(
[886] Fix | Delete
'error' => $result->get_error_message(),
[887] Fix | Delete
);
[888] Fix | Delete
} elseif ($result === false) {
[889] Fix | Delete
$result = array(
[890] Fix | Delete
'error' => "Failed to perform action.",
[891] Fix | Delete
);
[892] Fix | Delete
} else {
[893] Fix | Delete
$result = "OK";
[894] Fix | Delete
}
[895] Fix | Delete
$return[$item['name']] = $result;
[896] Fix | Delete
}
[897] Fix | Delete
[898] Fix | Delete
return $return;
[899] Fix | Delete
}
[900] Fix | Delete
}
[901] Fix | Delete
[902] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function