* This file is part of the ManageWP Worker plugin.
* (c) ManageWP LLC <contact@managewp.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
* Taken from WordPress's automatic updater skin, which was added in version 3.7.
* @see Automatic_Upgrader_Skin
class MWP_Updater_TraceableUpdaterSkin
public $done_header = false;
protected $messages = array();
private $startedImplicit = false;
public function request_filesystem_credentials($error = false, $context = '', $allow_relaxed_file_ownership = false)
if ($error instanceof WP_Error) {
throw new MWP_Worker_Exception(MWP_Worker_Exception::FILESYSTEM_CREDENTIALS_ERROR, $error->get_error_message());
$this->options['context'] = $context;
// file.php and template.php are documented to be required; the rest are there to match
// the list in the MMB_Installer class.
require_once ABSPATH.'wp-admin/includes/file.php';
require_once ABSPATH.'wp-admin/includes/plugin.php';
require_once ABSPATH.'wp-admin/includes/theme.php';
require_once ABSPATH.'wp-admin/includes/misc.php';
require_once ABSPATH.'wp-admin/includes/template.php';
require_once ABSPATH.'wp-admin/includes/class-wp-upgrader.php';
// This will output a credentials form in event of failure; we don't want that, so just hide with a buffer.
$result = request_filesystem_credentials('', '', $error, $context, null, $allow_relaxed_file_ownership);
public function get_upgrade_messages()
* @param string|array|WP_Error $data
public function feedback($data)
if (!$this->startedImplicit) {
$this->startedImplicit = true;
@ob_implicit_flush(true);
if (is_wp_error($data)) {
$string = $data->get_error_message();
if (!empty($this->upgrader->strings[$string])) {
$string = $this->upgrader->strings[$string];
if (strpos($string, '%') !== false) {
$args = array_splice($args, 1);
$string = vsprintf($string, $args);
// Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
$string = wp_kses($string, array(
$this->messages[] = array(
'args' => isset($args) ? $args : array(),
$output = ob_get_contents();
$this->feedback($output);
public function bulk_header()
public function bulk_footer()
// Below was taken from WP_Upgrader_Skin, so we don't autoload it and cause trouble.
public function decrement_update_count()
public function error($errors)
if (is_string($errors)) {
$this->feedback($errors);
if (!$errors instanceof WP_Error || !$errors->get_error_code()) {
foreach ($errors->get_error_messages() as $message) {
if ($errors->get_error_data() && is_string($errors->get_error_data())) {
$this->feedback($message.' '.esc_html(strip_tags($errors->get_error_data())));
$this->feedback($message);
* @param WP_Upgrader $upgrader
public function set_upgrader($upgrader)
if (is_object($upgrader)) {
$this->upgrader = $upgrader;
public function add_strings()
public function set_result($result)