WordPress PHP Cross Reference Blogging Systems

Source: /wp-admin/includes/class-wp-upgrader-skin.php - 211 lines - 5228 bytes - Summary - Text - Print

Description: Upgrader API: WP_Upgrader_Skin class

   1  <?php
   2  /**
   3   * Upgrader API: WP_Upgrader_Skin class
   4   *
   5   * @package WordPress
   6   * @subpackage Upgrader
   7   * @since 4.6.0
   8   */
   9  
  10  /**
  11   * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes.
  12   *
  13   * @since 2.8.0
  14   * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
  15   */
  16  class WP_Upgrader_Skin {
  17  
  18      public $upgrader;
  19      public $done_header = false;
  20      public $done_footer = false;
  21  
  22      /**
  23       * Holds the result of an upgrade.
  24       *
  25       * @since 2.8.0
  26       * @access public
  27       * @var string|bool|WP_Error
  28       */
  29      public $result = false;
  30      public $options = array();
  31  
  32      /**
  33       *
  34       * @param array $args
  35       */
  36  	public function __construct($args = array()) {
  37          $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
  38          $this->options = wp_parse_args($args, $defaults);
  39      }
  40  
  41      /**
  42       * @param WP_Upgrader $upgrader
  43       */
  44  	public function set_upgrader(&$upgrader) {
  45          if ( is_object($upgrader) )
  46              $this->upgrader =& $upgrader;
  47          $this->add_strings();
  48      }
  49  
  50      /**
  51       * @access public
  52       */
  53  	public function add_strings() {
  54      }
  55  
  56      /**
  57       * Sets the result of an upgrade.
  58       *
  59       * @since 2.8.0
  60       * @access public
  61       *
  62       * @param string|bool|WP_Error $result The result of an upgrade.
  63       */
  64  	public function set_result( $result ) {
  65          $this->result = $result;
  66      }
  67  
  68      /**
  69       * Displays a form to the user to request for their FTP/SSH details in order
  70       * to connect to the filesystem.
  71       *
  72       * @since 2.8.0
  73       * @since 4.6.0 The `$context` parameter default changed from `false` to an empty string.
  74       *
  75       * @see request_filesystem_credentials()
  76       *
  77       * @param bool   $error                        Optional. Whether the current request has failed to connect.
  78       *                                             Default false.
  79       * @param string $context                      Optional. Full path to the directory that is tested
  80       *                                             for being writable. Default empty.
  81       * @param bool   $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false.
  82       * @return bool False on failure, true on success.
  83       */
  84  	public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
  85          $url = $this->options['url'];
  86          if ( ! $context ) {
  87              $context = $this->options['context'];
  88          }
  89          if ( !empty($this->options['nonce']) ) {
  90              $url = wp_nonce_url($url, $this->options['nonce']);
  91          }
  92  
  93          $extra_fields = array();
  94  
  95          return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership );
  96      }
  97  
  98      /**
  99       * @access public
 100       */
 101  	public function header() {
 102          if ( $this->done_header ) {
 103              return;
 104          }
 105          $this->done_header = true;
 106          echo '<div class="wrap">';
 107          echo '<h1>' . $this->options['title'] . '</h1>';
 108      }
 109  
 110      /**
 111       * @access public
 112       */
 113  	public function footer() {
 114          if ( $this->done_footer ) {
 115              return;
 116          }
 117          $this->done_footer = true;
 118          echo '</div>';
 119      }
 120  
 121      /**
 122       *
 123       * @param string|WP_Error $errors
 124       */
 125  	public function error($errors) {
 126          if ( ! $this->done_header )
 127              $this->header();
 128          if ( is_string($errors) ) {
 129              $this->feedback($errors);
 130          } elseif ( is_wp_error($errors) && $errors->get_error_code() ) {
 131              foreach ( $errors->get_error_messages() as $message ) {
 132                  if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) )
 133                      $this->feedback($message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) );
 134                  else
 135                      $this->feedback($message);
 136              }
 137          }
 138      }
 139  
 140      /**
 141       *
 142       * @param string $string
 143       */
 144  	public function feedback($string) {
 145          if ( isset( $this->upgrader->strings[$string] ) )
 146              $string = $this->upgrader->strings[$string];
 147  
 148          if ( strpos($string, '%') !== false ) {
 149              $args = func_get_args();
 150              $args = array_splice($args, 1);
 151              if ( $args ) {
 152                  $args = array_map( 'strip_tags', $args );
 153                  $args = array_map( 'esc_html', $args );
 154                  $string = vsprintf($string, $args);
 155              }
 156          }
 157          if ( empty($string) )
 158              return;
 159          show_message($string);
 160      }
 161  
 162      /**
 163       * @access public
 164       */
 165  	public function before() {}
 166  
 167      /**
 168       * @access public
 169       */
 170  	public function after() {}
 171  
 172      /**
 173       * Output JavaScript that calls function to decrement the update counts.
 174       *
 175       * @since 3.9.0
 176       *
 177       * @param string $type Type of update count to decrement. Likely values include 'plugin',
 178       *                     'theme', 'translation', etc.
 179       */
 180  	protected function decrement_update_count( $type ) {
 181          if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) {
 182              return;
 183          }
 184  
 185          if ( defined( 'IFRAME_REQUEST' ) ) {
 186              echo '<script type="text/javascript">
 187                      if ( window.postMessage && JSON ) {
 188                          window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname );
 189                      }
 190                  </script>';
 191          } else {
 192              echo '<script type="text/javascript">
 193                      (function( wp ) {
 194                          if ( wp && wp.updates.decrementCount ) {
 195                              wp.updates.decrementCount( "' . $type . '" );
 196                          }
 197                      })( window.wp );
 198                  </script>';
 199          }
 200      }
 201  
 202      /**
 203       * @access public
 204       */
 205  	public function bulk_header() {}
 206  
 207      /**
 208       * @access public
 209       */
 210  	public function bulk_footer() {}
 211  }

title

Description

title

Description

title

Description

title

title

Body