2016-05-10 13:11:30 +02:00
< ? php
/**
2016-05-10 13:31:28 +02:00
* Upgrader API : Bulk_Upgrader_Skin class
2016-05-10 13:11:30 +02:00
*
* @ package WordPress
* @ subpackage Upgrader
2016-05-10 13:31:28 +02:00
* @ since 4.6 . 0
2016-05-10 13:11:30 +02:00
*/
/**
2016-05-10 13:31:28 +02:00
* Generic Bulk Upgrader Skin for WordPress Upgrades .
2016-05-10 13:11:30 +02:00
*
* @ since 3.0 . 0
2016-05-13 22:59:27 +02:00
* @ since 4.6 . 0 Moved to its own file from wp - admin / includes / class - wp - upgrader - skins . php .
2016-07-09 15:45:33 +02:00
*
* @ see WP_Upgrader_Skin
2016-05-10 13:11:30 +02:00
*/
class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
public $in_loop = false ;
/**
* @ var string | false
*/
public $error = false ;
/**
* @ param array $args
*/
2017-12-01 00:11:00 +01:00
public function __construct ( $args = array () ) {
$defaults = array (
'url' => '' ,
'nonce' => '' ,
);
$args = wp_parse_args ( $args , $defaults );
parent :: __construct ( $args );
2016-05-10 13:11:30 +02:00
}
/**
*/
public function add_strings () {
2017-12-01 00:11:00 +01:00
$this -> upgrader -> strings [ 'skin_upgrade_start' ] = __ ( 'The update process is starting. This process may take a while on some hosts, so please be patient.' );
2019-09-03 02:41:05 +02:00
/* translators: 1: Title of an update, 2: Error message. */
2017-12-01 00:11:00 +01:00
$this -> upgrader -> strings [ 'skin_update_failed_error' ] = __ ( 'An error occurred while updating %1$s: %2$s' );
2019-09-03 02:41:05 +02:00
/* translators: %s: Title of an update. */
2018-03-11 17:44:34 +01:00
$this -> upgrader -> strings [ 'skin_update_failed' ] = __ ( 'The update of %s failed.' );
2019-09-03 02:41:05 +02:00
/* translators: %s: Title of an update. */
2018-03-11 17:44:34 +01:00
$this -> upgrader -> strings [ 'skin_update_successful' ] = __ ( '%s updated successfully.' );
2017-12-01 00:11:00 +01:00
$this -> upgrader -> strings [ 'skin_upgrade_end' ] = __ ( 'All updates have been completed.' );
2016-05-10 13:11:30 +02:00
}
/**
* @ param string $string
2019-09-15 12:42:54 +02:00
* @ param mixed ... $args Optional text replacements .
2016-05-10 13:11:30 +02:00
*/
2019-09-15 12:42:54 +02:00
public function feedback ( $string , ... $args ) {
2017-12-01 00:11:00 +01:00
if ( isset ( $this -> upgrader -> strings [ $string ] ) ) {
$string = $this -> upgrader -> strings [ $string ];
}
2016-05-10 13:11:30 +02:00
2017-12-01 00:11:00 +01:00
if ( strpos ( $string , '%' ) !== false ) {
2016-05-10 13:11:30 +02:00
if ( $args ) {
2017-12-01 00:11:00 +01:00
$args = array_map ( 'strip_tags' , $args );
$args = array_map ( 'esc_html' , $args );
$string = vsprintf ( $string , $args );
2016-05-10 13:11:30 +02:00
}
}
2017-12-01 00:11:00 +01:00
if ( empty ( $string ) ) {
2016-05-10 13:11:30 +02:00
return ;
2017-12-01 00:11:00 +01:00
}
if ( $this -> in_loop ) {
2016-05-10 13:11:30 +02:00
echo " $string <br /> \n " ;
2017-12-01 00:11:00 +01:00
} else {
2016-05-10 13:11:30 +02:00
echo " <p> $string </p> \n " ;
2017-12-01 00:11:00 +01:00
}
2016-05-10 13:11:30 +02:00
}
/**
*/
public function header () {
// Nothing, This will be displayed within a iframe.
}
/**
*/
public function footer () {
// Nothing, This will be displayed within a iframe.
}
/**
* @ param string | WP_Error $error
*/
2017-12-01 00:11:00 +01:00
public function error ( $error ) {
if ( is_string ( $error ) && isset ( $this -> upgrader -> strings [ $error ] ) ) {
$this -> error = $this -> upgrader -> strings [ $error ];
}
2016-05-10 13:11:30 +02:00
2017-12-01 00:11:00 +01:00
if ( is_wp_error ( $error ) ) {
2016-05-10 13:11:30 +02:00
$messages = array ();
foreach ( $error -> get_error_messages () as $emessage ) {
2017-12-01 00:11:00 +01:00
if ( $error -> get_error_data () && is_string ( $error -> get_error_data () ) ) {
2016-05-10 13:11:30 +02:00
$messages [] = $emessage . ' ' . esc_html ( strip_tags ( $error -> get_error_data () ) );
2017-12-01 00:11:00 +01:00
} else {
2016-05-10 13:11:30 +02:00
$messages [] = $emessage ;
2017-12-01 00:11:00 +01:00
}
2016-05-10 13:11:30 +02:00
}
2017-12-01 00:11:00 +01:00
$this -> error = implode ( ', ' , $messages );
2016-05-10 13:11:30 +02:00
}
2017-12-01 00:11:00 +01:00
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js ( $this -> upgrader -> update_current ) . '\').hide();</script>' ;
2016-05-10 13:11:30 +02:00
}
/**
*/
public function bulk_header () {
2017-12-01 00:11:00 +01:00
$this -> feedback ( 'skin_upgrade_start' );
2016-05-10 13:11:30 +02:00
}
/**
*/
public function bulk_footer () {
2017-12-01 00:11:00 +01:00
$this -> feedback ( 'skin_upgrade_end' );
2016-05-10 13:11:30 +02:00
}
/**
* @ param string $title
*/
2017-12-01 00:11:00 +01:00
public function before ( $title = '' ) {
2016-05-10 13:11:30 +02:00
$this -> in_loop = true ;
printf ( '<h2>' . $this -> upgrader -> strings [ 'skin_before_update_header' ] . ' <span class="spinner waiting-' . $this -> upgrader -> update_current . '"></span></h2>' , $title , $this -> upgrader -> update_current , $this -> upgrader -> update_count );
2017-12-01 00:11:00 +01:00
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js ( $this -> upgrader -> update_current ) . '\').css("display", "inline-block");</script>' ;
2017-05-12 01:50:41 +02:00
// This progress messages div gets moved via JavaScript when clicking on "Show details.".
2017-12-01 00:11:00 +01:00
echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr ( $this -> upgrader -> update_current ) . '"><p>' ;
2016-05-10 13:11:30 +02:00
$this -> flush_output ();
}
/**
* @ param string $title
*/
2017-12-01 00:11:00 +01:00
public function after ( $title = '' ) {
2016-05-10 13:11:30 +02:00
echo '</p></div>' ;
if ( $this -> error || ! $this -> result ) {
if ( $this -> error ) {
2017-12-01 00:11:00 +01:00
echo '<div class="error"><p>' . sprintf ( $this -> upgrader -> strings [ 'skin_update_failed_error' ], $title , '<strong>' . $this -> error . '</strong>' ) . '</p></div>' ;
2016-05-10 13:11:30 +02:00
} else {
2017-12-01 00:11:00 +01:00
echo '<div class="error"><p>' . sprintf ( $this -> upgrader -> strings [ 'skin_update_failed' ], $title ) . '</p></div>' ;
2016-05-10 13:11:30 +02:00
}
2017-12-01 00:11:00 +01:00
echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js ( $this -> upgrader -> update_current ) . '\').show();</script>' ;
2016-05-10 13:11:30 +02:00
}
if ( $this -> result && ! is_wp_error ( $this -> result ) ) {
2017-05-12 01:50:41 +02:00
if ( ! $this -> error ) {
echo '<div class="updated js-update-details" data-update-details="progress-' . esc_attr ( $this -> upgrader -> update_current ) . '">' .
'<p>' . sprintf ( $this -> upgrader -> strings [ 'skin_update_successful' ], $title ) .
' <button type="button" class="hide-if-no-js button-link js-update-details-toggle" aria-expanded="false">' . __ ( 'Show details.' ) . '</button>' .
'</p></div>' ;
}
2017-12-01 00:11:00 +01:00
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js ( $this -> upgrader -> update_current ) . '\').hide();</script>' ;
2016-05-10 13:11:30 +02:00
}
$this -> reset ();
$this -> flush_output ();
}
/**
*/
public function reset () {
$this -> in_loop = false ;
2017-12-01 00:11:00 +01:00
$this -> error = false ;
2016-05-10 13:11:30 +02:00
}
/**
*/
public function flush_output () {
wp_ob_end_flush_all ();
flush ();
}
}