PluginProbe
ManageWP Worker / 4.9.32
ManageWP Worker v4.9.32
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / MWP / Updater / TraceableUpdaterSkin.php

TraceableUpdaterSkin.php in ManageWP Worker 4.9.32, at src/MWP/Updater/TraceableUpdaterSkin.php

203 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * This file is part of the ManageWP Worker plugin.
4 *
5 * (c) ManageWP LLC <[email protected]>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 /**
12 * Taken from WordPress's automatic updater skin, which was added in version 3.7.
13 *
14 * @see Automatic_Upgrader_Skin
15 */
16 class MWP_Updater_TraceableUpdaterSkin
17 {
18
19 public $options = array(
20 'url' => '',
21 'nonce' => '',
22 'title' => '',
23 'context' => false,
24 );
25
26 public $upgrader;
27
28 public $result;
29
30 public $done_header = false;
31
32 protected $messages = array();
33
34 private $startedImplicit = false;
35
36 public function request_filesystem_credentials($error = false, $context = '', $allow_relaxed_file_ownership = false)
37 {
38 if ($error instanceof WP_Error) {
39 throw new MWP_Worker_Exception(MWP_Worker_Exception::FILESYSTEM_CREDENTIALS_ERROR, $error->get_error_message());
40 }
41
42 if ($context) {
43 $this->options['context'] = $context;
44 }
45
46 // file.php and template.php are documented to be required; the rest are there to match
47 // the list in the MMB_Installer class.
48 require_once ABSPATH.'wp-admin/includes/file.php';
49 require_once ABSPATH.'wp-admin/includes/plugin.php';
50 require_once ABSPATH.'wp-admin/includes/theme.php';
51 require_once ABSPATH.'wp-admin/includes/misc.php';
52 require_once ABSPATH.'wp-admin/includes/template.php';
53 require_once ABSPATH.'wp-admin/includes/class-wp-upgrader.php';
54 // This will output a credentials form in event of failure; we don't want that, so just hide with a buffer.
55 ob_start();
56 /** @handled function */
57 $result = request_filesystem_credentials('', '', $error, $context, null, $allow_relaxed_file_ownership);
58 ob_end_clean();
59
60 return $result;
61 }
62
63 public function get_upgrade_messages()
64 {
65 return $this->messages;
66 }
67
68 /**
69 * @param string|array|WP_Error $data
70 */
71 public function feedback($data)
72 {
73 if (!$this->startedImplicit) {
74 $this->startedImplicit = true;
75 @ob_implicit_flush(true);
76 }
77
78 echo ' ';
79 @ob_flush();
80
81 if (is_wp_error($data)) {
82 $string = $data->get_error_message();
83 } else {
84 if (is_array($data)) {
85 return;
86 } else {
87 $string = $data;
88 }
89 }
90
91 if (!empty($this->upgrader->strings[$string])) {
92 $string = $this->upgrader->strings[$string];
93 }
94
95 if (strpos($string, '%') !== false) {
96 $args = func_get_args();
97 $args = array_splice($args, 1);
98 if (!empty($args)) {
99 $string = vsprintf($string, $args);
100 }
101 }
102
103 $string = trim($string);
104
105 /** @handled function */
106 // Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
107 $string = wp_kses($string, array(
108 'a' => array(
109 'href' => true
110 ),
111 'br' => true,
112 'em' => true,
113 'strong' => true,
114 ));
115
116 if (empty($string)) {
117 return;
118 }
119
120 $this->messages[] = array(
121 'message' => $string,
122 'key' => $data,
123 'args' => isset($args) ? $args : array(),
124 );
125 }
126
127 public function header()
128 {
129 ob_start();
130 }
131
132 public function footer()
133 {
134 $output = ob_get_contents();
135 if (!empty($output)) {
136 $this->feedback($output);
137 ob_end_clean();
138 }
139 }
140
141 public function bulk_header()
142 {
143 }
144
145 public function bulk_footer()
146 {
147 }
148
149 public function before()
150 {
151 }
152
153 public function after()
154 {
155 }
156
157 // Below was taken from WP_Upgrader_Skin, so we don't autoload it and cause trouble.
158 public function decrement_update_count()
159 {
160 }
161
162 public function error($errors)
163 {
164 if (is_string($errors)) {
165 $this->feedback($errors);
166
167 return;
168 }
169
170 if (!$errors instanceof WP_Error || !$errors->get_error_code()) {
171 return;
172 }
173
174 foreach ($errors->get_error_messages() as $message) {
175 if ($errors->get_error_data() && is_string($errors->get_error_data())) {
176 $this->feedback($message.' '.esc_html(strip_tags($errors->get_error_data())));
177 } else {
178 $this->feedback($message);
179 }
180 }
181 }
182
183 /**
184 * @param WP_Upgrader $upgrader
185 */
186 public function set_upgrader($upgrader)
187 {
188 if (is_object($upgrader)) {
189 $this->upgrader = $upgrader;
190 }
191 $this->add_strings();
192 }
193
194 public function add_strings()
195 {
196 }
197
198 public function set_result($result)
199 {
200 $this->result = $result;
201 }
202 }
203