TGM_Bulk_Installer

Hack: Prevent TGMPA v2.4.1- bulk installer class from being loaded if 2.4.1- is loaded after 2.5+.

Defined (1)

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

/functions/class-tgm-plugin-activation.php  
  1. class TGM_Bulk_Installer extends WP_Upgrader { 
  2.  
  3. /** 
  4. * Holds result of bulk plugin installation. 
  5. * @since 2.2.0 
  6. * @var string 
  7. */ 
  8. public $result; 
  9.  
  10. /** 
  11. * Flag to check if bulk installation is occurring or not. 
  12. * @since 2.2.0 
  13. * @var boolean 
  14. */ 
  15. public $bulk = false; 
  16.  
  17. /** 
  18. * Processes the bulk installation of plugins. 
  19. * @since 2.2.0 
  20. * @param array $packages The plugin sources needed for installation 
  21. * @return string|boolean Install confirmation messages on success, false on failure 
  22. */ 
  23. public function bulk_install( $packages ) { 
  24.  
  25. /** Pass installer skin object and set bulk property to true */ 
  26. $this->init(); 
  27. $this->bulk = true; 
  28.  
  29. /** Set install strings and automatic activation strings (if config option is set to true) */ 
  30. $this->install_strings(); 
  31. if ( TGM_Plugin_Activation::$instance->is_automatic ) 
  32. $this->activate_strings(); 
  33.  
  34. /** Run the header string to notify user that the process has begun */ 
  35. $this->skin->header(); 
  36.  
  37. /** Connect to the Filesystem */ 
  38. $res = $this->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) ); 
  39. if ( ! $res ) { 
  40. $this->skin->footer(); 
  41. return false; 
  42.  
  43. /** Set the bulk header and prepare results array */ 
  44. $this->skin->bulk_header(); 
  45. $results = array(); 
  46.  
  47. /** Get the total number of packages being processed and iterate as each package is successfully installed */ 
  48. $this->update_count = count( $packages ); 
  49. $this->update_current = 0; 
  50.  
  51. /** Loop through each plugin and process the installation */ 
  52. foreach ( $packages as $plugin ) { 
  53. $this->update_current++; // Increment counter 
  54.  
  55. /** Do the plugin install */ 
  56. $result = $this->run( 
  57. array( 
  58. 'package' => $plugin, // The plugin source 
  59. 'destination' => WP_PLUGIN_DIR, // The destination dir 
  60. 'clear_destination' => false, // Do we want to clear the destination or not? 
  61. 'clear_working' => true, // Remove original install file 
  62. 'is_multi' => true, // Are we processing multiple installs? 
  63. 'hook_extra' => array( 'plugin' => $plugin, ), // Pass plugin source as extra data 
  64. ); 
  65.  
  66. /** Store installation results in result property */ 
  67. $results[$plugin] = $this->result; 
  68.  
  69. /** Prevent credentials auth screen from displaying multiple times */ 
  70. if ( false === $result ) 
  71. break; 
  72.  
  73. /** Pass footer skin strings */ 
  74. $this->skin->bulk_footer(); 
  75. $this->skin->footer(); 
  76.  
  77. /** Return our results */ 
  78. return $results; 
  79.  
  80.  
  81. /** 
  82. * Performs the actual installation of each plugin. 
  83. * This method also activates the plugin in the automatic flag has been 
  84. * set to true for the TGMPA class. 
  85. * @since 2.2.0 
  86. * @param array $options The installation cofig options 
  87. * @return null/array Return early if error, array of installation data on success 
  88. */ 
  89. public function run( $options ) { 
  90.  
  91. /** Default config options */ 
  92. $defaults = array( 
  93. 'package' => '',  
  94. 'destination' => '',  
  95. 'clear_destination' => false,  
  96. 'clear_working' => true,  
  97. 'is_multi' => false,  
  98. 'hook_extra' => array(),  
  99. ); 
  100.  
  101. /** Parse default options with config options from $this->bulk_upgrade and extract them */ 
  102. $options = wp_parse_args( $options, $defaults ); 
  103. extract( $options ); 
  104.  
  105. /** Connect to the Filesystem */ 
  106. $res = $this->fs_connect( array( WP_CONTENT_DIR, $destination ) ); 
  107. if ( ! $res ) 
  108. return false; 
  109.  
  110. /** Return early if there is an error connecting to the Filesystem */ 
  111. if ( is_wp_error( $res ) ) { 
  112. $this->skin->error( $res ); 
  113. return $res; 
  114.  
  115. /** Call $this->header separately if running multiple times */ 
  116. if ( ! $is_multi ) 
  117. $this->skin->header(); 
  118.  
  119. /** Set strings before the package is installed */ 
  120. $this->skin->before(); 
  121.  
  122. /** Download the package (this just returns the filename of the file if the package is a local file) */ 
  123. $download = $this->download_package( $package ); 
  124. if ( is_wp_error( $download ) ) { 
  125. $this->skin->error( $download ); 
  126. $this->skin->after(); 
  127. return $download; 
  128.  
  129. /** Don't accidentally delete a local file */ 
  130. $delete_package = ( $download != $package ); 
  131.  
  132. /** Unzip file into a temporary working directory */ 
  133. $working_dir = $this->unpack_package( $download, $delete_package ); 
  134. if ( is_wp_error( $working_dir ) ) { 
  135. $this->skin->error( $working_dir ); 
  136. $this->skin->after(); 
  137. return $working_dir; 
  138.  
  139. /** Install the package into the working directory with all passed config options */ 
  140. $result = $this->install_package( 
  141. array( 
  142. 'source' => $working_dir,  
  143. 'destination' => $destination,  
  144. 'clear_destination' => $clear_destination,  
  145. 'clear_working' => $clear_working,  
  146. 'hook_extra' => $hook_extra,  
  147. ); 
  148.  
  149. /** Pass the result of the installation */ 
  150. $this->skin->set_result( $result ); 
  151.  
  152. /** Set correct strings based on results */ 
  153. if ( is_wp_error( $result ) ) { 
  154. $this->skin->error( $result ); 
  155. $this->skin->feedback( 'process_failed' ); 
  156. /** The plugin install is successful */ 
  157. else { 
  158. $this->skin->feedback( 'process_success' ); 
  159.  
  160. /** Only process the activation of installed plugins if the automatic flag is set to true */ 
  161. if ( TGM_Plugin_Activation::$instance->is_automatic ) { 
  162. /** Flush plugins cache so we can make sure that the installed plugins list is always up to date */ 
  163. wp_cache_flush(); 
  164.  
  165. /** Get the installed plugin file and activate it */ 
  166. $plugin_info = $this->plugin_info( $package ); 
  167. $activate = activate_plugin( $plugin_info ); 
  168.  
  169. /** Re-populate the file path now that the plugin has been installed and activated */ 
  170. TGM_Plugin_Activation::$instance->populate_file_path(); 
  171.  
  172. /** Set correct strings based on results */ 
  173. if ( is_wp_error( $activate ) ) { 
  174. $this->skin->error( $activate ); 
  175. $this->skin->feedback( 'activation_failed' ); 
  176. /** The plugin activation is successful */ 
  177. else { 
  178. $this->skin->feedback( 'activation_success' ); 
  179.  
  180. /** Flush plugins cache so we can make sure that the installed plugins list is always up to date */ 
  181. wp_cache_flush(); 
  182.  
  183. /** Set install footer strings */ 
  184. $this->skin->after(); 
  185. if ( ! $is_multi ) 
  186. $this->skin->footer(); 
  187.  
  188. return $result; 
  189.  
  190.  
  191. /** 
  192. * Sets the correct install strings for the installer skin to use. 
  193. * @since 2.2.0 
  194. */ 
  195. public function install_strings() { 
  196.  
  197. $this->strings['no_package'] = __( 'Install package not available.', TGM_Plugin_Activation::$instance->domain ); 
  198. $this->strings['downloading_package'] = __( 'Downloading install package from <span class="code">%s</span>…', TGM_Plugin_Activation::$instance->domain ); 
  199. $this->strings['unpack_package'] = __( 'Unpacking the package…', TGM_Plugin_Activation::$instance->domain ); 
  200. $this->strings['installing_package'] = __( 'Installing the plugin…', TGM_Plugin_Activation::$instance->domain ); 
  201. $this->strings['process_failed'] = __( 'Plugin install failed.', TGM_Plugin_Activation::$instance->domain ); 
  202. $this->strings['process_success'] = __( 'Plugin installed successfully.', TGM_Plugin_Activation::$instance->domain ); 
  203.  
  204.  
  205. /** 
  206. * Sets the correct activation strings for the installer skin to use. 
  207. * @since 2.2.0 
  208. */ 
  209. public function activate_strings() { 
  210.  
  211. $this->strings['activation_failed'] = __( 'Plugin activation failed.', TGM_Plugin_Activation::$instance->domain ); 
  212. $this->strings['activation_success'] = __( 'Plugin activated successfully.', TGM_Plugin_Activation::$instance->domain ); 
  213.  
  214.  
  215. /** 
  216. * Grabs the plugin file from an installed plugin. 
  217. * @since 2.2.0 
  218. * @return string|boolean Return plugin file on success, false on failure 
  219. */ 
  220. public function plugin_info() { 
  221.  
  222. /** Return false if installation result isn't an array or the destination name isn't set */ 
  223. if ( ! is_array( $this->result ) ) 
  224. return false; 
  225. if ( empty( $this->result['destination_name'] ) ) 
  226. return false; 
  227.  
  228. /** Get the installed plugin file or return false if it isn't set */ 
  229. $plugin = get_plugins( '/' . $this->result['destination_name'] ); 
  230. if ( empty( $plugin ) ) 
  231. return false; 
  232.  
  233. /** Assume the requested plugin is the first in the list */ 
  234. $pluginfiles = array_keys( $plugin ); 
  235.  
  236. return $this->result['destination_name'] . '/' . $pluginfiles[0]; 
  237.  
  238.