[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Upgrader API: Automatic_Upgrader_Skin class
   4   *
   5   * @package WordPress
   6   * @subpackage Upgrader
   7   * @since 4.6.0
   8   */
   9  
  10  /**
  11   * Upgrader Skin for Automatic WordPress Upgrades
  12   *
  13   * This skin is designed to be used when no output is intended, all output
  14   * is captured and stored for the caller to process and log/email/discard.
  15   *
  16   * @since 3.7.0
  17   * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
  18   *
  19   * @see Bulk_Upgrader_Skin
  20   */
  21  class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
  22      protected $messages = array();
  23  
  24      /**
  25       * Determines whether the upgrader needs FTP/SSH details in order to connect
  26       * to the filesystem.
  27       *
  28       * @since 3.7.0
  29       * @since 4.6.0 The `$context` parameter default changed from `false` to an empty string.
  30       *
  31       * @see request_filesystem_credentials()
  32       *
  33       * @param bool|WP_Error $error                        Optional. Whether the current request has failed to connect,
  34       *                                                    or an error object. Default false.
  35       * @param string        $context                      Optional. Full path to the directory that is tested
  36       *                                                    for being writable. Default empty.
  37       * @param bool          $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false.
  38       * @return bool True on success, false on failure.
  39       */
  40  	public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
  41          if ( $context ) {
  42              $this->options['context'] = $context;
  43          }
  44          /*
  45           * TODO: Fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version.
  46           * This will output a credentials form in event of failure. We don't want that, so just hide with a buffer.
  47           */
  48          ob_start();
  49          $result = parent::request_filesystem_credentials( $error, $context, $allow_relaxed_file_ownership );
  50          ob_end_clean();
  51          return $result;
  52      }
  53  
  54      /**
  55       * @return array
  56       */
  57  	public function get_upgrade_messages() {
  58          return $this->messages;
  59      }
  60  
  61      /**
  62       * @param string|array|WP_Error $data
  63       * @param mixed                 ...$args Optional text replacements.
  64       */
  65  	public function feedback( $data, ...$args ) {
  66          if ( is_wp_error( $data ) ) {
  67              $string = $data->get_error_message();
  68          } elseif ( is_array( $data ) ) {
  69              return;
  70          } else {
  71              $string = $data;
  72          }
  73          if ( ! empty( $this->upgrader->strings[ $string ] ) ) {
  74              $string = $this->upgrader->strings[ $string ];
  75          }
  76  
  77          if ( strpos( $string, '%' ) !== false ) {
  78              if ( ! empty( $args ) ) {
  79                  $string = vsprintf( $string, $args );
  80              }
  81          }
  82  
  83          $string = trim( $string );
  84  
  85          // Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
  86          $string = wp_kses(
  87              $string,
  88              array(
  89                  'a'      => array(
  90                      'href' => true,
  91                  ),
  92                  'br'     => true,
  93                  'em'     => true,
  94                  'strong' => true,
  95              )
  96          );
  97  
  98          if ( empty( $string ) ) {
  99              return;
 100          }
 101  
 102          $this->messages[] = $string;
 103      }
 104  
 105      /**
 106       */
 107  	public function header() {
 108          ob_start();
 109      }
 110  
 111      /**
 112       */
 113  	public function footer() {
 114          $output = ob_get_clean();
 115          if ( ! empty( $output ) ) {
 116              $this->feedback( $output );
 117          }
 118      }
 119  }


Generated: Fri Aug 7 01:00:03 2020 Cross-referenced by PHPXref 0.7.1