[wp-trac] [WordPress Trac] #49915: Function registered on `upgrader_process_complete` does not run on first update.

WordPress Trac noreply at wordpress.org
Tue Jun 16 09:42:13 UTC 2020


#49915: Function registered on `upgrader_process_complete` does not run on first
update.
-----------------------------+------------------------------
 Reporter:  apedog           |       Owner:  (none)
     Type:  defect (bug)     |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Upgrade/Install  |     Version:
 Severity:  normal           |  Resolution:
 Keywords:                   |     Focuses:
-----------------------------+------------------------------

Comment (by apedog):

 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:
 {{{#!php
 add_action( 'upgrader_process_complete', 'my_upgrade_routine', 10, 2 );
 function my_upgrade_routine( $upgrader_object, $options ){
         if(
                 $options['action'] == 'update'
                 &&
                 $options['type'] == 'plugin'
                 &&
                 (
                         (
                                 isset( $options['plugins'] )
                                 &&
                                 in_array( plugin_basename( __FILE__ ),
 $options['plugins'])
                         )
                         ||
                         (
                                 isset( $options['plugin'] )
                                 &&
                                 plugin_basename( __FILE__ ) ==
 $options['plugin']
                         )
                 )
         ){
                 $plugin_data = get_plugin_data( __FILE__, false);
                 $header_version = $plugin_data['Version'];
                 update_option( 'my_plugin_version_header', $header_version
 );
                 update_option( 'my_plugin_version_hardcoded', '1.0' );
         }
 }
 }}}

 And the upgraded plugin has this in version 1.1:
 {{{#!php
                 $plugin_data = get_plugin_data( __FILE__, false);
                 $header_version = $plugin_data['Version'];
                 update_option( 'my_plugin_version_header', $header_version
 );
                 update_option( 'my_plugin_version_hardcoded', '1.1' );
 }}}

 After upgrading to 1.1, {{{get_option('my_plugin_version_header')}}} will
 return {{{1.1}}} but {{{get_option('my_plugin_version_hardcoded')}}} will
 return {{{1.0}}}

 @pbiron
 You said in slack that you might take a look at this. Did you get a
 chance?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49915#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list