/wp-admin/includes/class-wp-upgrader-skin.php

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