3
* Upgrader API: WP_Upgrader_Skin class
11
* Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes.
14
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
16
class WP_Upgrader_Skin {
19
public $done_header = false;
20
public $done_footer = false;
23
* Holds the result of an upgrade.
27
* @var string|bool|WP_Error
29
public $result = false;
30
public $options = array();
36
public function __construct($args = array()) {
37
$defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
38
$this->options = wp_parse_args($args, $defaults);
42
* @param WP_Upgrader $upgrader
44
public function set_upgrader(&$upgrader) {
45
if ( is_object($upgrader) )
46
$this->upgrader =& $upgrader;
53
public function add_strings() {
57
* Sets the result of an upgrade.
62
* @param string|bool|WP_Error $result The result of an upgrade.
64
public function set_result( $result ) {
65
$this->result = $result;
69
* Displays a form to the user to request for their FTP/SSH details in order
70
* to connect to the filesystem.
73
* @since 4.6.0 The `$context` parameter default changed from `false` to an empty string.
75
* @see request_filesystem_credentials()
77
* @param bool $error Optional. Whether the current request has failed to connect.
79
* @param string $context Optional. Full path to the directory that is tested
80
* for being writable. Default empty.
81
* @param bool $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false.
82
* @return bool False on failure, true on success.
84
public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
85
$url = $this->options['url'];
87
$context = $this->options['context'];
89
if ( !empty($this->options['nonce']) ) {
90
$url = wp_nonce_url($url, $this->options['nonce']);
93
$extra_fields = array();
95
return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership );
101
public function header() {
102
if ( $this->done_header ) {
105
$this->done_header = true;
106
echo '<div class="wrap">';
107
echo '<h1>' . $this->options['title'] . '</h1>';
113
public function footer() {
114
if ( $this->done_footer ) {
117
$this->done_footer = true;
123
* @param string|WP_Error $errors
125
public function error($errors) {
126
if ( ! $this->done_header )
128
if ( is_string($errors) ) {
129
$this->feedback($errors);
130
} elseif ( is_wp_error($errors) && $errors->get_error_code() ) {
131
foreach ( $errors->get_error_messages() as $message ) {
132
if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) )
133
$this->feedback($message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) );
135
$this->feedback($message);
142
* @param string $string
144
public function feedback($string) {
145
if ( isset( $this->upgrader->strings[$string] ) )
146
$string = $this->upgrader->strings[$string];
148
if ( strpos($string, '%') !== false ) {
149
$args = func_get_args();
150
$args = array_splice($args, 1);
152
$args = array_map( 'strip_tags', $args );
153
$args = array_map( 'esc_html', $args );
154
$string = vsprintf($string, $args);
157
if ( empty($string) )
159
show_message($string);
165
public function before() {}
170
public function after() {}
173
* Output JavaScript that calls function to decrement the update counts.
177
* @param string $type Type of update count to decrement. Likely values include 'plugin',
178
* 'theme', 'translation', etc.
180
protected function decrement_update_count( $type ) {
181
if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) {
185
if ( defined( 'IFRAME_REQUEST' ) ) {
186
echo '<script type="text/javascript">
187
if ( window.postMessage && JSON ) {
188
window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname );
192
echo '<script type="text/javascript">
194
if ( wp && wp.updates.decrementCount ) {
195
wp.updates.decrementCount( "' . $type . '" );
205
public function bulk_header() {}
210
public function bulk_footer() {}