[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/includes/ -> class-bulk-upgrader-skin.php (source)

   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       * @since 5.9.0 Renamed `$string` (a PHP reserved keyword) to `$feedback` for PHP 8 named parameter support.
  53       *
  54       * @param string $feedback Message data.
  55       * @param mixed  ...$args  Optional text replacements.
  56       */
  57  	public function feedback( $feedback, ...$args ) {
  58          if ( isset( $this->upgrader->strings[ $feedback ] ) ) {
  59              $feedback = $this->upgrader->strings[ $feedback ];
  60          }
  61  
  62          if ( strpos( $feedback, '%' ) !== false ) {
  63              if ( $args ) {
  64                  $args     = array_map( 'strip_tags', $args );
  65                  $args     = array_map( 'esc_html', $args );
  66                  $feedback = vsprintf( $feedback, $args );
  67              }
  68          }
  69          if ( empty( $feedback ) ) {
  70              return;
  71          }
  72          if ( $this->in_loop ) {
  73              echo "$feedback<br />\n";
  74          } else {
  75              echo "<p>$feedback</p>\n";
  76          }
  77      }
  78  
  79      /**
  80       */
  81  	public function header() {
  82          // Nothing, This will be displayed within a iframe.
  83      }
  84  
  85      /**
  86       */
  87  	public function footer() {
  88          // Nothing, This will be displayed within a iframe.
  89      }
  90  
  91      /**
  92       * @since 5.9.0 Renamed `$error` to `$errors` for PHP 8 named parameter support.
  93       *
  94       * @param string|WP_Error $errors Errors.
  95       */
  96  	public function error( $errors ) {
  97          if ( is_string( $errors ) && isset( $this->upgrader->strings[ $errors ] ) ) {
  98              $this->error = $this->upgrader->strings[ $errors ];
  99          }
 100  
 101          if ( is_wp_error( $errors ) ) {
 102              $messages = array();
 103              foreach ( $errors->get_error_messages() as $emessage ) {
 104                  if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) ) {
 105                      $messages[] = $emessage . ' ' . esc_html( strip_tags( $errors->get_error_data() ) );
 106                  } else {
 107                      $messages[] = $emessage;
 108                  }
 109              }
 110              $this->error = implode( ', ', $messages );
 111          }
 112          echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>';
 113      }
 114  
 115      /**
 116       */
 117  	public function bulk_header() {
 118          $this->feedback( 'skin_upgrade_start' );
 119      }
 120  
 121      /**
 122       */
 123  	public function bulk_footer() {
 124          $this->feedback( 'skin_upgrade_end' );
 125      }
 126  
 127      /**
 128       * @param string $title
 129       */
 130  	public function before( $title = '' ) {
 131          $this->in_loop = true;
 132          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 );
 133          echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').css("display", "inline-block");</script>';
 134          // This progress messages div gets moved via JavaScript when clicking on "Show details.".
 135          echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr( $this->upgrader->update_current ) . '"><p>';
 136          $this->flush_output();
 137      }
 138  
 139      /**
 140       * @param string $title
 141       */
 142  	public function after( $title = '' ) {
 143          echo '</p></div>';
 144          if ( $this->error || ! $this->result ) {
 145              if ( $this->error ) {
 146                  echo '<div class="error"><p>' . sprintf( $this->upgrader->strings['skin_update_failed_error'], $title, '<strong>' . $this->error . '</strong>' ) . '</p></div>';
 147              } else {
 148                  echo '<div class="error"><p>' . sprintf( $this->upgrader->strings['skin_update_failed'], $title ) . '</p></div>';
 149              }
 150  
 151              echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js( $this->upgrader->update_current ) . '\').show();</script>';
 152          }
 153          if ( $this->result && ! is_wp_error( $this->result ) ) {
 154              if ( ! $this->error ) {
 155                  echo '<div class="updated js-update-details" data-update-details="progress-' . esc_attr( $this->upgrader->update_current ) . '">' .
 156                      '<p>' . sprintf( $this->upgrader->strings['skin_update_successful'], $title ) .
 157                      ' <button type="button" class="hide-if-no-js button-link js-update-details-toggle" aria-expanded="false">' . __( 'Show details.' ) . '</button>' .
 158                      '</p></div>';
 159              }
 160  
 161              echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>';
 162          }
 163  
 164          $this->reset();
 165          $this->flush_output();
 166      }
 167  
 168      /**
 169       */
 170  	public function reset() {
 171          $this->in_loop = false;
 172          $this->error   = false;
 173      }
 174  
 175      /**
 176       */
 177  	public function flush_output() {
 178          wp_ob_end_flush_all();
 179          flush();
 180      }
 181  }


Generated: Fri Dec 6 01:00:02 2024 Cross-referenced by PHPXref 0.7.1