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


Generated: Wed Jul 17 01:00:03 2019 Cross-referenced by PHPXref 0.7.1