Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the upgrader_process_complete hook for wp_theme_has_theme_json #45881

Merged
merged 1 commit into from
Nov 18, 2022

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented Nov 18, 2022

Follow-up to #45543

What

This properly sets up the hook upgrader_process_complete, given it all the info it needs about.

Why

Without this, the upgrade process (translations, plugins, themes, core) will report a fatal in the logs (although it will proceed and complete).

How

Telling the hook the callback will receive two parameters (note the last parameter, it'll be 1 by default):

add_action( 'hook_name', 'callback', 10, 2 );

Test instructions

Verify the bug exists:

  • Check out the 14.5.3 branch (it should also happen in trunk): git checkout -b 14.5.3 14.5.3.
  • Go to a site.
  • Downgrade any plugin you have to a previous version. I've used create-block-theme and the wp-cli: wp plugin update create-block-theme --version=1.3.7. See how to use the wp-cli with the bundled wp-env.
  • Go to the plugins admin page and upgrade the plugin.
  • The expected result is that it works as expected and no notices are shown. Instead, what happens is that the upgrade is completed, but a notice is shown in the screen. If you inspect the logs you'll see something like:
[18-Nov-2022 09:21:15 UTC] PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function _wp_theme_has_theme_json_clean_cache_upon_upgrading_active_theme(), 1 passed in /home/andre/flywheel-sites/wordpress-nightly/app/public/wp-includes/class-wp-hook.php on line 310 and exactly 2 expected in /home/andre/src/gutenberg/lib/compat/wordpress-6.2/get-global-styles-and-settings.php:67
Stack trace:
#0 /home/andre/flywheel-sites/wordpress-nightly/app/public/wp-includes/class-wp-hook.php(310): _wp_theme_has_theme_json_clean_cache_upon_upgrading_active_theme(Object(Plugin_Upgrader))
#1 /home/andre/flywheel-sites/wordpress-nightly/app/public/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters('', Array)
#2 /home/andre/flywheel-sites/wordpress-nightly/app/public/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#3 /home/andre/flywheel-sites/wordpress-nightly/app/public/wp-admin/includes/class-plugin-upgrader.php(371): do_action('upgrader_proces...', Object(Plugin_Upgrader), Array)
#4 /home/andre/flywheel-sites/wordpress-nightly/app/public in /home/andre/src/gutenberg/lib/compat/wordpress-6.2/get-global-styles-and-settings.php on line 67

Verify this PR fixes it:

  • Reproduce the same instructions using this PR.
  • Verify that there's no fatal errors reported (in the screen and the log).

@codesandbox
Copy link

codesandbox bot commented Nov 18, 2022

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@oandregal oandregal changed the title Tell the hook how many parameters there are Fix the upgrader_process_complete hook for wp_theme_has_theme_json Nov 18, 2022
@oandregal oandregal self-assigned this Nov 18, 2022
@oandregal oandregal added the [Type] Bug An existing feature does not function as intended label Nov 18, 2022
Copy link
Contributor

@mmtr mmtr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the speedy fix!

@oandregal
Copy link
Member Author

We may want to create a 14.5.4 release with this fix. I'm unavailable to do it now, pinged folks privately to check availability. I'd appreciate if anyone else can help with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants