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