Jetpack_Automatic_Plugin_Install_Skin

Allows us to capture that the site doesn't have proper file system access.

Defined (1)

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

/json-endpoints/jetpack/class.jetpack-json-api-plugins-install-endpoint.php  
  1. class Jetpack_Automatic_Plugin_Install_Skin extends Automatic_Upgrader_Skin { 
  2. /** 
  3. * Stores the last error key; 
  4. **/ 
  5. protected $main_error_code = 'install_error'; 
  6.  
  7. /** 
  8. * Stores the last error message. 
  9. **/ 
  10. protected $main_error_message = 'An unknown error occurred during installation'; 
  11.  
  12. /** 
  13. * Overwrites the set_upgrader to be able to tell if we e ven have the ability to write to the files. 
  14. * @param WP_Upgrader $upgrader 
  15. */ 
  16. public function set_upgrader( &$upgrader ) { 
  17. parent::set_upgrader( $upgrader ); 
  18.  
  19. // Check if we even have permission to. 
  20. $result = $upgrader->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) ); 
  21. if ( ! $result ) { 
  22. // set the string here since they are not available just yet 
  23. $upgrader->generic_strings(); 
  24. $this->feedback( 'fs_unavailable' ); 
  25.  
  26. /** 
  27. * Overwrites the error function 
  28. */ 
  29. public function error( $error ) { 
  30. if ( is_wp_error( $error ) ) { 
  31. $this->feedback( $error ); 
  32.  
  33. private function set_main_error_code( $code ) { 
  34. // Don't set the process_failed as code since it is not that helpful unless we don't have one already set. 
  35. $this->main_error_code = ( $code === 'process_failed' && $this->main_error_code ? $this->main_error_code : $code ); 
  36.  
  37. private function set_main_error_message( $message, $code ) { 
  38. // Don't set the process_failed as message since it is not that helpful unless we don't have one already set. 
  39. $this->main_error_message = ( $code === 'process_failed' && $this->main_error_code ? $this->main_error_code : $message ); 
  40.  
  41. public function get_main_error_code() { 
  42. return $this->main_error_code; 
  43.  
  44. public function get_main_error_message() { 
  45. return $this->main_error_message; 
  46.  
  47. /** 
  48. * Overwrites the feedback function 
  49. */ 
  50. public function feedback( $data ) { 
  51.  
  52. $current_error = null; 
  53. if ( is_wp_error( $data ) ) { 
  54. $this->set_main_error_code( $data->get_error_code() ); 
  55. $string = $data->get_error_message(); 
  56. } elseif ( is_array( $data ) ) { 
  57. return; 
  58. } else { 
  59. $string = $data; 
  60.  
  61. if ( ! empty( $this->upgrader->strings[ $string ] ) ) { 
  62. $this->set_main_error_code( $string ); 
  63.  
  64. $current_error = $string; 
  65. $string = $this->upgrader->strings[ $string ]; 
  66.  
  67. if ( strpos( $string, '%' ) !== false ) { 
  68. $args = func_get_args(); 
  69. $args = array_splice( $args, 1 ); 
  70. if ( ! empty( $args ) ) 
  71. $string = vsprintf( $string, $args ); 
  72.  
  73. $string = trim( $string ); 
  74. $string = wp_kses( $string, array( 
  75. 'a' => array( 
  76. 'href' => true 
  77. ),  
  78. 'br' => true,  
  79. 'em' => true,  
  80. 'strong' => true,  
  81. ) ); 
  82.  
  83. $this->set_main_error_message( $string, $current_error ); 
  84. $this->messages[] = $string;