Open Geczy opened 12 years ago
This is a simple problem, with a complex answer..
Here is the root of the issue:
add_filter( 'upgrader_post_install', array( $this, 'upgrader_post_install' ), 10, 3 );
Call this function after EVERY plugin upgrade:
/**
* Upgrader/Updater
* Move & activate the plugin, echo the update message
*
* @since 1.0
* @param boolean $true always true
* @param mixed $hook_extra not used
* @param array $result the result of the move
* @return array $result the result of the move
*/
public function upgrader_post_install( $true, $hook_extra, $result ) {
global $wp_filesystem;
// Move & Activate
$proper_destination = WP_PLUGIN_DIR.'/'.$this->config['proper_folder_name'];
$wp_filesystem->move( $result['destination'], $proper_destination );
$result['destination'] = $proper_destination;
$activate = activate_plugin( WP_PLUGIN_DIR.'/'.$this->config['slug'] );
// Output the update message
$fail = __( 'The plugin has been updated, but could not be reactivated. Please reactivate it manually.', 'github_plugin_updater' );
$success = __( 'Plugin reactivated successfully.', 'github_plugin_updater' );
echo is_wp_error( $activate ) ? $fail : $success;
return $result;
}
get_plugin_info has a fail safe, to ensure it is looking for the right plugin:
/**
* Get Plugin info
*
* @since 1.0
* @param bool $false always false
* @param string $action the API function being performed
* @param object $args plugin arguments
* @return object $response the plugin info
*/
public function get_plugin_info( $false, $action, $response ) {
// Check if this call API is for the right plugin
if ( !isset( $response->slug ) || $response->slug != $this->config['slug'] )
return false;
.....
We need to add similar solution to upgrader_post_install
For the time being, I would just recommend replacing the function with the following:
/**
* Upgrader/Updater
* Move & activate the plugin, echo the update message
*
* @since 1.0
* @param boolean $true always true
* @param mixed $hook_extra not used
* @param array $result the result of the move
* @return array $result the result of the move
*/
public function upgrader_post_install( $true, $hook_extra, $result ) {
global $wp_filesystem;
if( isset($this->config['slug']) && $hook_extra['plugin'] && $this->config['slug'] == $hook_extra['plugin'] ){
// Move & Activate
$proper_destination = WP_PLUGIN_DIR.'/'.$this->config['proper_folder_name'];
$wp_filesystem->move( $result['destination'], $proper_destination );
$result['destination'] = $proper_destination;
$activate = activate_plugin( WP_PLUGIN_DIR.'/'.$this->config['slug'] );
// Output the update message
$fail = __( 'The plugin has been updated, but could not be reactivated. Please reactivate it manually.', 'github_plugin_updater' );
$success = __( 'Plugin moved and reactivated successfully.', 'github_plugin_updater' );
echo is_wp_error( $activate ) ? $fail : $success;
return $result;
}
return $result;
}
This is not heavily tested, but it worked for me. If someone else wants to tidy it up, and generated a pull request I would appreciate it.
With this plugin activated, whatever third party plugin I install will take the folder name defined in proper_folder_name