Make WordPress Core

Opened 5 years ago

Last modified 6 months ago

#50849 new defect (bug)

Incorrect action passed to hooks when updating plugin/theme by uploading ZIP file

Reported by: desrosj's profile desrosj Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 5.5
Component: Upgrade/Install Keywords: has-patch has-test-info has-unit-tests changes-requested
Focuses: Cc:

Description

When a plugin or theme is being upgraded or downgraded by uploading a new zip file as added in #9757, the action passed in $hook_extra to the upgrader_process_complete action hook is always install, regardless of the action being taken.

Attachments (1)

50849.diff (1.6 KB) - added by desrosj 5 years ago.

Download all attachments as: .zip

Change History (30)

@desrosj
5 years ago

#1 follow-up: @desrosj
5 years ago

  • Milestone changed from Awaiting Review to 5.5.1

It seems the upgrader_process_complete hook is run twice: once when the zip file is uploaded, and again when the actual overwrite takes place after clicking the proceed button.

50849.diff is fixing the second but not the first. I think, ideally, the hook should not fire when uploading a file to update a plugin or theme as the process is no actually complete.

If the decision is to continue firing it in both spots, then $hook_extra should pass along more information as to where the process is at.

#2 @desrosj
5 years ago

  • Version changed from trunk to 5.5

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


5 years ago

#4 @johnbillion
5 years ago

  • Keywords needs-testing added

This ticket was mentioned in Slack in #core-auto-updates by audrasjb. View the logs.


5 years ago

This ticket was mentioned in Slack in #core by desrosj. View the logs.


5 years ago

#7 @desrosj
5 years ago

  • Milestone changed from 5.5.1 to 5.5.2

With 5.5.1 being a shorter cycle, punting this so it can receive proper attention.

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


5 years ago

#9 in reply to: ↑ 1 @hellofromTonya
5 years ago

In the patch, the same code is repeated twice. That makes it less maintainable as any future changes must be made in both places.

Both of these classes are extending off of WP_Upgrader. The code can be abstracted to the base class as a protected method. Then it's available for both the theme and plugin classes to directly invoke that new method.

Maybe something like this in the WP_Upgrader class:

<?php
protected function get_hook_extra_action_type() {
        if (
                ! empty( $this->skin->overwrite )
                &&
                in_array( $this->skin->overwrite, array( 'update-theme', 'downgrade-theme' ), true )
        ) {
                return $this->skin->overwrite;
        }

        return 'install';
}

What do you think @desrosj?

#10 @desrosj
5 years ago

Revisiting this, the hook should not be fired twice. Let's move to fire it only after the replacement is made and the update is complete.

The code can be abstracted to the base class as a protected method. Then it's available for both the theme and plugin classes to directly invoke that new method.

This should be fine! But we'll just need to test all of the different scenarios carefully to confirm.

#11 @whyisjake
5 years ago

@desrosj, with the 5.5.2 release slated for October 29th, how do you feel about wrapping this up?

#12 @whyisjake
5 years ago

  • Milestone changed from 5.5.2 to 5.5.3

@desrosj let me know that this could be pushed to 5.5.3.

#13 @JeffPaul
5 years ago

  • Milestone changed from 5.5.3 to 5.6

We're working on a short cycle 5.5.3 release in the very near future and have no further minor releases planned so I'm punting this to 5.6 in hopes it'll have the patch tested and confirmed for that major release.

This ticket was mentioned in Slack in #core-auto-updates by audrasjb. View the logs.


5 years ago

#16 @hellofromTonya
5 years ago

PR 684 does the following:

  • Applies 50849.diff patch
  • Refactors to encapsulate the theme and plugin code into the base class, ie method get_hook_extra_action
  • Prevents the hook from running during install action. It now only runs when it's actually completed, ie update and downgrade.

Testing Results:

  • Upload plugin with same version: hook ran 1x and 'action' = 'update-plugin'
  • Upload plugin with newer version: hook ran 1x and 'action' = 'update-plugin'
  • Upload plugin with older version: hook ran 1x and 'action' = 'downgrade-plugin'
  • Upload theme with same version: hook ran 1x and 'action' = 'update-theme'
  • Upload theme with newer version: hook ran 1x and 'action' = 'update-theme'
  • Upload theme with older version: hook ran 1x and 'action' = 'downgrade-theme'

@desrosj can you do a code review and test it out please?

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.


5 years ago

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.


5 years ago

#19 @hellofromTonya
5 years ago

  • Milestone changed from 5.6 to Future Release

RC1 is tomorrow. Per conversation in Slack, moving this one to Future Release and @desrosj will review.

Please punt to Future Release, but I’ll add a task for myself to revisit that after 5.6.

#20 @francina
5 years ago

@desrosj how do you feel about this ticket for 5.8? @hellofromTonya do you think it needs a refresh?
Thanks!

This ticket was mentioned in Slack in #core-auto-updates by francina. View the logs.


5 years ago

#22 @justinahinon
5 years ago

It would be nice to know how someone who have no experience with the upgrader can reproduce the issue being mentioned and also test the patch/PR.

#23 @desrosj
5 years ago

Hi @justinahinon! Good point. Here are some steps to test:

Attach a function to the upgrader_process_complete action hook that will log information. This should print the contents of the second parameter to the debug log:

add_action( 'upgrader_process_complete', function( $upgrader, $hook_info ) {
error_log( print_r( $hook_info, true ) );
}, 10, 2 );
  • Attempt to upgrade and downgrade a plugin and theme by uploading a zip file.
  • The information should print to the log twice: once after uploading the zip, and once after clicking the confirmation to replace the installed version with the uploaded version.
  • Also, observe that the action index of the array is always install.
  • Apply patch and repeat.
  • Information should only be printed once, and only after clicking the confirmation (the upload completing does not signify a "complete" process.
  • The action should now be set to upgrade-plugin|theme or downgrade-plugin|theme.

This ticket was mentioned in PR #9104 on WordPress/wordpress-develop by @SirLouen.


7 months ago
#24

Refreshing #684 + Adding Review
Trac ticket: https://core.trac.wordpress.org/ticket/50849

#25 @SirLouen
7 months ago

  • Keywords has-test-info added; needs-testing removed

Combined Bug Reproduction and Patch Test Report

Description

✅ This report validates that the indicated patch works as expected.

Patch tested: https://github.com/WordPress/wordpress-develop/pull/9104.diff

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.2.28
  • Server: nginx/1.29.0
  • Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
  • Browser: Chrome 137.0.0.0
  • OS: Windows 10/11
  • Theme: Twenty Fifteen 4.0
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.0

Testing Instructions

  • Mainly Using these instructions with a Theme and a Plugin
  • 🐞 Results logged displayed in the Artifacts sections below

Actual Results

  1. ✅ Issue resolved with patch, results below

Additional Notes

  1. Another refresh was required.
  2. Added @desrosj review in PR 684
  3. Patch Ready to launch.

Supplemental Artifacts

Results:

Update plugin:

Pre Patch:

[27-Jun-2025 22:19:10 UTC] Array
(
    [type] => plugin
    [action] => install
)

[27-Jun-2025 22:19:13 UTC] Array
(
    [type] => plugin
    [action] => install
)

After Patch:

[27-Jun-2025 22:10:11 UTC] Array
(
    [type] => plugin
    [action] => update
)

Downgrade plugin

Pre Patch:

[27-Jun-2025 22:19:53 UTC] Array
(
    [type] => plugin
    [action] => install
)

[27-Jun-2025 22:19:56 UTC] Array
(
    [type] => plugin
    [action] => install
)

After Patch:

[27-Jun-2025 22:12:02 UTC] Array
(
    [type] => plugin
    [action] => downgrade
)

Upgrade theme

Pre Patch:

[27-Jun-2025 22:16:52 UTC] Array
(
    [type] => theme
    [action] => install
)

[27-Jun-2025 22:16:57 UTC] Array
(
    [type] => theme
    [action] => install
)

After Patch:

[27-Jun-2025 22:13:56 UTC] Array
(
    [type] => theme
    [action] => update
)

Downgrade theme

Pre Patch:

[27-Jun-2025 22:17:45 UTC] Array
(
    [type] => theme
    [action] => install
)

[27-Jun-2025 22:17:47 UTC] Array
(
    [type] => theme
    [action] => install
)

After Patch:

[27-Jun-2025 22:15:13 UTC] Array
(
    [type] => theme
    [action] => downgrade
)
Version 0, edited 7 months ago by SirLouen (next)

#26 @SirLouen
7 months ago

  • Keywords has-unit-tests added

Added some unit testing.

This ticket was mentioned in Slack in #core-test by sirlouen. View the logs.


6 months ago

#28 @yashjawale
6 months ago

Test Report

Description

This report validates whether the indicated patch works as expected.
Instructions followed from comment:23

Patch tested: https://github.com/WordPress/wordpress-develop/pull/9104.diff

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.2.28
  • Server: nginx/1.27.5
  • Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
  • Browser: Firefox 140.0
  • OS: macOS
  • Theme: Twenty Twenty-One 2.5
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.0

Actual Results

  1. ✅ Update/Downgrade actions are logged properly
  2. ✅ Actions are logged once
  3. ⚠️ upgrader_process_complete does not get triggered during first time install of plugin/theme (the action should get triggered even during install according to https://developer.wordpress.org/reference/hooks/upgrader_process_complete/ )

Additional Notes

  • The plugin & theme were tested with version numbers 1.0.0 & 2.0.0

Supplemental Artifacts

Test Results:

Pre patch

Theme install

Array
(
    [type] => theme
    [action] => install
)

Theme upgrade

Array
(
    [type] => theme
    [action] => install
)

Theme downgrade

Array
(
    [type] => theme
    [action] => install
)

Plugin install

Array
(
    [type] => plugin
    [action] => install
)

Plugin upgrade

Array
(
    [type] => plugin
    [action] => install
)

Plugin downgrade

Array
(
    [type] => plugin
    [action] => install
)

Post patch

Theme install

NO LOGS

Theme upgrade

Array
(
    [type] => theme
    [action] => update
)

Theme downgrade

Array
(
    [type] => theme
    [action] => downgrade
)

Plugin install

NO LOGS

Plugin upgrade

Array
(
    [type] => plugin
    [action] => update
)

Plugin downgrade

Array
(
    [type] => plugin
    [action] => downgrade
)

#29 @SirLouen
6 months ago

  • Keywords changes-requested added
Note: See TracTickets for help on using tickets.