wp/wp-admin/includes/class-wp-upgrader-skin.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    11  * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes.
    11  * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes.
    12  *
    12  *
    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 #[AllowDynamicProperties]
    16 class WP_Upgrader_Skin {
    17 class WP_Upgrader_Skin {
    17 
    18 
    18 	/**
    19 	/**
    19 	 * Holds the upgrader data.
    20 	 * Holds the upgrader data.
    20 	 *
    21 	 *
    21 	 * @since 2.8.0
    22 	 * @since 2.8.0
    22 	 *
       
    23 	 * @var WP_Upgrader
    23 	 * @var WP_Upgrader
    24 	 */
    24 	 */
    25 	public $upgrader;
    25 	public $upgrader;
    26 
    26 
    27 	/**
    27 	/**
    28 	 * Whether header is done.
    28 	 * Whether header is done.
    29 	 *
    29 	 *
    30 	 * @since 2.8.0
    30 	 * @since 2.8.0
    31 	 *
       
    32 	 * @var bool
    31 	 * @var bool
    33 	 */
    32 	 */
    34 	public $done_header = false;
    33 	public $done_header = false;
    35 
    34 
    36 	/**
    35 	/**
    37 	 * Whether footer is done.
    36 	 * Whether footer is done.
    38 	 *
    37 	 *
    39 	 * @since 2.8.0
    38 	 * @since 2.8.0
    40 	 *
       
    41 	 * @var bool
    39 	 * @var bool
    42 	 */
    40 	 */
    43 	public $done_footer = false;
    41 	public $done_footer = false;
    44 
    42 
    45 	/**
    43 	/**
    46 	 * Holds the result of an upgrade.
    44 	 * Holds the result of an upgrade.
    47 	 *
    45 	 *
    48 	 * @since 2.8.0
    46 	 * @since 2.8.0
    49 	 *
       
    50 	 * @var string|bool|WP_Error
    47 	 * @var string|bool|WP_Error
    51 	 */
    48 	 */
    52 	public $result = false;
    49 	public $result = false;
    53 
    50 
    54 	/**
    51 	/**
    55 	 * Holds the options of an upgrade.
    52 	 * Holds the options of an upgrade.
    56 	 *
    53 	 *
    57 	 * @since 2.8.0
    54 	 * @since 2.8.0
    58 	 *
       
    59 	 * @var array
    55 	 * @var array
    60 	 */
    56 	 */
    61 	public $options = array();
    57 	public $options = array();
    62 
    58 
    63 	/**
    59 	/**
    79 		);
    75 		);
    80 		$this->options = wp_parse_args( $args, $defaults );
    76 		$this->options = wp_parse_args( $args, $defaults );
    81 	}
    77 	}
    82 
    78 
    83 	/**
    79 	/**
       
    80 	 * Sets the relationship between the skin being used and the upgrader.
       
    81 	 *
    84 	 * @since 2.8.0
    82 	 * @since 2.8.0
    85 	 *
    83 	 *
    86 	 * @param WP_Upgrader $upgrader
    84 	 * @param WP_Upgrader $upgrader
    87 	 */
    85 	 */
    88 	public function set_upgrader( &$upgrader ) {
    86 	public function set_upgrader( &$upgrader ) {
    91 		}
    89 		}
    92 		$this->add_strings();
    90 		$this->add_strings();
    93 	}
    91 	}
    94 
    92 
    95 	/**
    93 	/**
       
    94 	 * Sets up the strings used in the update process.
       
    95 	 *
    96 	 * @since 3.0.0
    96 	 * @since 3.0.0
    97 	 */
    97 	 */
    98 	public function add_strings() {
    98 	public function add_strings() {
    99 	}
    99 	}
   100 
   100 
   138 
   138 
   139 		return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership );
   139 		return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership );
   140 	}
   140 	}
   141 
   141 
   142 	/**
   142 	/**
       
   143 	 * Displays the header before the update process.
       
   144 	 *
   143 	 * @since 2.8.0
   145 	 * @since 2.8.0
   144 	 */
   146 	 */
   145 	public function header() {
   147 	public function header() {
   146 		if ( $this->done_header ) {
   148 		if ( $this->done_header ) {
   147 			return;
   149 			return;
   150 		echo '<div class="wrap">';
   152 		echo '<div class="wrap">';
   151 		echo '<h1>' . $this->options['title'] . '</h1>';
   153 		echo '<h1>' . $this->options['title'] . '</h1>';
   152 	}
   154 	}
   153 
   155 
   154 	/**
   156 	/**
       
   157 	 * Displays the footer following the update process.
       
   158 	 *
   155 	 * @since 2.8.0
   159 	 * @since 2.8.0
   156 	 */
   160 	 */
   157 	public function footer() {
   161 	public function footer() {
   158 		if ( $this->done_footer ) {
   162 		if ( $this->done_footer ) {
   159 			return;
   163 			return;
   161 		$this->done_footer = true;
   165 		$this->done_footer = true;
   162 		echo '</div>';
   166 		echo '</div>';
   163 	}
   167 	}
   164 
   168 
   165 	/**
   169 	/**
       
   170 	 * Displays an error message about the update.
       
   171 	 *
   166 	 * @since 2.8.0
   172 	 * @since 2.8.0
   167 	 *
   173 	 *
   168 	 * @param string|WP_Error $errors Errors.
   174 	 * @param string|WP_Error $errors Errors.
   169 	 */
   175 	 */
   170 	public function error( $errors ) {
   176 	public function error( $errors ) {
   183 			}
   189 			}
   184 		}
   190 		}
   185 	}
   191 	}
   186 
   192 
   187 	/**
   193 	/**
       
   194 	 * Displays a message about the update.
       
   195 	 *
   188 	 * @since 2.8.0
   196 	 * @since 2.8.0
   189 	 * @since 5.9.0 Renamed `$string` (a PHP reserved keyword) to `$feedback` for PHP 8 named parameter support.
   197 	 * @since 5.9.0 Renamed `$string` (a PHP reserved keyword) to `$feedback` for PHP 8 named parameter support.
   190 	 *
   198 	 *
   191 	 * @param string $feedback Message data.
   199 	 * @param string $feedback Message data.
   192 	 * @param mixed  ...$args  Optional text replacements.
   200 	 * @param mixed  ...$args  Optional text replacements.
   194 	public function feedback( $feedback, ...$args ) {
   202 	public function feedback( $feedback, ...$args ) {
   195 		if ( isset( $this->upgrader->strings[ $feedback ] ) ) {
   203 		if ( isset( $this->upgrader->strings[ $feedback ] ) ) {
   196 			$feedback = $this->upgrader->strings[ $feedback ];
   204 			$feedback = $this->upgrader->strings[ $feedback ];
   197 		}
   205 		}
   198 
   206 
   199 		if ( strpos( $feedback, '%' ) !== false ) {
   207 		if ( str_contains( $feedback, '%' ) ) {
   200 			if ( $args ) {
   208 			if ( $args ) {
   201 				$args     = array_map( 'strip_tags', $args );
   209 				$args     = array_map( 'strip_tags', $args );
   202 				$args     = array_map( 'esc_html', $args );
   210 				$args     = array_map( 'esc_html', $args );
   203 				$feedback = vsprintf( $feedback, $args );
   211 				$feedback = vsprintf( $feedback, $args );
   204 			}
   212 			}
   208 		}
   216 		}
   209 		show_message( $feedback );
   217 		show_message( $feedback );
   210 	}
   218 	}
   211 
   219 
   212 	/**
   220 	/**
   213 	 * Action to perform before an update.
   221 	 * Performs an action before an update.
   214 	 *
   222 	 *
   215 	 * @since 2.8.0
   223 	 * @since 2.8.0
   216 	 */
   224 	 */
   217 	public function before() {}
   225 	public function before() {}
   218 
   226 
   219 	/**
   227 	/**
   220 	 * Action to perform following an update.
   228 	 * Performs an action following an update.
   221 	 *
   229 	 *
   222 	 * @since 2.8.0
   230 	 * @since 2.8.0
   223 	 */
   231 	 */
   224 	public function after() {}
   232 	public function after() {}
   225 
   233 
   226 	/**
   234 	/**
   227 	 * Output JavaScript that calls function to decrement the update counts.
   235 	 * Outputs JavaScript that calls function to decrement the update counts.
   228 	 *
   236 	 *
   229 	 * @since 3.9.0
   237 	 * @since 3.9.0
   230 	 *
   238 	 *
   231 	 * @param string $type Type of update count to decrement. Likely values include 'plugin',
   239 	 * @param string $type Type of update count to decrement. Likely values include 'plugin',
   232 	 *                     'theme', 'translation', etc.
   240 	 *                     'theme', 'translation', etc.
   237 		}
   245 		}
   238 
   246 
   239 		if ( defined( 'IFRAME_REQUEST' ) ) {
   247 		if ( defined( 'IFRAME_REQUEST' ) ) {
   240 			echo '<script type="text/javascript">
   248 			echo '<script type="text/javascript">
   241 					if ( window.postMessage && JSON ) {
   249 					if ( window.postMessage && JSON ) {
   242 						window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname );
   250 						window.parent.postMessage(
       
   251 							JSON.stringify( {
       
   252 								action: "decrementUpdateCount",
       
   253 								upgradeType: "' . $type . '"
       
   254 							} ),
       
   255 							window.location.protocol + "//" + window.location.hostname
       
   256 								+ ( "" !== window.location.port ? ":" + window.location.port : "" )
       
   257 						);
   243 					}
   258 					}
   244 				</script>';
   259 				</script>';
   245 		} else {
   260 		} else {
   246 			echo '<script type="text/javascript">
   261 			echo '<script type="text/javascript">
   247 					(function( wp ) {
   262 					(function( wp ) {
   252 				</script>';
   267 				</script>';
   253 		}
   268 		}
   254 	}
   269 	}
   255 
   270 
   256 	/**
   271 	/**
       
   272 	 * Displays the header before the bulk update process.
       
   273 	 *
   257 	 * @since 3.0.0
   274 	 * @since 3.0.0
   258 	 */
   275 	 */
   259 	public function bulk_header() {}
   276 	public function bulk_header() {}
   260 
   277 
   261 	/**
   278 	/**
       
   279 	 * Displays the footer following the bulk update process.
       
   280 	 *
   262 	 * @since 3.0.0
   281 	 * @since 3.0.0
   263 	 */
   282 	 */
   264 	public function bulk_footer() {}
   283 	public function bulk_footer() {}
   265 
   284 
   266 	/**
   285 	/**
   267 	 * Hides the `process_failed` error message when updating by uploading a zip file.
   286 	 * Hides the `process_failed` error message when updating by uploading a zip file.
   268 	 *
   287 	 *
   269 	 * @since 5.5.0
   288 	 * @since 5.5.0
   270 	 *
   289 	 *
   271 	 * @param WP_Error $wp_error WP_Error object.
   290 	 * @param WP_Error $wp_error WP_Error object.
   272 	 * @return bool
   291 	 * @return bool True if the error should be hidden, false otherwise.
   273 	 */
   292 	 */
   274 	public function hide_process_failed( $wp_error ) {
   293 	public function hide_process_failed( $wp_error ) {
   275 		return false;
   294 		return false;
   276 	}
   295 	}
   277 }
   296 }