#49915 closed defect (bug) (invalid)
Function registered on `upgrader_process_complete` does not run on first update.
| Reported by: | apedog | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Upgrade/Install | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
Adding the following line to a plugin will not run on first plugin update:
add_action( 'upgrader_process_complete', 'my_upgrade_routine', 10, 2 );
However on subsequent plugin upgrades it will run.
ie. my_upgrade_routine() will only run if it had already been registered on a previous plugin update.
It will not run if it was added in current update.
I'm assuming this also happens if the function name is changed. I've not tested this.
I have a custom plugin that updates from a github repo using a third-party plugin updater (that is reliable and stable).
I am testing this by manually running wp_version_check from WP-Crontrol plugin page.
Change History (5)
#3
in reply to: ↑ 2
@
6 years ago
Replying to apedog:
@pbiron
You said in slack that you might take a look at this. Did you get a chance?
No, I haven't had the time. Will try to in the next few days.
#4
@
6 years ago
- Resolution → invalid
- Status new → closed
After discussion on slack, it's been made clear that this is expected behaviour.
- The
upgrader_process_completeis not meant to be used to run plugin update routines. Only cleanup/logging/setting transients etc. - No code from the updated plugin can be run during the upgrade process. Only the old version of the plugin is available during the request.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Follow-up:
I ran further tests on this. Basically what happens is the plugin runs the old pre-upgrade function and not the post-upgrade version of the function. Strangely enough, if
get_plugin_data()is called from within the upgrade function it will reference the new post-upgrade header.So if the old plugin had this in version 1.0:
And the upgraded plugin has this in version 1.1:
After upgrading to 1.1,
get_option('my_plugin_version_header')will return1.1butget_option('my_plugin_version_hardcoded')will return1.0@pbiron
You said in slack that you might take a look at this. Did you get a chance?