[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Upgrader API: WP_Ajax_Upgrader_Skin class
   4   *
   5   * @package WordPress
   6   * @subpackage Upgrader
   7   * @since 4.6.0
   8   */
   9  
  10  /**
  11   * Upgrader Skin for Ajax WordPress upgrades.
  12   *
  13   * This skin is designed to be used for Ajax updates.
  14   *
  15   * @since 4.6.0
  16   *
  17   * @see Automatic_Upgrader_Skin
  18   */
  19  class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
  20  
  21      /**
  22       * Holds the WP_Error object.
  23       *
  24       * @since 4.6.0
  25       * @var null|WP_Error
  26       */
  27      protected $errors = null;
  28  
  29      /**
  30       * Constructor.
  31       *
  32       * @since 4.6.0
  33       *
  34       * @param array $args Options for the upgrader, see WP_Upgrader_Skin::__construct().
  35       */
  36  	public function __construct( $args = array() ) {
  37          parent::__construct( $args );
  38  
  39          $this->errors = new WP_Error();
  40      }
  41  
  42      /**
  43       * Retrieves the list of errors.
  44       *
  45       * @since 4.6.0
  46       *
  47       * @return WP_Error Errors during an upgrade.
  48       */
  49  	public function get_errors() {
  50          return $this->errors;
  51      }
  52  
  53      /**
  54       * Retrieves a string for error messages.
  55       *
  56       * @since 4.6.0
  57       *
  58       * @return string Error messages during an upgrade.
  59       */
  60  	public function get_error_messages() {
  61          $messages = array();
  62  
  63          foreach ( $this->errors->get_error_codes() as $error_code ) {
  64              $error_data = $this->errors->get_error_data( $error_code );
  65  
  66              if ( $error_data && is_string( $error_data ) ) {
  67                  $messages[] = $this->errors->get_error_message( $error_code ) . ' ' . esc_html( strip_tags( $error_data ) );
  68              } else {
  69                  $messages[] = $this->errors->get_error_message( $error_code );
  70              }
  71          }
  72  
  73          return implode( ', ', $messages );
  74      }
  75  
  76      /**
  77       * Stores a log entry for an error.
  78       *
  79       * @since 4.6.0
  80       * @since 5.3.0 Formalized the existing `...$args` parameter by adding it
  81       *              to the function signature.
  82       *
  83       * @param string|WP_Error $errors  Errors.
  84       * @param mixed           ...$args Optional text replacements.
  85       */
  86  	public function error( $errors, ...$args ) {
  87          if ( is_string( $errors ) ) {
  88              $string = $errors;
  89              if ( ! empty( $this->upgrader->strings[ $string ] ) ) {
  90                  $string = $this->upgrader->strings[ $string ];
  91              }
  92  
  93              if ( false !== strpos( $string, '%' ) ) {
  94                  if ( ! empty( $args ) ) {
  95                      $string = vsprintf( $string, $args );
  96                  }
  97              }
  98  
  99              // Count existing errors to generate a unique error code.
 100              $errors_count = count( $this->errors->get_error_codes() );
 101              $this->errors->add( 'unknown_upgrade_error_' . ( $errors_count + 1 ), $string );
 102          } elseif ( is_wp_error( $errors ) ) {
 103              foreach ( $errors->get_error_codes() as $error_code ) {
 104                  $this->errors->add( $error_code, $errors->get_error_message( $error_code ), $errors->get_error_data( $error_code ) );
 105              }
 106          }
 107  
 108          parent::error( $errors, ...$args );
 109      }
 110  
 111      /**
 112       * Stores a log entry.
 113       *
 114       * @since 4.6.0
 115       * @since 5.3.0 Formalized the existing `...$args` parameter by adding it
 116       *              to the function signature.
 117       *
 118       * @param string|array|WP_Error $data    Log entry data.
 119       * @param mixed                 ...$args Optional text replacements.
 120       */
 121  	public function feedback( $data, ...$args ) {
 122          if ( is_wp_error( $data ) ) {
 123              foreach ( $data->get_error_codes() as $error_code ) {
 124                  $this->errors->add( $error_code, $data->get_error_message( $error_code ), $data->get_error_data( $error_code ) );
 125              }
 126          }
 127  
 128          parent::feedback( $data, ...$args );
 129      }
 130  }


Generated: Sun Dec 8 01:00:03 2019 Cross-referenced by PHPXref 0.7.1