1

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:

enter image description here

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):

enter image description here

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:

enter image description here

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:

enter image description here

But after update one plugin, just shows me this:

enter image description here

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. :)

1 Answer 1

1

I solved my issue, so for those people who want to achieve the same thing about forcing updates using EDD, here's the solution (or at least worked for me):

First of all, when you update a plugin via the plugins page, it does via AJAX, so I had to read the /wp-admin/includes/ajax-actions.php file, and inside of the wp_ajax_update_plugin() function found that was executing wp_update_plugins() function, so I realized that was overwriting the update_plugins site transient.

At this point, I thought my filters were executing but no, the thing is I was executing those filters inside of the current_screen action, and when the wp_update_plugins() function was called from wp_ajax_update_plugin(), it wasn't listen to them.

So I had to create new filters and execute them when my class is invoked.

And that's it, problem solved. Hope you can find this useful.

1
  • Hello! Could you let us know how you fixed it with the code? Commented Oct 12, 2022 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.