[ Index ]

PHP Cross Reference of WordPress

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      /**
  19       * Holds the upgrader data.
  20       *
  21       * @since 2.8.0
  22       *
  23       * @var WP_Upgrader
  24       */
  25      public $upgrader;
  26  
  27      /**
  28       * Whether header is done.
  29       *
  30       * @since 2.8.0
  31       *
  32       * @var bool
  33       */
  34      public $done_header = false;
  35  
  36      /**
  37       * Whether footer is done.
  38       *
  39       * @since 2.8.0
  40       *
  41       * @var bool
  42       */
  43      public $done_footer = false;
  44  
  45      /**
  46       * Holds the result of an upgrade.
  47       *
  48       * @since 2.8.0
  49       *
  50       * @var string|bool|WP_Error
  51       */
  52      public $result = false;
  53  
  54      /**
  55       * Holds the options of an upgrade.
  56       *
  57       * @since 2.8.0
  58       *
  59       * @var array
  60       */
  61      public $options = array();
  62  
  63      /**
  64       * Constructor.
  65       *
  66       * Sets up the generic skin for the WordPress Upgrader classes.
  67       *
  68       * @since 2.8.0
  69       *
  70       * @param array $args Optional. The WordPress upgrader skin arguments to
  71       *                    override default options. Default empty array.
  72       */
  73  	public function __construct( $args = array() ) {
  74          $defaults      = array(
  75              'url'     => '',
  76              'nonce'   => '',
  77              'title'   => '',
  78              'context' => false,
  79          );
  80          $this->options = wp_parse_args( $args, $defaults );
  81      }
  82  
  83      /**
  84       * @param WP_Upgrader $upgrader
  85       */
  86  	public function set_upgrader( &$upgrader ) {
  87          if ( is_object( $upgrader ) ) {
  88              $this->upgrader =& $upgrader;
  89          }
  90          $this->add_strings();
  91      }
  92  
  93      /**
  94       */
  95  	public function add_strings() {
  96      }
  97  
  98      /**
  99       * Sets the result of an upgrade.
 100       *
 101       * @since 2.8.0
 102       *
 103       * @param string|bool|WP_Error $result The result of an upgrade.
 104       */
 105  	public function set_result( $result ) {
 106          $this->result = $result;
 107      }
 108  
 109      /**
 110       * Displays a form to the user to request for their FTP/SSH details in order
 111       * to connect to the filesystem.
 112       *
 113       * @since 2.8.0
 114       * @since 4.6.0 The `$context` parameter default changed from `false` to an empty string.
 115       *
 116       * @see request_filesystem_credentials()
 117       *
 118       * @param bool|WP_Error $error                        Optional. Whether the current request has failed to connect,
 119       *                                                    or an error object. Default false.
 120       * @param string        $context                      Optional. Full path to the directory that is tested
 121       *                                                    for being writable. Default empty.
 122       * @param bool          $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false.
 123       * @return bool True on success, false on failure.
 124       */
 125  	public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
 126          $url = $this->options['url'];
 127          if ( ! $context ) {
 128              $context = $this->options['context'];
 129          }
 130          if ( ! empty( $this->options['nonce'] ) ) {
 131              $url = wp_nonce_url( $url, $this->options['nonce'] );
 132          }
 133  
 134          $extra_fields = array();
 135  
 136          return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership );
 137      }
 138  
 139      /**
 140       */
 141  	public function header() {
 142          if ( $this->done_header ) {
 143              return;
 144          }
 145          $this->done_header = true;
 146          echo '<div class="wrap">';
 147          echo '<h1>' . $this->options['title'] . '</h1>';
 148      }
 149  
 150      /**
 151       */
 152  	public function footer() {
 153          if ( $this->done_footer ) {
 154              return;
 155          }
 156          $this->done_footer = true;
 157          echo '</div>';
 158      }
 159  
 160      /**
 161       * @param string|WP_Error $errors
 162       */
 163  	public function error( $errors ) {
 164          if ( ! $this->done_header ) {
 165              $this->header();
 166          }
 167          if ( is_string( $errors ) ) {
 168              $this->feedback( $errors );
 169          } elseif ( is_wp_error( $errors ) && $errors->has_errors() ) {
 170              foreach ( $errors->get_error_messages() as $message ) {
 171                  if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) ) {
 172                      $this->feedback( $message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) );
 173                  } else {
 174                      $this->feedback( $message );
 175                  }
 176              }
 177          }
 178      }
 179  
 180      /**
 181       * @param string $string
 182       * @param mixed  ...$args Optional text replacements.
 183       */
 184  	public function feedback( $string, ...$args ) {
 185          if ( isset( $this->upgrader->strings[ $string ] ) ) {
 186              $string = $this->upgrader->strings[ $string ];
 187          }
 188  
 189          if ( strpos( $string, '%' ) !== false ) {
 190              if ( $args ) {
 191                  $args   = array_map( 'strip_tags', $args );
 192                  $args   = array_map( 'esc_html', $args );
 193                  $string = vsprintf( $string, $args );
 194              }
 195          }
 196          if ( empty( $string ) ) {
 197              return;
 198          }
 199          show_message( $string );
 200      }
 201  
 202      /**
 203       * Action to perform before an update.
 204       *
 205       * @since 2.8.0
 206       */
 207  	public function before() {}
 208  
 209      /**
 210       * Action to perform following an update.
 211       *
 212       * @since 2.8.0
 213       */
 214  	public function after() {}
 215  
 216      /**
 217       * Output JavaScript that calls function to decrement the update counts.
 218       *
 219       * @since 3.9.0
 220       *
 221       * @param string $type Type of update count to decrement. Likely values include 'plugin',
 222       *                     'theme', 'translation', etc.
 223       */
 224  	protected function decrement_update_count( $type ) {
 225          if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) {
 226              return;
 227          }
 228  
 229          if ( defined( 'IFRAME_REQUEST' ) ) {
 230              echo '<script type="text/javascript">
 231                      if ( window.postMessage && JSON ) {
 232                          window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname );
 233                      }
 234                  </script>';
 235          } else {
 236              echo '<script type="text/javascript">
 237                      (function( wp ) {
 238                          if ( wp && wp.updates && wp.updates.decrementCount ) {
 239                              wp.updates.decrementCount( "' . $type . '" );
 240                          }
 241                      })( window.wp );
 242                  </script>';
 243          }
 244      }
 245  
 246      /**
 247       */
 248  	public function bulk_header() {}
 249  
 250      /**
 251       */
 252  	public function bulk_footer() {}
 253  
 254      /**
 255       * Hides the `process_failed` error message when updating by uploading a zip file.
 256       *
 257       * @since 5.5.0
 258       *
 259       * @param WP_Error $wp_error WP_Error
 260       * @return bool
 261       */
 262  	public function hide_process_failed( $wp_error ) {
 263          return false;
 264      }
 265  }


Generated: Tue Oct 20 01:00:03 2020 Cross-referenced by PHPXref 0.7.1