Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/updraftp.../central/modules
File: theme.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 Theme Commands which basically handles
[5] Fix | Delete
* the installation and activation of a theme
[6] Fix | Delete
*/
[7] Fix | Delete
class UpdraftCentral_Theme_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 listener.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('theme.php', 'file.php', 'template.php', 'class-wp-upgrader.php', 'theme-install.php', 'update.php');
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* Installs and activates a theme through upload
[53] Fix | Delete
*
[54] Fix | Delete
* @param array $params Parameter array containing information pertaining the currently uploaded theme
[55] Fix | Delete
* @return array Contains the result of the current process
[56] Fix | Delete
*/
[57] Fix | Delete
public function upload_theme($params) {
[58] Fix | Delete
return $this->process_chunk_upload($params, 'theme');
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* Checks whether the theme is currently installed and activated.
[63] Fix | Delete
*
[64] Fix | Delete
* @param array $query Parameter array containing the name of the theme to check
[65] Fix | Delete
* @return array Contains the result of the current process
[66] Fix | Delete
*/
[67] Fix | Delete
public function is_theme_installed($query) {
[68] Fix | Delete
[69] Fix | Delete
if (!isset($query['theme']))
[70] Fix | Delete
return $this->_generic_error_response('theme_name_required');
[71] Fix | Delete
[72] Fix | Delete
[73] Fix | Delete
$result = $this->_get_theme_info($query['theme']);
[74] Fix | Delete
return $this->_response($result);
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* Applies currently requested action for theme 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_theme_action($action, $query) {
[86] Fix | Delete
[87] Fix | Delete
$result = array();
[88] Fix | Delete
switch ($action) {
[89] Fix | Delete
case 'activate':
[90] Fix | Delete
$info = $this->_get_theme_info($query['theme']);
[91] Fix | Delete
if ($info['installed']) {
[92] Fix | Delete
switch_theme($info['slug']);
[93] Fix | Delete
if (wp_get_theme()->get_stylesheet() === $info['slug']) {
[94] Fix | Delete
$result = array('activated' => true, 'info' => $this->_get_theme_info($query['theme']));
[95] Fix | Delete
} else {
[96] Fix | Delete
$result = $this->_generic_error_response('theme_not_activated', array(
[97] Fix | Delete
'theme' => $query['theme'],
[98] Fix | Delete
'error_code' => 'theme_not_activated',
[99] Fix | Delete
'error_message' => __('There appears to be a problem activating or switching to the intended theme. Please kindly check your permission and try again.', 'updraftplus'),
[100] Fix | Delete
'info' => $this->_get_theme_info($query['theme'])
[101] Fix | Delete
));
[102] Fix | Delete
}
[103] Fix | Delete
} else {
[104] Fix | Delete
$result = $this->_generic_error_response('theme_not_installed', array(
[105] Fix | Delete
'theme' => $query['theme'],
[106] Fix | Delete
'error_code' => 'theme_not_installed',
[107] Fix | Delete
'error_message' => __('The theme you wish to activate is either not installed or has been removed recently.', 'updraftplus'),
[108] Fix | Delete
'info' => $info
[109] Fix | Delete
));
[110] Fix | Delete
}
[111] Fix | Delete
break;
[112] Fix | Delete
case 'network_enable':
[113] Fix | Delete
$info = $this->_get_theme_info($query['theme']);
[114] Fix | Delete
if ($info['installed']) {
[115] Fix | Delete
// Make sure that network_enable_theme is present and callable since
[116] Fix | Delete
// it is only available at 4.6. If not, we'll do things the old fashion way
[117] Fix | Delete
if (is_callable(array('WP_Theme', 'network_enable_theme'))) {
[118] Fix | Delete
WP_Theme::network_enable_theme($info['slug']);
[119] Fix | Delete
} else {
[120] Fix | Delete
$allowed_themes = get_site_option('allowedthemes');
[121] Fix | Delete
$allowed_themes[$info['slug']] = true;
[122] Fix | Delete
[123] Fix | Delete
update_site_option('allowedthemes', $allowed_themes);
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
$allowed = WP_Theme::get_allowed_on_network();
[127] Fix | Delete
if (is_array($allowed) && !empty($allowed[$info['slug']])) {
[128] Fix | Delete
$result = array('enabled' => true, 'info' => $this->_get_theme_info($query['theme']));
[129] Fix | Delete
} else {
[130] Fix | Delete
$result = $this->_generic_error_response('theme_not_enabled', array(
[131] Fix | Delete
'theme' => $query['theme'],
[132] Fix | Delete
'error_code' => 'theme_not_enabled',
[133] Fix | Delete
'error_message' => __('There appears to be a problem enabling the intended theme on your network. Please kindly check your permission and try again.', 'updraftplus'),
[134] Fix | Delete
'info' => $this->_get_theme_info($query['theme'])
[135] Fix | Delete
));
[136] Fix | Delete
}
[137] Fix | Delete
} else {
[138] Fix | Delete
$result = $this->_generic_error_response('theme_not_installed', array(
[139] Fix | Delete
'theme' => $query['theme'],
[140] Fix | Delete
'error_code' => 'theme_not_installed',
[141] Fix | Delete
'error_message' => __('The theme you wish to enable on your network is either not installed or has been removed recently.', 'updraftplus'),
[142] Fix | Delete
'info' => $info
[143] Fix | Delete
));
[144] Fix | Delete
}
[145] Fix | Delete
break;
[146] Fix | Delete
case 'network_disable':
[147] Fix | Delete
$info = $this->_get_theme_info($query['theme']);
[148] Fix | Delete
if ($info['installed']) {
[149] Fix | Delete
// Make sure that network_disable_theme is present and callable since
[150] Fix | Delete
// it is only available at 4.6. If not, we'll do things the old fashion way
[151] Fix | Delete
if (is_callable(array('WP_Theme', 'network_disable_theme'))) {
[152] Fix | Delete
WP_Theme::network_disable_theme($info['slug']);
[153] Fix | Delete
} else {
[154] Fix | Delete
$allowed_themes = get_site_option('allowedthemes');
[155] Fix | Delete
if (isset($allowed_themes[$info['slug']])) {
[156] Fix | Delete
unset($allowed_themes[$info['slug']]);
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
update_site_option('allowedthemes', $allowed_themes);
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
$allowed = WP_Theme::get_allowed_on_network();
[163] Fix | Delete
if (is_array($allowed) && empty($allowed[$info['slug']])) {
[164] Fix | Delete
$result = array('disabled' => true, 'info' => $this->_get_theme_info($query['theme']));
[165] Fix | Delete
} else {
[166] Fix | Delete
$result = $this->_generic_error_response('theme_not_disabled', array(
[167] Fix | Delete
'theme' => $query['theme'],
[168] Fix | Delete
'error_code' => 'theme_not_disabled',
[169] Fix | Delete
'error_message' => __('There appears to be a problem disabling the intended theme from your network. Please kindly check your permission and try again.', 'updraftplus'),
[170] Fix | Delete
'info' => $this->_get_theme_info($query['theme'])
[171] Fix | Delete
));
[172] Fix | Delete
}
[173] Fix | Delete
} else {
[174] Fix | Delete
$result = $this->_generic_error_response('theme_not_installed', array(
[175] Fix | Delete
'theme' => $query['theme'],
[176] Fix | Delete
'error_code' => 'theme_not_installed',
[177] Fix | Delete
'error_message' => __('The theme you wish to disable from your network is either not installed or has been removed recently.', 'updraftplus'),
[178] Fix | Delete
'info' => $info
[179] Fix | Delete
));
[180] Fix | Delete
}
[181] Fix | Delete
break;
[182] Fix | Delete
case 'install':
[183] Fix | Delete
$api = themes_api('theme_information', array(
[184] Fix | Delete
'slug' => $query['slug'],
[185] Fix | Delete
'fields' => array(
[186] Fix | Delete
'description' => true,
[187] Fix | Delete
'sections' => false,
[188] Fix | Delete
'rating' => true,
[189] Fix | Delete
'ratings' => true,
[190] Fix | Delete
'downloaded' => true,
[191] Fix | Delete
'downloadlink' => true,
[192] Fix | Delete
'last_updated' => true,
[193] Fix | Delete
'screenshot_url' => true,
[194] Fix | Delete
'parent' => true,
[195] Fix | Delete
)
[196] Fix | Delete
));
[197] Fix | Delete
[198] Fix | Delete
$info = $this->_get_theme_info($query['theme']);
[199] Fix | Delete
if (is_wp_error($api)) {
[200] Fix | Delete
$result = $this->_generic_error_response('generic_response_error', array(
[201] Fix | Delete
'theme' => $query['theme'],
[202] Fix | Delete
'error_code' => 'theme_not_installed',
[203] Fix | Delete
'error_message' => $api->get_error_message(),
[204] Fix | Delete
'info' => $info
[205] Fix | Delete
));
[206] Fix | Delete
} else {
[207] Fix | Delete
$installed = $info['installed'];
[208] Fix | Delete
[209] Fix | Delete
$error_code = $error_message = '';
[210] Fix | Delete
if (!$installed) {
[211] Fix | Delete
// WP < 3.7
[212] Fix | Delete
if (!class_exists('Automatic_Upgrader_Skin')) include_once(dirname(dirname(__FILE__)).'/classes/class-automatic-upgrader-skin.php');
[213] Fix | Delete
[214] Fix | Delete
$skin = new Automatic_Upgrader_Skin();
[215] Fix | Delete
$upgrader = new Theme_Upgrader($skin);
[216] Fix | Delete
[217] Fix | Delete
$download_link = $api->download_link;
[218] Fix | Delete
$installed = $upgrader->install($download_link);
[219] Fix | Delete
[220] Fix | Delete
if (is_wp_error($installed)) {
[221] Fix | Delete
$error_code = $installed->get_error_code();
[222] Fix | Delete
$error_message = $installed->get_error_message();
[223] Fix | Delete
} elseif (is_wp_error($skin->result)) {
[224] Fix | Delete
$error_code = $skin->result->get_error_code();
[225] Fix | Delete
$error_message = $skin->result->get_error_message();
[226] Fix | Delete
[227] Fix | Delete
$error_data = $skin->result->get_error_data($error_code);
[228] Fix | Delete
if (!empty($error_data)) {
[229] Fix | Delete
if (is_array($error_data)) $error_data = json_encode($error_data);
[230] Fix | Delete
$error_message .= ' '.$error_data;
[231] Fix | Delete
}
[232] Fix | Delete
} elseif (is_null($installed) || !$installed) {
[233] Fix | Delete
global $wp_filesystem;
[234] Fix | Delete
$upgrade_messages = $skin->get_upgrade_messages();
[235] Fix | Delete
[236] Fix | Delete
if (!class_exists('WP_Filesystem_Base')) include_once(ABSPATH.'/wp-admin/includes/class-wp-filesystem-base.php');
[237] Fix | Delete
[238] Fix | Delete
// Pass through the error from WP_Filesystem if one was raised.
[239] Fix | Delete
if ($wp_filesystem instanceof WP_Filesystem_Base && is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
[240] Fix | Delete
$error_code = $wp_filesystem->errors->get_error_code();
[241] Fix | Delete
$error_message = $wp_filesystem->errors->get_error_message();
[242] Fix | Delete
} elseif (!empty($upgrade_messages)) {
[243] Fix | Delete
// We're only after for the last feedback that we received from the install process. Mostly,
[244] Fix | Delete
// that is where the last error has been inserted.
[245] Fix | Delete
$messages = $skin->get_upgrade_messages();
[246] Fix | Delete
$error_code = 'install_failed';
[247] Fix | Delete
$error_message = end($messages);
[248] Fix | Delete
} else {
[249] Fix | Delete
$error_code = 'unable_to_connect_to_filesystem';
[250] Fix | Delete
$error_message = __('Unable to connect to the filesystem. Please confirm your credentials.');
[251] Fix | Delete
}
[252] Fix | Delete
}
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
if (!$installed || is_wp_error($installed)) {
[256] Fix | Delete
$result = $this->_generic_error_response('theme_install_failed', array(
[257] Fix | Delete
'theme' => $query['theme'],
[258] Fix | Delete
'error_code' => $error_code,
[259] Fix | Delete
'error_message' => $error_message,
[260] Fix | Delete
'info' => $this->_get_theme_info($query['theme'])
[261] Fix | Delete
));
[262] Fix | Delete
} else {
[263] Fix | Delete
$result = array('installed' => true, 'info' => $this->_get_theme_info($query['theme']));
[264] Fix | Delete
}
[265] Fix | Delete
}
[266] Fix | Delete
break;
[267] Fix | Delete
}
[268] Fix | Delete
[269] Fix | Delete
return $result;
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
/**
[273] Fix | Delete
* Preloads the submitted credentials to the global $_POST variable
[274] Fix | Delete
*
[275] Fix | Delete
* @param array $query Parameter array containing information for the currently requested action
[276] Fix | Delete
*/
[277] Fix | Delete
private function _preload_credentials($query) {
[278] Fix | Delete
if (!empty($query) && isset($query['filesystem_credentials'])) {
[279] Fix | Delete
parse_str($query['filesystem_credentials'], $filesystem_credentials);
[280] Fix | Delete
if (is_array($filesystem_credentials)) {
[281] Fix | Delete
foreach ($filesystem_credentials as $key => $value) {
[282] Fix | Delete
// Put them into $_POST, which is where request_filesystem_credentials() checks for them.
[283] Fix | Delete
$_POST[$key] = $value;
[284] Fix | Delete
}
[285] Fix | Delete
}
[286] Fix | Delete
}
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
/**
[290] Fix | Delete
* Checks whether we have the required fields submitted and the user has
[291] Fix | Delete
* the capabilities to execute the requested action
[292] Fix | Delete
*
[293] Fix | Delete
* @param array $query The submitted information
[294] Fix | Delete
* @param array $fields The required fields to check
[295] Fix | Delete
* @param array $capabilities The capabilities to check and validate
[296] Fix | Delete
*
[297] Fix | Delete
* @return array|string
[298] Fix | Delete
*/
[299] Fix | Delete
private function _validate_fields_and_capabilities($query, $fields, $capabilities) {
[300] Fix | Delete
[301] Fix | Delete
$error = '';
[302] Fix | Delete
if (!empty($fields)) {
[303] Fix | Delete
for ($i=0; $i<count($fields); $i++) {
[304] Fix | Delete
$field = $fields[$i];
[305] Fix | Delete
[306] Fix | Delete
if (!isset($query[$field])) {
[307] Fix | Delete
if ('keyword' === $field) {
[308] Fix | Delete
$error = $this->_generic_error_response('keyword_required');
[309] Fix | Delete
} else {
[310] Fix | Delete
$error = $this->_generic_error_response('theme_'.$query[$field].'_required');
[311] Fix | Delete
}
[312] Fix | Delete
break;
[313] Fix | Delete
}
[314] Fix | Delete
}
[315] Fix | Delete
}
[316] Fix | Delete
[317] Fix | Delete
if (empty($error) && !empty($capabilities)) {
[318] Fix | Delete
for ($i=0; $i<count($capabilities); $i++) {
[319] Fix | Delete
if (!current_user_can($capabilities[$i])) {
[320] Fix | Delete
$error = $this->_generic_error_response('theme_insufficient_permission');
[321] Fix | Delete
break;
[322] Fix | Delete
}
[323] Fix | Delete
}
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
return $error;
[327] Fix | Delete
}
[328] Fix | Delete
[329] Fix | Delete
/**
[330] Fix | Delete
* Activates the theme
[331] Fix | Delete
*
[332] Fix | Delete
* @param array $query Parameter array containing the name of the theme to activate
[333] Fix | Delete
* @return array Contains the result of the current process
[334] Fix | Delete
*/
[335] Fix | Delete
public function activate_theme($query) {
[336] Fix | Delete
[337] Fix | Delete
$error = $this->_validate_fields_and_capabilities($query, array('theme'), array('switch_themes'));
[338] Fix | Delete
if (!empty($error)) {
[339] Fix | Delete
return $error;
[340] Fix | Delete
}
[341] Fix | Delete
[342] Fix | Delete
$result = $this->_apply_theme_action('activate', $query);
[343] Fix | Delete
if (empty($result['activated'])) {
[344] Fix | Delete
return $result;
[345] Fix | Delete
}
[346] Fix | Delete
[347] Fix | Delete
return $this->_response($result);
[348] Fix | Delete
}
[349] Fix | Delete
[350] Fix | Delete
/**
[351] Fix | Delete
* Enables theme for network
[352] Fix | Delete
*
[353] Fix | Delete
* @param array $query Parameter array containing the name of the theme to activate
[354] Fix | Delete
* @return array Contains the result of the current process
[355] Fix | Delete
*/
[356] Fix | Delete
public function network_enable_theme($query) {
[357] Fix | Delete
[358] Fix | Delete
$error = $this->_validate_fields_and_capabilities($query, array('theme'), array('switch_themes'));
[359] Fix | Delete
if (!empty($error)) {
[360] Fix | Delete
return $error;
[361] Fix | Delete
}
[362] Fix | Delete
[363] Fix | Delete
$result = $this->_apply_theme_action('network_enable', $query);
[364] Fix | Delete
if (empty($result['enabled'])) {
[365] Fix | Delete
return $result;
[366] Fix | Delete
}
[367] Fix | Delete
[368] Fix | Delete
return $this->_response($result);
[369] Fix | Delete
}
[370] Fix | Delete
[371] Fix | Delete
/**
[372] Fix | Delete
* Disables theme from network
[373] Fix | Delete
*
[374] Fix | Delete
* @param array $query Parameter array containing the name of the theme to activate
[375] Fix | Delete
* @return array Contains the result of the current process
[376] Fix | Delete
*/
[377] Fix | Delete
public function network_disable_theme($query) {
[378] Fix | Delete
[379] Fix | Delete
$error = $this->_validate_fields_and_capabilities($query, array('theme'), array('switch_themes'));
[380] Fix | Delete
if (!empty($error)) {
[381] Fix | Delete
return $error;
[382] Fix | Delete
}
[383] Fix | Delete
[384] Fix | Delete
$result = $this->_apply_theme_action('network_disable', $query);
[385] Fix | Delete
if (empty($result['disabled'])) {
[386] Fix | Delete
return $result;
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
return $this->_response($result);
[390] Fix | Delete
}
[391] Fix | Delete
[392] Fix | Delete
/**
[393] Fix | Delete
* Download, install and activates the theme
[394] Fix | Delete
*
[395] Fix | Delete
* @param array $query Parameter array containing the filesystem credentials entered by the user along with the theme name and slug
[396] Fix | Delete
* @return array Contains the result of the current process
[397] Fix | Delete
*/
[398] Fix | Delete
public function install_activate_theme($query) {
[399] Fix | Delete
[400] Fix | Delete
$error = $this->_validate_fields_and_capabilities($query, array('theme', 'slug'), array('install_themes', 'switch_themes'));
[401] Fix | Delete
if (!empty($error)) {
[402] Fix | Delete
return $error;
[403] Fix | Delete
}
[404] Fix | Delete
[405] Fix | Delete
$this->_preload_credentials($query);
[406] Fix | Delete
[407] Fix | Delete
$result = $this->_apply_theme_action('install', $query);
[408] Fix | Delete
if (!empty($result['installed']) && $result['installed']) {
[409] Fix | Delete
$result = $this->_apply_theme_action('activate', $query);
[410] Fix | Delete
if (empty($result['activated'])) {
[411] Fix | Delete
return $result;
[412] Fix | Delete
}
[413] Fix | Delete
} else {
[414] Fix | Delete
return $result;
[415] Fix | Delete
}
[416] Fix | Delete
[417] Fix | Delete
return $this->_response($result);
[418] Fix | Delete
}
[419] Fix | Delete
[420] Fix | Delete
/**
[421] Fix | Delete
* Download, install the theme
[422] Fix | Delete
*
[423] Fix | Delete
* @param array $query Parameter array containing the filesystem credentials entered by the user along with the theme name and slug
[424] Fix | Delete
* @return array Contains the result of the current process
[425] Fix | Delete
*/
[426] Fix | Delete
public function install_theme($query) {
[427] Fix | Delete
[428] Fix | Delete
$error = $this->_validate_fields_and_capabilities($query, array('theme', 'slug'), array('install_themes'));
[429] Fix | Delete
if (!empty($error)) {
[430] Fix | Delete
return $error;
[431] Fix | Delete
}
[432] Fix | Delete
[433] Fix | Delete
$this->_preload_credentials($query);
[434] Fix | Delete
[435] Fix | Delete
$result = $this->_apply_theme_action('install', $query);
[436] Fix | Delete
if (empty($result['installed'])) {
[437] Fix | Delete
return $result;
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
return $this->_response($result);
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
/**
[444] Fix | Delete
* Uninstall/delete the theme
[445] Fix | Delete
*
[446] Fix | Delete
* @param array $query Parameter array containing the filesystem credentials entered by the user along with the theme name and slug
[447] Fix | Delete
* @return array Contains the result of the current process
[448] Fix | Delete
*/
[449] Fix | Delete
public function delete_theme($query) {
[450] Fix | Delete
[451] Fix | Delete
$error = $this->_validate_fields_and_capabilities($query, array('theme'), array('delete_themes'));
[452] Fix | Delete
if (!empty($error)) {
[453] Fix | Delete
return $error;
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
$this->_preload_credentials($query);
[457] Fix | Delete
$info = $this->_get_theme_info($query['theme']);
[458] Fix | Delete
[459] Fix | Delete
if ($info['installed']) {
[460] Fix | Delete
$deleted = delete_theme($info['slug']);
[461] Fix | Delete
[462] Fix | Delete
if ($deleted) {
[463] Fix | Delete
$result = array('deleted' => true, 'info' => $this->_get_theme_info($query['theme']));
[464] Fix | Delete
} else {
[465] Fix | Delete
$result = $this->_generic_error_response('delete_theme_failed', array(
[466] Fix | Delete
'theme' => $query['theme'],
[467] Fix | Delete
'error_code' => 'delete_theme_failed',
[468] Fix | Delete
'info' => $info
[469] Fix | Delete
));
[470] Fix | Delete
}
[471] Fix | Delete
} else {
[472] Fix | Delete
$result = $this->_generic_error_response('theme_not_installed', array(
[473] Fix | Delete
'theme' => $query['theme'],
[474] Fix | Delete
'error_code' => 'theme_not_installed',
[475] Fix | Delete
'info' => $info
[476] Fix | Delete
));
[477] Fix | Delete
}
[478] Fix | Delete
[479] Fix | Delete
return $this->_response($result);
[480] Fix | Delete
}
[481] Fix | Delete
[482] Fix | Delete
/**
[483] Fix | Delete
* Updates/upgrade the theme
[484] Fix | Delete
*
[485] Fix | Delete
* @param array $query Parameter array containing the filesystem credentials entered by the user along with the theme name and slug
[486] Fix | Delete
* @return array Contains the result of the current process
[487] Fix | Delete
*/
[488] Fix | Delete
public function update_theme($query) {
[489] Fix | Delete
[490] Fix | Delete
$error = $this->_validate_fields_and_capabilities($query, array('theme'), array('update_themes'));
[491] Fix | Delete
if (!empty($error)) {
[492] Fix | Delete
return $error;
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
$this->_preload_credentials($query);
[496] Fix | Delete
$info = $this->_get_theme_info($query['theme']);
[497] Fix | Delete
[498] Fix | Delete
// Make sure that we still have the theme installed before running
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function