I'm developing a plugin that needs to do some force update checks for other plugins that I host on my site with EDD, so I had this UI:
And when the user clicks on the Update button, it does an API request to my site and decide if there's a new version available for that plugin; if there is a new version, I save some plugin data in a transient.
After that, the user needs to go to the Plugins page, and with the data that we just saved in the transient, we obtain the package download and more information about the plugin using the EDD_SL_Plugin_Updater class and do a force update check by resetting the update_plugins
site transient:
$modules_to_update = ! $this->update_plugins ? $this->current_modules->modules : $this->update_plugins;
array_walk( $modules_to_update, array( $this, 'check_plugins_updates' ) );
private function check_plugins_updates( $module_data, $module_name ) {
$plugin_constants = parent::get_plugin_constants_values( $module_name );
if ( $this->update_plugins ) {
new WPB_EDD_SL_Plugin_Updater( $this->current_modules->api_url, $plugin_constants['basename'], $module_data );
/**
* Reset the "update_plugins" site transient,
* so it can do a force check plugin update.
*
* This is extremely necessary, because WordPress check
* plugins after hours or even minutes, sometimes.
*/
set_site_transient( 'update_plugins', '' );
return;
}
}
It's all good so far, we get the plugins updates (In this image, the user clicked on the Update button for both plugins):
Then, the user update one plugin, and updates it correctly, with no error. But, if the user tries to update another plugin, let's say WP Bullet Assets Manager, gets an error:
Update Failed: Plugin update failed.
And in the developers console says:
The plugin is at the latest version.
And this is the response for the AJAX update:
But if the user update, for example, Contact Form 7, updates it correctly.
Also, I have to use the upgrader_process_complete
action hook to set up the update_plugins
site transient again, if I don't do that, the other update disappears.
The good thing here is, if I refresh the plugins page after one plugin updated, the other plugin updates normally, because I still have the plugin data in the transient.
So, I'm stuck there.
Also, I checked the update_plugins
transient content and notice that when all is working, it shows me this:
But after update one plugin, just shows me this:
You can check the transient content here:
The good one: https://www.unserialize.com/s/41cddcdd-bd49-9de9-330e-000062c8267b
The bad one: https://www.unserialize.com/s/364b6ebe-e29b-4fc8-4360-0000723d32b8
Does anyone have created something like I want to do? I will really appreciate it.
Thanks for your time. :)