PluginProbe
ManageWP Worker / trunk
ManageWP Worker vtrunk
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 trunk, at src/MWP/Updater/TraceableUpdaterSkin.php

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