[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Upgrader API: WP_Upgrader_Skin class 4 * 5 * @package WordPress 6 * @subpackage Upgrader 7 * @since 4.6.0 8 */ 9 10 /** 11 * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes. 12 * 13 * @since 2.8.0 14 * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php. 15 */ 16 #[AllowDynamicProperties] 17 class WP_Upgrader_Skin { 18 19 /** 20 * Holds the upgrader data. 21 * 22 * @since 2.8.0 23 * 24 * @var WP_Upgrader 25 */ 26 public $upgrader; 27 28 /** 29 * Whether header is done. 30 * 31 * @since 2.8.0 32 * 33 * @var bool 34 */ 35 public $done_header = false; 36 37 /** 38 * Whether footer is done. 39 * 40 * @since 2.8.0 41 * 42 * @var bool 43 */ 44 public $done_footer = false; 45 46 /** 47 * Holds the result of an upgrade. 48 * 49 * @since 2.8.0 50 * 51 * @var string|bool|WP_Error 52 */ 53 public $result = false; 54 55 /** 56 * Holds the options of an upgrade. 57 * 58 * @since 2.8.0 59 * 60 * @var array 61 */ 62 public $options = array(); 63 64 /** 65 * Constructor. 66 * 67 * Sets up the generic skin for the WordPress Upgrader classes. 68 * 69 * @since 2.8.0 70 * 71 * @param array $args Optional. The WordPress upgrader skin arguments to 72 * override default options. Default empty array. 73 */ 74 public function __construct( $args = array() ) { 75 $defaults = array( 76 'url' => '', 77 'nonce' => '', 78 'title' => '', 79 'context' => false, 80 ); 81 $this->options = wp_parse_args( $args, $defaults ); 82 } 83 84 /** 85 * @since 2.8.0 86 * 87 * @param WP_Upgrader $upgrader 88 */ 89 public function set_upgrader( &$upgrader ) { 90 if ( is_object( $upgrader ) ) { 91 $this->upgrader =& $upgrader; 92 } 93 $this->add_strings(); 94 } 95 96 /** 97 * @since 3.0.0 98 */ 99 public function add_strings() { 100 } 101 102 /** 103 * Sets the result of an upgrade. 104 * 105 * @since 2.8.0 106 * 107 * @param string|bool|WP_Error $result The result of an upgrade. 108 */ 109 public function set_result( $result ) { 110 $this->result = $result; 111 } 112 113 /** 114 * Displays a form to the user to request for their FTP/SSH details in order 115 * to connect to the filesystem. 116 * 117 * @since 2.8.0 118 * @since 4.6.0 The `$context` parameter default changed from `false` to an empty string. 119 * 120 * @see request_filesystem_credentials() 121 * 122 * @param bool|WP_Error $error Optional. Whether the current request has failed to connect, 123 * or an error object. Default false. 124 * @param string $context Optional. Full path to the directory that is tested 125 * for being writable. Default empty. 126 * @param bool $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false. 127 * @return bool True on success, false on failure. 128 */ 129 public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) { 130 $url = $this->options['url']; 131 if ( ! $context ) { 132 $context = $this->options['context']; 133 } 134 if ( ! empty( $this->options['nonce'] ) ) { 135 $url = wp_nonce_url( $url, $this->options['nonce'] ); 136 } 137 138 $extra_fields = array(); 139 140 return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership ); 141 } 142 143 /** 144 * @since 2.8.0 145 */ 146 public function header() { 147 if ( $this->done_header ) { 148 return; 149 } 150 $this->done_header = true; 151 echo '<div class="wrap">'; 152 echo '<h1>' . $this->options['title'] . '</h1>'; 153 } 154 155 /** 156 * @since 2.8.0 157 */ 158 public function footer() { 159 if ( $this->done_footer ) { 160 return; 161 } 162 $this->done_footer = true; 163 echo '</div>'; 164 } 165 166 /** 167 * @since 2.8.0 168 * 169 * @param string|WP_Error $errors Errors. 170 */ 171 public function error( $errors ) { 172 if ( ! $this->done_header ) { 173 $this->header(); 174 } 175 if ( is_string( $errors ) ) { 176 $this->feedback( $errors ); 177 } elseif ( is_wp_error( $errors ) && $errors->has_errors() ) { 178 foreach ( $errors->get_error_messages() as $message ) { 179 if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) ) { 180 $this->feedback( $message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) ); 181 } else { 182 $this->feedback( $message ); 183 } 184 } 185 } 186 } 187 188 /** 189 * @since 2.8.0 190 * @since 5.9.0 Renamed `$string` (a PHP reserved keyword) to `$feedback` for PHP 8 named parameter support. 191 * 192 * @param string $feedback Message data. 193 * @param mixed ...$args Optional text replacements. 194 */ 195 public function feedback( $feedback, ...$args ) { 196 if ( isset( $this->upgrader->strings[ $feedback ] ) ) { 197 $feedback = $this->upgrader->strings[ $feedback ]; 198 } 199 200 if ( str_contains( $feedback, '%' ) ) { 201 if ( $args ) { 202 $args = array_map( 'strip_tags', $args ); 203 $args = array_map( 'esc_html', $args ); 204 $feedback = vsprintf( $feedback, $args ); 205 } 206 } 207 if ( empty( $feedback ) ) { 208 return; 209 } 210 show_message( $feedback ); 211 } 212 213 /** 214 * Performs an action before an update. 215 * 216 * @since 2.8.0 217 */ 218 public function before() {} 219 220 /** 221 * Performs and action following an update. 222 * 223 * @since 2.8.0 224 */ 225 public function after() {} 226 227 /** 228 * Outputs JavaScript that calls function to decrement the update counts. 229 * 230 * @since 3.9.0 231 * 232 * @param string $type Type of update count to decrement. Likely values include 'plugin', 233 * 'theme', 'translation', etc. 234 */ 235 protected function decrement_update_count( $type ) { 236 if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) { 237 return; 238 } 239 240 if ( defined( 'IFRAME_REQUEST' ) ) { 241 echo '<script type="text/javascript"> 242 if ( window.postMessage && JSON ) { 243 window.parent.postMessage( 244 JSON.stringify( { 245 action: "decrementUpdateCount", 246 upgradeType: "' . $type . '" 247 } ), 248 window.location.protocol + "//" + window.location.hostname 249 + ( "" !== window.location.port ? ":" + window.location.port : "" ) 250 ); 251 } 252 </script>'; 253 } else { 254 echo '<script type="text/javascript"> 255 (function( wp ) { 256 if ( wp && wp.updates && wp.updates.decrementCount ) { 257 wp.updates.decrementCount( "' . $type . '" ); 258 } 259 })( window.wp ); 260 </script>'; 261 } 262 } 263 264 /** 265 * @since 3.0.0 266 */ 267 public function bulk_header() {} 268 269 /** 270 * @since 3.0.0 271 */ 272 public function bulk_footer() {} 273 274 /** 275 * Hides the `process_failed` error message when updating by uploading a zip file. 276 * 277 * @since 5.5.0 278 * 279 * @param WP_Error $wp_error WP_Error object. 280 * @return bool True if the error should be hidden, false otherwise. 281 */ 282 public function hide_process_failed( $wp_error ) { 283 return false; 284 } 285 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Fri Apr 26 08:20:02 2024 | Cross-referenced by PHPXref |