| 1 |
<?php |
| 2 |
// @codingStandardsIgnoreFile |
| 3 |
if (!defined('ABSPATH')) die('No direct access.'); |
| 4 |
|
| 5 |
// Extracted from 4.5.2/wordpress/wp-admin/includes/class-wp-upgrader-skins.php; with the bulk_*() methods added since they are not in the base class on all WP versions. |
| 6 |
// Needed only on WP < 3.7 |
| 7 |
|
| 8 |
/** |
| 9 |
* Upgrader Skin for Automatic WordPress Upgrades |
| 10 |
* |
| 11 |
* Extracted from 4.5.2/wordpress/wp-admin/includes/class-wp-upgrader-skins.php; with the bulk_*() methods added since they are not in the base class on all WP versions. |
| 12 |
* Needed only on WP < 3.7 |
| 13 |
* |
| 14 |
* This skin is designed to be used when no output is intended, all output |
| 15 |
* is captured and stored for the caller to process and log/email/discard. |
| 16 |
* |
| 17 |
* @package WordPress |
| 18 |
* @subpackage Upgrader |
| 19 |
* @since 3.7.0 |
| 20 |
*/ |
| 21 |
class Automatic_Upgrader_Skin_Main extends WP_Upgrader_Skin { |
| 22 |
|
| 23 |
protected $messages = array(); |
| 24 |
|
| 25 |
/** |
| 26 |
* Request filesystem credentials |
| 27 |
* |
| 28 |
* @param bool $error Check if there is an error: default is false |
| 29 |
* @param string $context Context for credentials |
| 30 |
* @param bool $allow_relaxed_file_ownership Check if relaxed file ownership is allowed |
| 31 |
* @return bool |
| 32 |
*/ |
| 33 |
public function request_filesystem_credentials($error = false, $context = '', $allow_relaxed_file_ownership = false) { |
| 34 |
if ($context) { |
| 35 |
$this->options['context'] = $context; |
| 36 |
} |
| 37 |
// TODO: fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version |
| 38 |
// This will output a credentials form in event of failure, We don't want that, so just hide with a buffer |
| 39 |
ob_start(); |
| 40 |
$result = parent::request_filesystem_credentials($error, $context, $allow_relaxed_file_ownership); |
| 41 |
ob_end_clean(); |
| 42 |
return $result; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Get update message |
| 47 |
* |
| 48 |
* @return array reti=urns an array of messages |
| 49 |
*/ |
| 50 |
public function get_upgrade_messages() { |
| 51 |
return $this->messages; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Feedback |
| 56 |
* |
| 57 |
* @param string|array|WP_Error $data THis is the data to be used for the feedback |
| 58 |
*/ |
| 59 |
protected function updraft_feedback($data) { |
| 60 |
if (is_wp_error($data)) { |
| 61 |
$string = $data->get_error_message(); |
| 62 |
} elseif (is_array($data)) { |
| 63 |
return; |
| 64 |
} else { |
| 65 |
$string = $data; |
| 66 |
} |
| 67 |
if (!empty($this->upgrader->strings[$string])) |
| 68 |
$string = $this->upgrader->strings[$string]; |
| 69 |
|
| 70 |
if (false !== strpos($string, '%')) { |
| 71 |
$args = func_get_args(); |
| 72 |
$args = array_splice($args, 1); |
| 73 |
if (!empty($args)) |
| 74 |
$string = vsprintf($string, $args); |
| 75 |
} |
| 76 |
|
| 77 |
$string = trim($string); |
| 78 |
|
| 79 |
// Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output. |
| 80 |
$string = wp_kses($string, array( |
| 81 |
'a' => array( |
| 82 |
'href' => true |
| 83 |
), |
| 84 |
'br' => true, |
| 85 |
'em' => true, |
| 86 |
'strong' => true, |
| 87 |
)); |
| 88 |
|
| 89 |
if (empty($string)) |
| 90 |
return; |
| 91 |
|
| 92 |
$this->messages[] = $string; |
| 93 |
} |
| 94 |
|
| 95 |
public function header() { |
| 96 |
ob_start(); |
| 97 |
} |
| 98 |
|
| 99 |
public function footer() { |
| 100 |
$output = ob_get_clean(); |
| 101 |
if (!empty($output)) |
| 102 |
$this->feedback($output); |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* @access public |
| 107 |
*/ |
| 108 |
public function bulk_header() {} |
| 109 |
|
| 110 |
public function bulk_footer() { |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
global $updraftcentral_main; |
| 115 |
$wp_version = $updraftcentral_main->get_wordpress_version(); |
| 116 |
|
| 117 |
if (version_compare($wp_version, '5.3', '>=')) { |
| 118 |
if (!class_exists('Automatic_Upgrader_Skin')) require_once(dirname(__FILE__).'/automatic-upgrader-skin-compatibility.php'); |
| 119 |
} else { |
| 120 |
class Automatic_Upgrader_Skin extends Automatic_Upgrader_Skin_Main { |
| 121 |
|
| 122 |
public function feedback($string) { |
| 123 |
parent::updraft_feedback($string); |
| 124 |
} |
| 125 |
} |
| 126 |
} |