[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

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

   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       * @var string|bool|WP_Error
  27       */
  28      public $result  = false;
  29      public $options = array();
  30  
  31      /**
  32       * @param array $args
  33       */
  34  	public function __construct( $args = array() ) {
  35          $defaults      = array(
  36              'url'     => '',
  37              'nonce'   => '',
  38              'title'   => '',
  39              'context' => false,
  40          );
  41          $this->options = wp_parse_args( $args, $defaults );
  42      }
  43  
  44      /**
  45       * @param WP_Upgrader $upgrader
  46       */
  47  	public function set_upgrader( &$upgrader ) {
  48          if ( is_object( $upgrader ) ) {
  49              $this->upgrader =& $upgrader;
  50          }
  51          $this->add_strings();
  52      }
  53  
  54      /**
  55       */
  56  	public function add_strings() {
  57      }
  58  
  59      /**
  60       * Sets the result of an upgrade.
  61       *
  62       * @since 2.8.0
  63       *
  64       * @param string|bool|WP_Error $result The result of an upgrade.
  65       */
  66  	public function set_result( $result ) {
  67          $this->result = $result;
  68      }
  69  
  70      /**
  71       * Displays a form to the user to request for their FTP/SSH details in order
  72       * to connect to the filesystem.
  73       *
  74       * @since 2.8.0
  75       * @since 4.6.0 The `$context` parameter default changed from `false` to an empty string.
  76       *
  77       * @see request_filesystem_credentials()
  78       *
  79       * @param bool   $error                        Optional. Whether the current request has failed to connect.
  80       *                                             Default false.
  81       * @param string $context                      Optional. Full path to the directory that is tested
  82       *                                             for being writable. Default empty.
  83       * @param bool   $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false.
  84       * @return bool False on failure, true on success.
  85       */
  86  	public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
  87          $url = $this->options['url'];
  88          if ( ! $context ) {
  89              $context = $this->options['context'];
  90          }
  91          if ( ! empty( $this->options['nonce'] ) ) {
  92              $url = wp_nonce_url( $url, $this->options['nonce'] );
  93          }
  94  
  95          $extra_fields = array();
  96  
  97          return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership );
  98      }
  99  
 100      /**
 101       */
 102  	public function header() {
 103          if ( $this->done_header ) {
 104              return;
 105          }
 106          $this->done_header = true;
 107          echo '<div class="wrap">';
 108          echo '<h1>' . $this->options['title'] . '</h1>';
 109      }
 110  
 111      /**
 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       * @param string|WP_Error $errors
 123       */
 124  	public function error( $errors ) {
 125          if ( ! $this->done_header ) {
 126              $this->header();
 127          }
 128          if ( is_string( $errors ) ) {
 129              $this->feedback( $errors );
 130          } elseif ( is_wp_error( $errors ) && $errors->has_errors() ) {
 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       * @param mixed  ...$args Optional text replacements.
 144       */
 145  	public function feedback( $string, ...$args ) {
 146          if ( isset( $this->upgrader->strings[ $string ] ) ) {
 147              $string = $this->upgrader->strings[ $string ];
 148          }
 149  
 150          if ( strpos( $string, '%' ) !== false ) {
 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          }
 160          show_message( $string );
 161      }
 162  
 163      /**
 164       */
 165  	public function before() {}
 166  
 167      /**
 168       */
 169  	public function after() {}
 170  
 171      /**
 172       * Output JavaScript that calls function to decrement the update counts.
 173       *
 174       * @since 3.9.0
 175       *
 176       * @param string $type Type of update count to decrement. Likely values include 'plugin',
 177       *                     'theme', 'translation', etc.
 178       */
 179  	protected function decrement_update_count( $type ) {
 180          if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) {
 181              return;
 182          }
 183  
 184          if ( defined( 'IFRAME_REQUEST' ) ) {
 185              echo '<script type="text/javascript">
 186                      if ( window.postMessage && JSON ) {
 187                          window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname );
 188                      }
 189                  </script>';
 190          } else {
 191              echo '<script type="text/javascript">
 192                      (function( wp ) {
 193                          if ( wp && wp.updates && wp.updates.decrementCount ) {
 194                              wp.updates.decrementCount( "' . $type . '" );
 195                          }
 196                      })( window.wp );
 197                  </script>';
 198          }
 199      }
 200  
 201      /**
 202       */
 203  	public function bulk_header() {}
 204  
 205      /**
 206       */
 207  	public function bulk_footer() {}
 208  }


Generated: Tue Oct 22 08:20:01 2019 Cross-referenced by PHPXref 0.7