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

Does not work with PHP 8 or higher #518

Closed Sentixx closed 1 year ago

Sentixx commented 1 year ago

I've been using this updater (self hosted) quiet a while now. But since I needed to update my Webserver to PHP 8 / 8.1 my Plugins including this update-checker can't be activated anymore. Theres is an error with Puc/v5p0/Scheduler.php in line 58. I've been trying to fix it without any success so far. Does anybody had the same error so far and know how to fix it?

YahnisElsts commented 1 year ago

Could you please post the actual error message?

I have a test site running PHP 8.1.6 and I haven't noticed any errors like that.

Sentixx commented 1 year ago

Thats the error directly in Wordpress after installation. The error occurs when I try to activate the Plugin. With PHP 7.4 everything works normally.

Uncaught TypeError: Unsupported operand types: string * int in /html/wordpress/wp-content/plugins/mmw-tools/includes/Puc/v5p0/Scheduler.php:58 Stack trace: #0 /html/wordpress/wp-content/plugins/mmw-tools/includes/Puc/v5p0/Plugin/UpdateChecker.php(81): mmw\PluginUpdateChecker\v5p0\Scheduler->__construct(Object(mmw\PluginUpdateChecker\v5p0\Plugin\UpdateChecker), '...', Array) #1 /html/wordpress/wp-content/plugins/mmw-tools/includes/Puc/v5p0/UpdateChecker.php(95): mmw\PluginUpdateChecker\v5p0\Plugin\UpdateChecker->createScheduler('...') #2 /html/wordpress/wp-content/plugins/mmw-tools/includes/Puc/v5p0/Plugin/UpdateChecker.php(59): mmw\PluginUpdateChecker\v5p0\UpdateChecker->__construct('...', '...', '...', '...', '') #3 /html/wordpress/wp-content/plugins/mmw-tools/includes/Puc/v5p0/PucFactory.php(122): mmw\PluginUpdateChecker\v5p0\Plugin\UpdateChecker->__construct('...', '...', '...', '...', '', '') #4 /html/wordpress/wp-content/plugins/mmw-tools/mmw-tools.php(116): mmw\PluginUpdateChecker\v5p0\PucFactory::buildUpdateChecker('...', '...', '...', '...') #5 /html/wordpress/wp-admin/includes/plugin.php(2314): include_once('...') #6 /html/wordpress/wp-admin/plugins.php(192): plugin_sandbox_scrape('...') #7 {main} thrown in /html/wordpress/wp-content/plugins/mmw-tools/includes/Puc/v5p0/Scheduler.php on line 58

YahnisElsts commented 1 year ago

It sounds like the $checkPeriod argument to buildUpdateChecker() might be set incorrectly. It's optional, but if you do provide it, it should be an integer. What does your buildUpdateChecker call look like (you can edit out the URL if it's private)?

Sentixx commented 1 year ago

The $checkPeriod argument is still default.

require 'includes/plugin-update-checker.php';
use mmw\PluginUpdateChecker\v5\PucFactory;

$myUpdateChecker = PucFactory::buildUpdateChecker(
    'myurl/details.json',
    __FILE__, 'mmw-tools.php',
    'unique-plugin-or-theme-slug'
YahnisElsts commented 1 year ago

There's a comma after __FILE__ that should probably be a period. Alternatively, 'mmw-tools.php' might need to be omitted entirely. Here, I've reformatted the code to show one argument per line, with argument names:

$myUpdateChecker = PucFactory::buildUpdateChecker(
    'myurl/details.json',   //$metadataUrl
    __FILE__,               //$fullPath
    'mmw-tools.php',        //$slug
    'unique-plugin-or-theme-slug' //$checkPeriod <-- 
Sentixx commented 1 year ago

Omitting 'mmw-tools.php' did actually fix it. My buildUpdateChecker call now looks like this: $myUpdateChecker = PucFactory::buildUpdateChecker( 'myurl/details.json', //$metadataUrl __FILE__, //$fullPath 'plugin-slug' //$checkPeriod <--

Thank you

YahnisElsts commented 1 year ago

All right, I'll close this then.