[ 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      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       */
 144  	public function feedback( $string ) {
 145          if ( isset( $this->upgrader->strings[ $string ] ) ) {
 146              $string = $this->upgrader->strings[ $string ];
 147          }
 148  
 149          if ( strpos( $string, '%' ) !== false ) {
 150              $args = func_get_args();
 151              $args = array_splice( $args, 1 );
 152              if ( $args ) {
 153                  $args   = array_map( 'strip_tags', $args );
 154                  $args   = array_map( 'esc_html', $args );
 155                  $string = vsprintf( $string, $args );
 156              }
 157          }
 158          if ( empty( $string ) ) {
 159              return;
 160          }
 161          show_message( $string );
 162      }
 163  
 164      /**
 165       */
 166  	public function before() {}
 167  
 168      /**
 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 && wp.updates.decrementCount ) {
 195                              wp.updates.decrementCount( "' . $type . '" );
 196                          }
 197                      })( window.wp );
 198                  </script>';
 199          }
 200      }
 201  
 202      /**
 203       */
 204  	public function bulk_header() {}
 205  
 206      /**
 207       */
 208  	public function bulk_footer() {}
 209  }


Generated: Thu Jul 18 01:00:03 2019 Cross-referenced by PHPXref 0.7.1