$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>How to test 'upgrader_process_complete' hook in plugin development?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How to test 'upgrader_process_complete' hook in plugin development?

matteradmin9PV0评论

I maintain and develop several plugins in the WP repo and have been wanting to deploy some update that display notices/setups new settings for installations that are upgrading to the new version of the plugin. However, it is not possible to manually update a plugin on one's localhost (there is a feature request for this to be included in WP core). I found this post on reddit with some interesting suggestions, namely

  1. update the code in the WP repo but keep the same current version number, install a lower version number on a localhost and trigger the update via the dashboard.
  2. use the Github-Updater plugin to update the plugin from a github repo, however not sure if this works. Going to try and come back to post the results here.
  3. can trigger updates by using the WP Rollback plugin to rollback your plugin version. This sounds a little convoluted, one would have to code the reverse logic to test it.
  4. Use the Updater plugin which claims it can update from a zip file. (going to test this)

I guess one of the above should do the trick. However, has anyone else come across this problem? What solution have you used?

[EDIT] Option 4 does not trigger the update hook, it simply deactivates/removes the old plugin and installs the new one.

I maintain and develop several plugins in the WP repo and have been wanting to deploy some update that display notices/setups new settings for installations that are upgrading to the new version of the plugin. However, it is not possible to manually update a plugin on one's localhost (there is a feature request for this to be included in WP core). I found this post on reddit with some interesting suggestions, namely

  1. update the code in the WP repo but keep the same current version number, install a lower version number on a localhost and trigger the update via the dashboard.
  2. use the Github-Updater plugin to update the plugin from a github repo, however not sure if this works. Going to try and come back to post the results here.
  3. can trigger updates by using the WP Rollback plugin to rollback your plugin version. This sounds a little convoluted, one would have to code the reverse logic to test it.
  4. Use the Updater plugin which claims it can update from a zip file. (going to test this)

I guess one of the above should do the trick. However, has anyone else come across this problem? What solution have you used?

[EDIT] Option 4 does not trigger the update hook, it simply deactivates/removes the old plugin and installs the new one.

Share Improve this question asked Jan 22, 2019 at 6:35 AurovrataAurovrata 1,34611 silver badges18 bronze badges 2
  • And what is your problem exactly with manual update? – Krzysiek Dróżdż Commented Jan 22, 2019 at 7:19
  • it does not trigger the update hook – Aurovrata Commented Jan 22, 2019 at 7:23
Add a comment  | 

1 Answer 1

Reset to default -1

OK, so you want to do something after update (let's say add some DB table, change its structure or something like that).

The feature request you mention is very old and I don't believe it would be solved - because there is no need for that feature.

There are many scenarios, when your plugin won't be notified that its version changed:

  1. User manually uploads newer version and performs update.
  2. User goes to FTP and overwrites plugin directory with newer version.
  3. User deletes the plugin and uploads newer version.
  4. User used your plugin in old version some time ago and now uploads it again using FTP.

So what? All of these cases should cause update notification? No, I don't believe so.

The update notification is an event that is meant to notify you, that plugin updater ended its job. You can log it, you can send some notification emails, and so on.

But you shouldn't rely on it to perform any actions for newer version of a plugin. And these cases above show you why.

On the other hand - if your plugin won't work, then it's its fault, not WP. And when you go to Codex page for that hook, you'll see:

The upgrader_process_complete action hook is run when the download process for a plugin install or update finishes.

It is passed two arguments: an instance of the WP_Upgrader() class and the $hook_extra array.

Use with caution: When you use the upgrader_process_complete action hook in your plugin and your plugin is the one which under upgrade, then this action will run the old version of your plugin.

So I don't believe you should use this action in your case at all...

So how other plugins take care of that?

One of the common practice is versioning the DB. (WP also does it). You can put an option and store your plugin version in there. Your plugin may check that version and if it sees, that this option is different than its version, then DB update (or any other operations) has to be done.

Post a comment

comment list (0)

  1. No comments so far