PluginProbe
ManageWP Worker / 4.9.36
ManageWP Worker v4.9.36
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.36, at src/MWP/Updater/TraceableUpdaterSkin.php

208 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 /**
33 * @var bool Whether the plugin is currently active
34 */
35 public $plugin_active;
36
37 protected $messages = array();
38
39 private $startedImplicit = false;
40
41 public function request_filesystem_credentials($error = false, $context = '', $allow_relaxed_file_ownership = false)
42 {
43 if ($error instanceof WP_Error) {
44 throw new MWP_Worker_Exception(MWP_Worker_Exception::FILESYSTEM_CREDENTIALS_ERROR, $error->get_error_message());
45 }
46
47 if ($context) {
48 $this->options['context'] = $context;
49 }
50
51 // file.php and template.php are documented to be required; the rest are there to match
52 // the list in the MMB_Installer class.
53 require_once ABSPATH.'wp-admin/includes/file.php';
54 require_once ABSPATH.'wp-admin/includes/plugin.php';
55 require_once ABSPATH.'wp-admin/includes/theme.php';
56 require_once ABSPATH.'wp-admin/includes/misc.php';
57 require_once ABSPATH.'wp-admin/includes/template.php';
58 require_once ABSPATH.'wp-admin/includes/class-wp-upgrader.php';
59 // This will output a credentials form in event of failure; we don't want that, so just hide with a buffer.
60 ob_start();
61 /** @handled function */
62 $result = request_filesystem_credentials('', '', $error, $context, null, $allow_relaxed_file_ownership);
63 ob_end_clean();
64
65 return $result;
66 }
67
68 public function get_upgrade_messages()
69 {
70 return $this->messages;
71 }
72
73 /**
74 * @param string|array|WP_Error $data
75 */
76 public function feedback($data)
77 {
78 if (!$this->startedImplicit) {
79 $this->startedImplicit = true;
80 @ob_implicit_flush(true);
81 }
82
83 echo ' ';
84 @ob_flush();
85
86 if (is_wp_error($data)) {
87 $string = $data->get_error_message();
88 } else {
89 if (is_array($data)) {
90 return;
91 } else {
92 $string = $data;
93 }
94 }
95
96 if (!empty($this->upgrader->strings[$string])) {
97 $string = $this->upgrader->strings[$string];
98 }
99
100 if (strpos($string, '%') !== false) {
101 $args = func_get_args();
102 $args = array_splice($args, 1);
103 if (!empty($args)) {
104 $string = vsprintf($string, $args);
105 }
106 }
107
108 $string = trim($string);
109
110 /** @handled function */
111 // Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
112 $string = wp_kses($string, array(
113 'a' => array(
114 'href' => true
115 ),
116 'br' => true,
117 'em' => true,
118 'strong' => true,
119 ));
120
121 if (empty($string)) {
122 return;
123 }
124
125 $this->messages[] = array(
126 'message' => $string,
127 'key' => $data,
128 'args' => isset($args) ? $args : array(),
129 );
130 }
131
132 public function header()
133 {
134 ob_start();
135 }
136
137 public function footer()
138 {
139 $output = ob_get_contents();
140 if (!empty($output)) {
141 $this->feedback($output);
142 ob_end_clean();
143 }
144 }
145
146 public function bulk_header()
147 {
148 }
149
150 public function bulk_footer()
151 {
152 }
153
154 public function before()
155 {
156 }
157
158 public function after()
159 {
160 }
161
162 // Below was taken from WP_Upgrader_Skin, so we don't autoload it and cause trouble.
163 public function decrement_update_count()
164 {
165 }
166
167 public function error($errors)
168 {
169 if (is_string($errors)) {
170 $this->feedback($errors);
171
172 return;
173 }
174
175 if (!$errors instanceof WP_Error || !$errors->get_error_code()) {
176 return;
177 }
178
179 foreach ($errors->get_error_messages() as $message) {
180 if ($errors->get_error_data() && is_string($errors->get_error_data())) {
181 $this->feedback($message.' '.esc_html(strip_tags($errors->get_error_data())));
182 } else {
183 $this->feedback($message);
184 }
185 }
186 }
187
188 /**
189 * @param WP_Upgrader $upgrader
190 */
191 public function set_upgrader($upgrader)
192 {
193 if (is_object($upgrader)) {
194 $this->upgrader = $upgrader;
195 }
196 $this->add_strings();
197 }
198
199 public function add_strings()
200 {
201 }
202
203 public function set_result($result)
204 {
205 $this->result = $result;
206 }
207 }
208