[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Upgrader API: Bulk_Upgrader_Skin class 4 * 5 * @package WordPress 6 * @subpackage Upgrader 7 * @since 4.6.0 8 */ 9 10 /** 11 * Generic Bulk Upgrader Skin for WordPress Upgrades. 12 * 13 * @since 3.0.0 14 * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php. 15 * 16 * @see WP_Upgrader_Skin 17 */ 18 class Bulk_Upgrader_Skin extends WP_Upgrader_Skin { 19 public $in_loop = false; 20 /** 21 * @var string|false 22 */ 23 public $error = false; 24 25 /** 26 * @param array $args 27 */ 28 public function __construct( $args = array() ) { 29 $defaults = array( 30 'url' => '', 31 'nonce' => '', 32 ); 33 $args = wp_parse_args( $args, $defaults ); 34 35 parent::__construct( $args ); 36 } 37 38 /** 39 */ 40 public function add_strings() { 41 $this->upgrader->strings['skin_upgrade_start'] = __( 'The update process is starting. This process may take a while on some hosts, so please be patient.' ); 42 /* translators: 1: Title of an update, 2: Error message. */ 43 $this->upgrader->strings['skin_update_failed_error'] = __( 'An error occurred while updating %1$s: %2$s' ); 44 /* translators: %s: Title of an update. */ 45 $this->upgrader->strings['skin_update_failed'] = __( 'The update of %s failed.' ); 46 /* translators: %s: Title of an update. */ 47 $this->upgrader->strings['skin_update_successful'] = __( '%s updated successfully.' ); 48 $this->upgrader->strings['skin_upgrade_end'] = __( 'All updates have been completed.' ); 49 } 50 51 /** 52 * @param string $string 53 * @param mixed ...$args Optional text replacements. 54 */ 55 public function feedback( $string, ...$args ) { 56 if ( isset( $this->upgrader->strings[ $string ] ) ) { 57 $string = $this->upgrader->strings[ $string ]; 58 } 59 60 if ( strpos( $string, '%' ) !== false ) { 61 if ( $args ) { 62 $args = array_map( 'strip_tags', $args ); 63 $args = array_map( 'esc_html', $args ); 64 $string = vsprintf( $string, $args ); 65 } 66 } 67 if ( empty( $string ) ) { 68 return; 69 } 70 if ( $this->in_loop ) { 71 echo "$string<br />\n"; 72 } else { 73 echo "<p>$string</p>\n"; 74 } 75 } 76 77 /** 78 */ 79 public function header() { 80 // Nothing, This will be displayed within a iframe. 81 } 82 83 /** 84 */ 85 public function footer() { 86 // Nothing, This will be displayed within a iframe. 87 } 88 89 /** 90 * @param string|WP_Error $error 91 */ 92 public function error( $error ) { 93 if ( is_string( $error ) && isset( $this->upgrader->strings[ $error ] ) ) { 94 $this->error = $this->upgrader->strings[ $error ]; 95 } 96 97 if ( is_wp_error( $error ) ) { 98 $messages = array(); 99 foreach ( $error->get_error_messages() as $emessage ) { 100 if ( $error->get_error_data() && is_string( $error->get_error_data() ) ) { 101 $messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) ); 102 } else { 103 $messages[] = $emessage; 104 } 105 } 106 $this->error = implode( ', ', $messages ); 107 } 108 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>'; 109 } 110 111 /** 112 */ 113 public function bulk_header() { 114 $this->feedback( 'skin_upgrade_start' ); 115 } 116 117 /** 118 */ 119 public function bulk_footer() { 120 $this->feedback( 'skin_upgrade_end' ); 121 } 122 123 /** 124 * @param string $title 125 */ 126 public function before( $title = '' ) { 127 $this->in_loop = true; 128 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 ); 129 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').css("display", "inline-block");</script>'; 130 // This progress messages div gets moved via JavaScript when clicking on "Show details.". 131 echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr( $this->upgrader->update_current ) . '"><p>'; 132 $this->flush_output(); 133 } 134 135 /** 136 * @param string $title 137 */ 138 public function after( $title = '' ) { 139 echo '</p></div>'; 140 if ( $this->error || ! $this->result ) { 141 if ( $this->error ) { 142 echo '<div class="error"><p>' . sprintf( $this->upgrader->strings['skin_update_failed_error'], $title, '<strong>' . $this->error . '</strong>' ) . '</p></div>'; 143 } else { 144 echo '<div class="error"><p>' . sprintf( $this->upgrader->strings['skin_update_failed'], $title ) . '</p></div>'; 145 } 146 147 echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js( $this->upgrader->update_current ) . '\').show();</script>'; 148 } 149 if ( $this->result && ! is_wp_error( $this->result ) ) { 150 if ( ! $this->error ) { 151 echo '<div class="updated js-update-details" data-update-details="progress-' . esc_attr( $this->upgrader->update_current ) . '">' . 152 '<p>' . sprintf( $this->upgrader->strings['skin_update_successful'], $title ) . 153 ' <button type="button" class="hide-if-no-js button-link js-update-details-toggle" aria-expanded="false">' . __( 'Show details.' ) . '</button>' . 154 '</p></div>'; 155 } 156 157 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>'; 158 } 159 160 $this->reset(); 161 $this->flush_output(); 162 } 163 164 /** 165 */ 166 public function reset() { 167 $this->in_loop = false; 168 $this->error = false; 169 } 170 171 /** 172 */ 173 public function flush_output() { 174 wp_ob_end_flush_all(); 175 flush(); 176 } 177 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Apr 21 01:00:05 2021 | Cross-referenced by PHPXref 0.7.1 |