WP_Upgrader_Skin

Generic Skin for the WordPress Upgrader classes.

Defined (1)

The class is defined in the following location(s).

/wp-admin/includes/class-wp-upgrader-skin.php  
  1. class WP_Upgrader_Skin { 
  2.  
  3. public $upgrader; 
  4. public $done_header = false; 
  5. public $done_footer = false; 
  6.  
  7. /** 
  8. * Holds the result of an upgrade. 
  9. * @since 2.8.0 
  10. * @access public 
  11. * @var string|bool|WP_Error 
  12. */ 
  13. public $result = false; 
  14. public $options = array(); 
  15.  
  16. /** 
  17. * @param array $args 
  18. */ 
  19. public function __construct($args = array()) { 
  20. $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false ); 
  21. $this->options = wp_parse_args($args, $defaults); 
  22.  
  23. /** 
  24. * @param WP_Upgrader $upgrader 
  25. */ 
  26. public function set_upgrader(&$upgrader) { 
  27. if ( is_object($upgrader) ) 
  28. $this->upgrader =& $upgrader; 
  29. $this->add_strings(); 
  30.  
  31. /** 
  32. * @access public 
  33. */ 
  34. public function add_strings() { 
  35.  
  36. /** 
  37. * Sets the result of an upgrade. 
  38. * @since 2.8.0 
  39. * @access public 
  40. * @param string|bool|WP_Error $result The result of an upgrade. 
  41. */ 
  42. public function set_result( $result ) { 
  43. $this->result = $result; 
  44.  
  45. /** 
  46. * Displays a form to the user to request for their FTP/SSH details in order 
  47. * to connect to the filesystem. 
  48. * @since 2.8.0 
  49. * @since 4.6.0 The `$context` parameter default changed from `false` to an empty string. 
  50. * @see request_filesystem_credentials() 
  51. * @param bool $error Optional. Whether the current request has failed to connect. 
  52. * Default false. 
  53. * @param string $context Optional. Full path to the directory that is tested 
  54. * for being writable. Default empty. 
  55. * @param bool $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false. 
  56. * @return bool False on failure, true on success. 
  57. */ 
  58. public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) { 
  59. $url = $this->options['url']; 
  60. if ( ! $context ) { 
  61. $context = $this->options['context']; 
  62. if ( !empty($this->options['nonce']) ) { 
  63. $url = wp_nonce_url($url, $this->options['nonce']); 
  64.  
  65. $extra_fields = array(); 
  66.  
  67. return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership ); 
  68.  
  69. /** 
  70. * @access public 
  71. */ 
  72. public function header() { 
  73. if ( $this->done_header ) { 
  74. return; 
  75. $this->done_header = true; 
  76. echo '<div class="wrap">'; 
  77. echo '<h1>' . $this->options['title'] . '</h1>'; 
  78.  
  79. /** 
  80. * @access public 
  81. */ 
  82. public function footer() { 
  83. if ( $this->done_footer ) { 
  84. return; 
  85. $this->done_footer = true; 
  86. echo '</div>'; 
  87.  
  88. /** 
  89. * @param string|WP_Error $errors 
  90. */ 
  91. public function error($errors) { 
  92. if ( ! $this->done_header ) 
  93. $this->header(); 
  94. if ( is_string($errors) ) { 
  95. $this->feedback($errors); 
  96. } elseif ( is_wp_error($errors) && $errors->get_error_code() ) { 
  97. foreach ( $errors->get_error_messages() as $message ) { 
  98. if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) ) 
  99. $this->feedback($message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) ); 
  100. else 
  101. $this->feedback($message); 
  102.  
  103. /** 
  104. * @param string $string 
  105. */ 
  106. public function feedback($string) { 
  107. if ( isset( $this->upgrader->strings[$string] ) ) 
  108. $string = $this->upgrader->strings[$string]; 
  109.  
  110. if ( strpos($string, '%') !== false ) { 
  111. $args = func_get_args(); 
  112. $args = array_splice($args, 1); 
  113. if ( $args ) { 
  114. $args = array_map( 'strip_tags', $args ); 
  115. $args = array_map( 'esc_html', $args ); 
  116. $string = vsprintf($string, $args); 
  117. if ( empty($string) ) 
  118. return; 
  119. show_message($string); 
  120.  
  121. /** 
  122. * @access public 
  123. */ 
  124. public function before() {} 
  125.  
  126. /** 
  127. * @access public 
  128. */ 
  129. public function after() {} 
  130.  
  131. /** 
  132. * Output JavaScript that calls function to decrement the update counts. 
  133. * @since 3.9.0 
  134. * @param string $type Type of update count to decrement. Likely values include 'plugin',  
  135. * 'theme', 'translation', etc. 
  136. */ 
  137. protected function decrement_update_count( $type ) { 
  138. if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) { 
  139. return; 
  140.  
  141. if ( defined( 'IFRAME_REQUEST' ) ) { 
  142. echo '<script type="text/javascript"> 
  143. if ( window.postMessage && JSON ) { 
  144. window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname ); 
  145. </script>'; 
  146. } else { 
  147. echo '<script type="text/javascript"> 
  148. (function( wp ) { 
  149. if ( wp && wp.updates.decrementCount ) { 
  150. wp.updates.decrementCount( "' . $type . '" ); 
  151. })( window.wp ); 
  152. </script>'; 
  153.  
  154. /** 
  155. * @access public 
  156. */ 
  157. public function bulk_header() {} 
  158.  
  159. /** 
  160. * @access public 
  161. */ 
  162. public function bulk_footer() {}