YahnisElsts / plugin-update-checker

A custom update checker for WordPress plugins. Useful if you don't want to host your project in the official WP repository, but would still like it to support automatic updates. Despite the name, it also works with themes.
MIT License
2.22k stars 403 forks source link

Invalid data in site options after updating the package #498

Closed light-source closed 2 years ago

light-source commented 2 years ago

Hello. I've updated your package via composer from v4.11 to v4.12 and it have been giving me a warning, call_user_func() expects parameter 1 to be a valid callback, class 'x\Puc_v4p11_Plugin_Update' not found (in the StateStore.php, 'load' method). After a small research I got that for some reasons this class had been written in site options, so became invalid after the update. I fixed it manually with a call delete_site_option($this->optionName) once and it's gone. But I think it's an issue and should be fixed, so nobody gets it during next updates. Thank you in advance for looking into it.

YahnisElsts commented 2 years ago

Does 'x\Puc_v4p11_Plugin_Update' imply that you added a custom namespace to the library? My guess would that this is what indirectly triggered the error. Unfortunately, the part of the code that decides which class to use to load a stored update is not namespace-aware. This means that it would not have been able to determine the base class (Pugin_update) and would try to use the version-specific class Puc_v4p11_Plugin_Update which no longer exists in 4.12.

I'll see if I can fix StateStore to support namespaces for the next release.

light-source commented 2 years ago

Yes, I've added a namespace via Scoper. Please have a look, because your package is a critical part of any WP plugin (that uses it), it means there is no way even to add a temporary fix down the line if the updater's logic is broken.

YahnisElsts commented 2 years ago

This should be fixed by the last two commits, but I don't have much personal experience with PHP Scoper and I haven't tested this patch.

YahnisElsts commented 2 years ago

Do you perhaps have an opportunity to test this fix? If it works, I'll make a new release.

light-source commented 2 years ago

I've tested with the master branch, and it has no warning anymore. Thank you. Firstly I thought that the wrong data in site options leads to a case, when new versions are unavailable constantly, but then I read your comment to the fixing commit and got that it had had auto fixing with the first checking for updates, so the issue wasn't so big as I thought and was relating to the PHP warning only. But anyway I'm glad it's fixed.

YahnisElsts commented 2 years ago

I've made a new release that includes this fix.

light-source commented 2 years ago

Thank you kindly.