13 * @since 2.8.0 |
13 * @since 2.8.0 |
14 * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php. |
14 * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php. |
15 */ |
15 */ |
16 class WP_Upgrader_Skin { |
16 class WP_Upgrader_Skin { |
17 |
17 |
|
18 /** |
|
19 * Holds the upgrader data. |
|
20 * |
|
21 * @since 2.8.0 |
|
22 * |
|
23 * @var object |
|
24 */ |
18 public $upgrader; |
25 public $upgrader; |
|
26 |
|
27 /** |
|
28 * Whether header is done. |
|
29 * |
|
30 * @since 2.8.0 |
|
31 * |
|
32 * @var bool |
|
33 */ |
19 public $done_header = false; |
34 public $done_header = false; |
|
35 |
|
36 /** |
|
37 * Whether footer is done. |
|
38 * |
|
39 * @since 2.8.0 |
|
40 * |
|
41 * @var bool |
|
42 */ |
20 public $done_footer = false; |
43 public $done_footer = false; |
21 |
44 |
22 /** |
45 /** |
23 * Holds the result of an upgrade. |
46 * Holds the result of an upgrade. |
24 * |
47 * |
25 * @since 2.8.0 |
48 * @since 2.8.0 |
|
49 * |
26 * @var string|bool|WP_Error |
50 * @var string|bool|WP_Error |
27 */ |
51 */ |
28 public $result = false; |
52 public $result = false; |
|
53 |
|
54 /** |
|
55 * Holds the options of an upgrade. |
|
56 * |
|
57 * @since 2.8.0 |
|
58 * |
|
59 * @var array |
|
60 */ |
29 public $options = array(); |
61 public $options = array(); |
30 |
62 |
31 /** |
63 /** |
32 * @param array $args |
64 * Constructor. |
|
65 * |
|
66 * Sets up the generic skin for the WordPress Upgrader classes. |
|
67 * |
|
68 * @since 2.8.0 |
|
69 * |
|
70 * @param array $args Optional. The WordPress upgrader skin arguments to |
|
71 * override default options. Default empty array. |
33 */ |
72 */ |
34 public function __construct( $args = array() ) { |
73 public function __construct( $args = array() ) { |
35 $defaults = array( |
74 $defaults = array( |
36 'url' => '', |
75 'url' => '', |
37 'nonce' => '', |
76 'nonce' => '', |
74 * @since 2.8.0 |
113 * @since 2.8.0 |
75 * @since 4.6.0 The `$context` parameter default changed from `false` to an empty string. |
114 * @since 4.6.0 The `$context` parameter default changed from `false` to an empty string. |
76 * |
115 * |
77 * @see request_filesystem_credentials() |
116 * @see request_filesystem_credentials() |
78 * |
117 * |
79 * @param bool $error Optional. Whether the current request has failed to connect. |
118 * @param bool|WP_Error $error Optional. Whether the current request has failed to connect, |
80 * Default false. |
119 * or an error object. Default false. |
81 * @param string $context Optional. Full path to the directory that is tested |
120 * @param string $context Optional. Full path to the directory that is tested |
82 * for being writable. Default empty. |
121 * for being writable. Default empty. |
83 * @param bool $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false. |
122 * @param bool $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false. |
84 * @return bool False on failure, true on success. |
123 * @return bool True on success, false on failure. |
85 */ |
124 */ |
86 public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) { |
125 public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) { |
87 $url = $this->options['url']; |
126 $url = $this->options['url']; |
88 if ( ! $context ) { |
127 if ( ! $context ) { |
89 $context = $this->options['context']; |
128 $context = $this->options['context']; |
138 } |
177 } |
139 } |
178 } |
140 |
179 |
141 /** |
180 /** |
142 * @param string $string |
181 * @param string $string |
143 */ |
182 * @param mixed ...$args Optional text replacements. |
144 public function feedback( $string ) { |
183 */ |
|
184 public function feedback( $string, ...$args ) { |
145 if ( isset( $this->upgrader->strings[ $string ] ) ) { |
185 if ( isset( $this->upgrader->strings[ $string ] ) ) { |
146 $string = $this->upgrader->strings[ $string ]; |
186 $string = $this->upgrader->strings[ $string ]; |
147 } |
187 } |
148 |
188 |
149 if ( strpos( $string, '%' ) !== false ) { |
189 if ( strpos( $string, '%' ) !== false ) { |
150 $args = func_get_args(); |
|
151 $args = array_splice( $args, 1 ); |
|
152 if ( $args ) { |
190 if ( $args ) { |
153 $args = array_map( 'strip_tags', $args ); |
191 $args = array_map( 'strip_tags', $args ); |
154 $args = array_map( 'esc_html', $args ); |
192 $args = array_map( 'esc_html', $args ); |
155 $string = vsprintf( $string, $args ); |
193 $string = vsprintf( $string, $args ); |
156 } |
194 } |
160 } |
198 } |
161 show_message( $string ); |
199 show_message( $string ); |
162 } |
200 } |
163 |
201 |
164 /** |
202 /** |
|
203 * Action to perform before an update. |
|
204 * |
|
205 * @since 2.8.0 |
165 */ |
206 */ |
166 public function before() {} |
207 public function before() {} |
167 |
208 |
168 /** |
209 /** |
|
210 * Action to perform following an update. |
|
211 * |
|
212 * @since 2.8.0 |
169 */ |
213 */ |
170 public function after() {} |
214 public function after() {} |
171 |
215 |
172 /** |
216 /** |
173 * Output JavaScript that calls function to decrement the update counts. |
217 * Output JavaScript that calls function to decrement the update counts. |