[ 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 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 * 190 * @param string $string 191 * @param mixed ...$args Optional text replacements. 192 */ 193 public function feedback( $string, ...$args ) { 194 if ( isset( $this->upgrader->strings[ $string ] ) ) { 195 $string = $this->upgrader->strings[ $string ]; 196 } 197 198 if ( strpos( $string, '%' ) !== false ) { 199 if ( $args ) { 200 $args = array_map( 'strip_tags', $args ); 201 $args = array_map( 'esc_html', $args ); 202 $string = vsprintf( $string, $args ); 203 } 204 } 205 if ( empty( $string ) ) { 206 return; 207 } 208 show_message( $string ); 209 } 210 211 /** 212 * Action to perform before an update. 213 * 214 * @since 2.8.0 215 */ 216 public function before() {} 217 218 /** 219 * Action to perform following an update. 220 * 221 * @since 2.8.0 222 */ 223 public function after() {} 224 225 /** 226 * Output JavaScript that calls function to decrement the update counts. 227 * 228 * @since 3.9.0 229 * 230 * @param string $type Type of update count to decrement. Likely values include 'plugin', 231 * 'theme', 'translation', etc. 232 */ 233 protected function decrement_update_count( $type ) { 234 if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) { 235 return; 236 } 237 238 if ( defined( 'IFRAME_REQUEST' ) ) { 239 echo '<script type="text/javascript"> 240 if ( window.postMessage && JSON ) { 241 window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname ); 242 } 243 </script>'; 244 } else { 245 echo '<script type="text/javascript"> 246 (function( wp ) { 247 if ( wp && wp.updates && wp.updates.decrementCount ) { 248 wp.updates.decrementCount( "' . $type . '" ); 249 } 250 })( window.wp ); 251 </script>'; 252 } 253 } 254 255 /** 256 * @since 3.0.0 257 */ 258 public function bulk_header() {} 259 260 /** 261 * @since 3.0.0 262 */ 263 public function bulk_footer() {} 264 265 /** 266 * Hides the `process_failed` error message when updating by uploading a zip file. 267 * 268 * @since 5.5.0 269 * 270 * @param WP_Error $wp_error WP_Error object. 271 * @return bool 272 */ 273 public function hide_process_failed( $wp_error ) { 274 return false; 275 } 276 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Jan 25 01:00:03 2021 | Cross-referenced by PHPXref 0.7.1 |