Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp.../central/modules
File: plugin.php
<?php
[0] Fix | Delete
[1] Fix | Delete
if (!defined('UPDRAFTCENTRAL_CLIENT_DIR')) die('No access.');
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* Handles UpdraftCentral Plugin Commands which basically handles
[5] Fix | Delete
* the installation and activation of a plugin
[6] Fix | Delete
*/
[7] Fix | Delete
class UpdraftCentral_Plugin_Commands extends UpdraftCentral_Commands {
[8] Fix | Delete
[9] Fix | Delete
private $switched = false;
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Function that gets called before every action
[13] Fix | Delete
*
[14] Fix | Delete
* @param string $command a string that corresponds to UDC command to call a certain method for this class.
[15] Fix | Delete
* @param array $data an array of data post or get fields
[16] Fix | Delete
* @param array $extra_info extrainfo use in the udrpc_action, e.g. user_id
[17] Fix | Delete
*
[18] Fix | Delete
* link to udrpc_action main function in class UpdraftCentral_Listener
[19] Fix | Delete
*/
[20] Fix | Delete
public function _pre_action($command, $data, $extra_info) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- This function is called from listner.php and $extra_info is being sent.
[21] Fix | Delete
// Here we assign the current blog_id to a variable $blog_id
[22] Fix | Delete
$blog_id = get_current_blog_id();
[23] Fix | Delete
if (!empty($data['site_id'])) $blog_id = $data['site_id'];
[24] Fix | Delete
[25] Fix | Delete
if (function_exists('switch_to_blog') && is_multisite() && $blog_id) {
[26] Fix | Delete
$this->switched = switch_to_blog($blog_id);
[27] Fix | Delete
}
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Function that gets called after every action
[32] Fix | Delete
*
[33] Fix | Delete
* @param string $command a string that corresponds to UDC command to call a certain method for this class.
[34] Fix | Delete
* @param array $data an array of data post or get fields
[35] Fix | Delete
* @param array $extra_info extrainfo use in the udrpc_action, e.g. user_id
[36] Fix | Delete
*
[37] Fix | Delete
* link to udrpc_action main function in class UpdraftCentral_Listener
[38] Fix | Delete
*/
[39] Fix | Delete
public function _post_action($command, $data, $extra_info) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
[40] Fix | Delete
// Here, we're restoring to the current (default) blog before we switched
[41] Fix | Delete
if ($this->switched) restore_current_blog();
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Constructor
[46] Fix | Delete
*/
[47] Fix | Delete
public function __construct() {
[48] Fix | Delete
$this->_admin_include('plugin.php', 'file.php', 'template.php', 'class-wp-upgrader.php', 'plugin-install.php', 'update.php');
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* Installs and activates a plugin through upload
[53] Fix | Delete
*
[54] Fix | Delete
* @param array $params Parameter array containing information pertaining the currently uploaded plugin
[55] Fix | Delete
* @return array Contains the result of the current process
[56] Fix | Delete
*/
[57] Fix | Delete
public function upload_plugin($params) {
[58] Fix | Delete
return $this->process_chunk_upload($params, 'plugin');
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* Checks whether the plugin is currently installed and activated.
[63] Fix | Delete
*
[64] Fix | Delete
* @param array $query Parameter array containing the name of the plugin to check
[65] Fix | Delete
* @return array Contains the result of the current process
[66] Fix | Delete
*/
[67] Fix | Delete
public function is_plugin_installed($query) {
[68] Fix | Delete
[69] Fix | Delete
if (!isset($query['plugin']))
[70] Fix | Delete
return $this->_generic_error_response('plugin_name_required');
[71] Fix | Delete
[72] Fix | Delete
[73] Fix | Delete
$result = $this->_get_plugin_info($query);
[74] Fix | Delete
return $this->_response($result);
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* Applies currently requested action for plugin processing
[79] Fix | Delete
*
[80] Fix | Delete
* @param string $action The action to apply (e.g. activate or install)
[81] Fix | Delete
* @param array $query Parameter array containing information for the currently requested action
[82] Fix | Delete
*
[83] Fix | Delete
* @return array
[84] Fix | Delete
*/
[85] Fix | Delete
private function _apply_plugin_action($action, $query) {
[86] Fix | Delete
[87] Fix | Delete
$result = array();
[88] Fix | Delete
switch ($action) {
[89] Fix | Delete
case 'activate':
[90] Fix | Delete
case 'network_activate':
[91] Fix | Delete
$info = $this->_get_plugin_info($query);
[92] Fix | Delete
if ($info['installed']) {
[93] Fix | Delete
if (is_multisite() && 'network_activate' === $action) {
[94] Fix | Delete
$activate = activate_plugin($info['plugin_path'], '', true);
[95] Fix | Delete
} else {
[96] Fix | Delete
$activate = activate_plugin($info['plugin_path']);
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
if (is_wp_error($activate)) {
[100] Fix | Delete
$result = $this->_generic_error_response('generic_response_error', array(
[101] Fix | Delete
'plugin' => $query['plugin'],
[102] Fix | Delete
'error_code' => 'generic_response_error',
[103] Fix | Delete
'error_message' => $activate->get_error_message(),
[104] Fix | Delete
'info' => $this->_get_plugin_info($query)
[105] Fix | Delete
));
[106] Fix | Delete
} else {
[107] Fix | Delete
$result = array('activated' => true, 'info' => $this->_get_plugin_info($query));
[108] Fix | Delete
}
[109] Fix | Delete
} else {
[110] Fix | Delete
$result = $this->_generic_error_response('plugin_not_installed', array(
[111] Fix | Delete
'plugin' => $query['plugin'],
[112] Fix | Delete
'error_code' => 'plugin_not_installed',
[113] Fix | Delete
'error_message' => __('The plugin you wish to activate is either not installed or has been removed recently.', 'updraftplus'),
[114] Fix | Delete
'info' => $info
[115] Fix | Delete
));
[116] Fix | Delete
}
[117] Fix | Delete
break;
[118] Fix | Delete
case 'deactivate':
[119] Fix | Delete
case 'network_deactivate':
[120] Fix | Delete
$info = $this->_get_plugin_info($query);
[121] Fix | Delete
if ($info['active']) {
[122] Fix | Delete
if (is_multisite() && 'network_deactivate' === $action) {
[123] Fix | Delete
deactivate_plugins($info['plugin_path'], false, true);
[124] Fix | Delete
} else {
[125] Fix | Delete
deactivate_plugins($info['plugin_path']);
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
if (!is_plugin_active($info['plugin_path'])) {
[129] Fix | Delete
$result = array('deactivated' => true, 'info' => $this->_get_plugin_info($query));
[130] Fix | Delete
} else {
[131] Fix | Delete
$result = $this->_generic_error_response('deactivate_plugin_failed', array(
[132] Fix | Delete
'plugin' => $query['plugin'],
[133] Fix | Delete
'error_code' => 'deactivate_plugin_failed',
[134] Fix | Delete
'error_message' => __('There appears to be a problem deactivating the intended plugin. Please kindly check your permission and try again.', 'updraftplus'),
[135] Fix | Delete
'info' => $this->_get_plugin_info($query)
[136] Fix | Delete
));
[137] Fix | Delete
}
[138] Fix | Delete
} else {
[139] Fix | Delete
$result = $this->_generic_error_response('not_active', array(
[140] Fix | Delete
'plugin' => $query['plugin'],
[141] Fix | Delete
'error_code' => 'not_active',
[142] Fix | Delete
'error_message' => __('The plugin you wish to deactivate is currently not active or is already deactivated.', 'updraftplus'),
[143] Fix | Delete
'info' => $info
[144] Fix | Delete
));
[145] Fix | Delete
}
[146] Fix | Delete
break;
[147] Fix | Delete
case 'install':
[148] Fix | Delete
$api = plugins_api('plugin_information', array(
[149] Fix | Delete
'slug' => $query['slug'],
[150] Fix | Delete
'fields' => array(
[151] Fix | Delete
'short_description' => false,
[152] Fix | Delete
'sections' => false,
[153] Fix | Delete
'requires' => false,
[154] Fix | Delete
'rating' => false,
[155] Fix | Delete
'ratings' => false,
[156] Fix | Delete
'downloaded' => false,
[157] Fix | Delete
'last_updated' => false,
[158] Fix | Delete
'added' => false,
[159] Fix | Delete
'tags' => false,
[160] Fix | Delete
'compatibility' => false,
[161] Fix | Delete
'homepage' => false,
[162] Fix | Delete
'donate_link' => false,
[163] Fix | Delete
)
[164] Fix | Delete
));
[165] Fix | Delete
[166] Fix | Delete
$info = $this->_get_plugin_info($query);
[167] Fix | Delete
if (is_wp_error($api)) {
[168] Fix | Delete
$result = $this->_generic_error_response('generic_response_error', array(
[169] Fix | Delete
'plugin' => $query['plugin'],
[170] Fix | Delete
'error_code' => 'generic_response_error',
[171] Fix | Delete
'error_message' => $api->get_error_message(),
[172] Fix | Delete
'info' => $info
[173] Fix | Delete
));
[174] Fix | Delete
} else {
[175] Fix | Delete
$installed = $info['installed'];
[176] Fix | Delete
[177] Fix | Delete
$error_code = $error_message = '';
[178] Fix | Delete
if (!$installed) {
[179] Fix | Delete
// WP < 3.7
[180] Fix | Delete
if (!class_exists('Automatic_Upgrader_Skin')) include_once(dirname(dirname(__FILE__)).'/classes/class-automatic-upgrader-skin.php');
[181] Fix | Delete
[182] Fix | Delete
$skin = new Automatic_Upgrader_Skin();
[183] Fix | Delete
$upgrader = new Plugin_Upgrader($skin);
[184] Fix | Delete
[185] Fix | Delete
$download_link = $api->download_link;
[186] Fix | Delete
$installed = $upgrader->install($download_link);
[187] Fix | Delete
[188] Fix | Delete
if (is_wp_error($installed)) {
[189] Fix | Delete
$error_code = $installed->get_error_code();
[190] Fix | Delete
$error_message = $installed->get_error_message();
[191] Fix | Delete
} elseif (is_wp_error($skin->result)) {
[192] Fix | Delete
$error_code = $skin->result->get_error_code();
[193] Fix | Delete
$error_message = $skin->result->get_error_message();
[194] Fix | Delete
[195] Fix | Delete
$error_data = $skin->result->get_error_data($error_code);
[196] Fix | Delete
if (!empty($error_data)) {
[197] Fix | Delete
if (is_array($error_data)) $error_data = json_encode($error_data);
[198] Fix | Delete
$error_message .= ' '.$error_data;
[199] Fix | Delete
}
[200] Fix | Delete
} elseif (is_null($installed) || !$installed) {
[201] Fix | Delete
global $wp_filesystem;
[202] Fix | Delete
$upgrade_messages = $skin->get_upgrade_messages();
[203] Fix | Delete
[204] Fix | Delete
if (!class_exists('WP_Filesystem_Base')) include_once(ABSPATH.'/wp-admin/includes/class-wp-filesystem-base.php');
[205] Fix | Delete
[206] Fix | Delete
// Pass through the error from WP_Filesystem if one was raised.
[207] Fix | Delete
if ($wp_filesystem instanceof WP_Filesystem_Base && is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
[208] Fix | Delete
$error_code = $wp_filesystem->errors->get_error_code();
[209] Fix | Delete
$error_message = $wp_filesystem->errors->get_error_message();
[210] Fix | Delete
} elseif (!empty($upgrade_messages)) {
[211] Fix | Delete
// We're only after for the last feedback that we received from the install process. Mostly,
[212] Fix | Delete
// that is where the last error has been inserted.
[213] Fix | Delete
$messages = $skin->get_upgrade_messages();
[214] Fix | Delete
$error_code = 'install_failed';
[215] Fix | Delete
$error_message = end($messages);
[216] Fix | Delete
} else {
[217] Fix | Delete
$error_code = 'unable_to_connect_to_filesystem';
[218] Fix | Delete
$error_message = __('Unable to connect to the filesystem. Please confirm your credentials.');
[219] Fix | Delete
}
[220] Fix | Delete
}
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
if (!$installed || is_wp_error($installed)) {
[224] Fix | Delete
$result = $this->_generic_error_response('plugin_install_failed', array(
[225] Fix | Delete
'plugin' => $query['plugin'],
[226] Fix | Delete
'error_code' => $error_code,
[227] Fix | Delete
'error_message' => $error_message,
[228] Fix | Delete
'info' => $this->_get_plugin_info($query)
[229] Fix | Delete
));
[230] Fix | Delete
} else {
[231] Fix | Delete
$result = array('installed' => true, 'info' => $this->_get_plugin_info($query));
[232] Fix | Delete
}
[233] Fix | Delete
}
[234] Fix | Delete
break;
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
return $result;
[238] Fix | Delete
}
[239] Fix | Delete
[240] Fix | Delete
/**
[241] Fix | Delete
* Preloads the submitted credentials to the global $_POST variable
[242] Fix | Delete
*
[243] Fix | Delete
* @param array $query Parameter array containing information for the currently requested action
[244] Fix | Delete
*/
[245] Fix | Delete
private function _preload_credentials($query) {
[246] Fix | Delete
if (!empty($query) && isset($query['filesystem_credentials'])) {
[247] Fix | Delete
parse_str($query['filesystem_credentials'], $filesystem_credentials);
[248] Fix | Delete
if (is_array($filesystem_credentials)) {
[249] Fix | Delete
foreach ($filesystem_credentials as $key => $value) {
[250] Fix | Delete
// Put them into $_POST, which is where request_filesystem_credentials() checks for them.
[251] Fix | Delete
$_POST[$key] = $value;
[252] Fix | Delete
}
[253] Fix | Delete
}
[254] Fix | Delete
}
[255] Fix | Delete
}
[256] Fix | Delete
[257] Fix | Delete
/**
[258] Fix | Delete
* Checks whether we have the required fields submitted and the user has
[259] Fix | Delete
* the capabilities to execute the requested action
[260] Fix | Delete
*
[261] Fix | Delete
* @param array $query The submitted information
[262] Fix | Delete
* @param array $fields The required fields to check
[263] Fix | Delete
* @param array $capabilities The capabilities to check and validate
[264] Fix | Delete
*
[265] Fix | Delete
* @return array|string
[266] Fix | Delete
*/
[267] Fix | Delete
private function _validate_fields_and_capabilities($query, $fields, $capabilities) {
[268] Fix | Delete
[269] Fix | Delete
$error = '';
[270] Fix | Delete
if (!empty($fields)) {
[271] Fix | Delete
for ($i=0; $i<count($fields); $i++) {
[272] Fix | Delete
$field = $fields[$i];
[273] Fix | Delete
[274] Fix | Delete
if (!isset($query[$field])) {
[275] Fix | Delete
if ('keyword' === $field) {
[276] Fix | Delete
$error = $this->_generic_error_response('keyword_required');
[277] Fix | Delete
} else {
[278] Fix | Delete
$error = $this->_generic_error_response('plugin_'.$query[$field].'_required');
[279] Fix | Delete
}
[280] Fix | Delete
break;
[281] Fix | Delete
}
[282] Fix | Delete
}
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
if (empty($error) && !empty($capabilities)) {
[286] Fix | Delete
for ($i=0; $i<count($capabilities); $i++) {
[287] Fix | Delete
if (!current_user_can($capabilities[$i])) {
[288] Fix | Delete
$error = $this->_generic_error_response('plugin_insufficient_permission');
[289] Fix | Delete
break;
[290] Fix | Delete
}
[291] Fix | Delete
}
[292] Fix | Delete
}
[293] Fix | Delete
[294] Fix | Delete
return $error;
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
/**
[298] Fix | Delete
* Activates the plugin
[299] Fix | Delete
*
[300] Fix | Delete
* @param array $query Parameter array containing the name of the plugin to activate
[301] Fix | Delete
* @return array Contains the result of the current process
[302] Fix | Delete
*/
[303] Fix | Delete
public function activate_plugin($query) {
[304] Fix | Delete
[305] Fix | Delete
$error = $this->_validate_fields_and_capabilities($query, array('plugin'), array('activate_plugins'));
[306] Fix | Delete
if (!empty($error)) {
[307] Fix | Delete
return $error;
[308] Fix | Delete
}
[309] Fix | Delete
[310] Fix | Delete
$action = 'activate';
[311] Fix | Delete
if (!empty($query['multisite']) && (bool) $query['multisite']) $action = 'network_'.$action;
[312] Fix | Delete
[313] Fix | Delete
$result = $this->_apply_plugin_action($action, $query);
[314] Fix | Delete
if (empty($result['activated'])) {
[315] Fix | Delete
return $result;
[316] Fix | Delete
}
[317] Fix | Delete
[318] Fix | Delete
return $this->_response($result);
[319] Fix | Delete
}
[320] Fix | Delete
[321] Fix | Delete
/**
[322] Fix | Delete
* Deactivates the plugin
[323] Fix | Delete
*
[324] Fix | Delete
* @param array $query Parameter array containing the name of the plugin to deactivate
[325] Fix | Delete
* @return array Contains the result of the current process
[326] Fix | Delete
*/
[327] Fix | Delete
public function deactivate_plugin($query) {
[328] Fix | Delete
[329] Fix | Delete
$error = $this->_validate_fields_and_capabilities($query, array('plugin'), array('activate_plugins'));
[330] Fix | Delete
if (!empty($error)) {
[331] Fix | Delete
return $error;
[332] Fix | Delete
}
[333] Fix | Delete
[334] Fix | Delete
$action = 'deactivate';
[335] Fix | Delete
if (!empty($query['multisite']) && (bool) $query['multisite']) $action = 'network_'.$action;
[336] Fix | Delete
[337] Fix | Delete
$result = $this->_apply_plugin_action($action, $query);
[338] Fix | Delete
if (empty($result['deactivated'])) {
[339] Fix | Delete
return $result;
[340] Fix | Delete
}
[341] Fix | Delete
[342] Fix | Delete
return $this->_response($result);
[343] Fix | Delete
}
[344] Fix | Delete
[345] Fix | Delete
/**
[346] Fix | Delete
* Download, install and activates the plugin
[347] Fix | Delete
*
[348] Fix | Delete
* @param array $query Parameter array containing the filesystem credentials entered by the user along with the plugin name and slug
[349] Fix | Delete
* @return array Contains the result of the current process
[350] Fix | Delete
*/
[351] Fix | Delete
public function install_activate_plugin($query) {
[352] Fix | Delete
[353] Fix | Delete
$error = $this->_validate_fields_and_capabilities($query, array('plugin', 'slug'), array('install_plugins', 'activate_plugins'));
[354] Fix | Delete
if (!empty($error)) {
[355] Fix | Delete
return $error;
[356] Fix | Delete
}
[357] Fix | Delete
[358] Fix | Delete
$this->_preload_credentials($query);
[359] Fix | Delete
[360] Fix | Delete
$result = $this->_apply_plugin_action('install', $query);
[361] Fix | Delete
if (!empty($result['installed']) && $result['installed']) {
[362] Fix | Delete
$action = 'activate';
[363] Fix | Delete
if (!empty($query['multisite']) && (bool) $query['multisite']) $action = 'network_'.$action;
[364] Fix | Delete
[365] Fix | Delete
$result = $this->_apply_plugin_action($action, $query);
[366] Fix | Delete
if (empty($result['activated'])) {
[367] Fix | Delete
return $result;
[368] Fix | Delete
}
[369] Fix | Delete
} else {
[370] Fix | Delete
return $result;
[371] Fix | Delete
}
[372] Fix | Delete
[373] Fix | Delete
return $this->_response($result);
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
/**
[377] Fix | Delete
* Download, install the plugin
[378] Fix | Delete
*
[379] Fix | Delete
* @param array $query Parameter array containing the filesystem credentials entered by the user along with the plugin name and slug
[380] Fix | Delete
* @return array Contains the result of the current process
[381] Fix | Delete
*/
[382] Fix | Delete
public function install_plugin($query) {
[383] Fix | Delete
[384] Fix | Delete
$error = $this->_validate_fields_and_capabilities($query, array('plugin', 'slug'), array('install_plugins'));
[385] Fix | Delete
if (!empty($error)) {
[386] Fix | Delete
return $error;
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
$this->_preload_credentials($query);
[390] Fix | Delete
[391] Fix | Delete
$result = $this->_apply_plugin_action('install', $query);
[392] Fix | Delete
if (empty($result['installed'])) {
[393] Fix | Delete
return $result;
[394] Fix | Delete
}
[395] Fix | Delete
[396] Fix | Delete
return $this->_response($result);
[397] Fix | Delete
}
[398] Fix | Delete
[399] Fix | Delete
/**
[400] Fix | Delete
* Uninstall/delete the plugin
[401] Fix | Delete
*
[402] Fix | Delete
* @param array $query Parameter array containing the filesystem credentials entered by the user along with the plugin name and slug
[403] Fix | Delete
* @return array Contains the result of the current process
[404] Fix | Delete
*/
[405] Fix | Delete
public function delete_plugin($query) {
[406] Fix | Delete
[407] Fix | Delete
$error = $this->_validate_fields_and_capabilities($query, array('plugin'), array('delete_plugins'));
[408] Fix | Delete
if (!empty($error)) {
[409] Fix | Delete
return $error;
[410] Fix | Delete
}
[411] Fix | Delete
[412] Fix | Delete
$this->_preload_credentials($query);
[413] Fix | Delete
$info = $this->_get_plugin_info($query);
[414] Fix | Delete
[415] Fix | Delete
if ($info['installed']) {
[416] Fix | Delete
$deleted = delete_plugins(array($info['plugin_path']));
[417] Fix | Delete
[418] Fix | Delete
if ($deleted) {
[419] Fix | Delete
$result = array('deleted' => true, 'info' => $this->_get_plugin_info($query));
[420] Fix | Delete
} else {
[421] Fix | Delete
$result = $this->_generic_error_response('delete_plugin_failed', array(
[422] Fix | Delete
'plugin' => $query['plugin'],
[423] Fix | Delete
'error_code' => 'delete_plugin_failed',
[424] Fix | Delete
'info' => $info
[425] Fix | Delete
));
[426] Fix | Delete
}
[427] Fix | Delete
} else {
[428] Fix | Delete
$result = $this->_generic_error_response('plugin_not_installed', array(
[429] Fix | Delete
'plugin' => $query['plugin'],
[430] Fix | Delete
'error_code' => 'plugin_not_installed',
[431] Fix | Delete
'info' => $info
[432] Fix | Delete
));
[433] Fix | Delete
}
[434] Fix | Delete
[435] Fix | Delete
return $this->_response($result);
[436] Fix | Delete
}
[437] Fix | Delete
[438] Fix | Delete
/**
[439] Fix | Delete
* Updates/upgrade the plugin
[440] Fix | Delete
*
[441] Fix | Delete
* @param array $query Parameter array containing the filesystem credentials entered by the user along with the plugin name and slug
[442] Fix | Delete
* @return array Contains the result of the current process
[443] Fix | Delete
*/
[444] Fix | Delete
public function update_plugin($query) {
[445] Fix | Delete
[446] Fix | Delete
$error = $this->_validate_fields_and_capabilities($query, array('plugin', 'slug'), array('update_plugins'));
[447] Fix | Delete
if (!empty($error)) {
[448] Fix | Delete
return $error;
[449] Fix | Delete
}
[450] Fix | Delete
[451] Fix | Delete
$this->_preload_credentials($query);
[452] Fix | Delete
$info = $this->_get_plugin_info($query);
[453] Fix | Delete
[454] Fix | Delete
// Make sure that we still have the plugin installed before running
[455] Fix | Delete
// the update process
[456] Fix | Delete
if ($info['installed']) {
[457] Fix | Delete
// Load the updates command class if not existed
[458] Fix | Delete
if (!class_exists('UpdraftCentral_Updates_Commands')) include_once('updates.php');
[459] Fix | Delete
$update_command = new UpdraftCentral_Updates_Commands($this->rc);
[460] Fix | Delete
[461] Fix | Delete
$result = $update_command->update_plugin($info['plugin_path'], $query['slug']);
[462] Fix | Delete
if (!empty($result['error'])) {
[463] Fix | Delete
$result['values'] = array('plugin' => $query['plugin'], 'info' => $info);
[464] Fix | Delete
}
[465] Fix | Delete
} else {
[466] Fix | Delete
$result = $this->_generic_error_response('plugin_not_installed', array(
[467] Fix | Delete
'plugin' => $query['plugin'],
[468] Fix | Delete
'error_code' => 'plugin_not_installed',
[469] Fix | Delete
'info' => $info
[470] Fix | Delete
));
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
return $this->_response($result);
[474] Fix | Delete
}
[475] Fix | Delete
[476] Fix | Delete
/**
[477] Fix | Delete
* Gets the plugin information along with its active and install status
[478] Fix | Delete
*
[479] Fix | Delete
* @internal
[480] Fix | Delete
* @param array $query Contains either the plugin name or slug or both to be used when retrieving information
[481] Fix | Delete
* @return array
[482] Fix | Delete
*/
[483] Fix | Delete
private function _get_plugin_info($query) {
[484] Fix | Delete
[485] Fix | Delete
$info = array(
[486] Fix | Delete
'active' => false,
[487] Fix | Delete
'installed' => false
[488] Fix | Delete
);
[489] Fix | Delete
[490] Fix | Delete
// Clear plugin cache so that newly installed/downloaded plugins
[491] Fix | Delete
// gets reflected when calling "get_plugins"
[492] Fix | Delete
if (function_exists('wp_clean_plugins_cache')) {
[493] Fix | Delete
wp_clean_plugins_cache();
[494] Fix | Delete
}
[495] Fix | Delete
[496] Fix | Delete
// Gets all plugins available.
[497] Fix | Delete
$get_plugins = get_plugins();
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function