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.26k stars 410 forks source link

Feature request: enable automatic plugin updates support (since WordPress 5.5) #393

Closed elzadj closed 4 years ago

elzadj commented 4 years ago

Hello Yahnis!

Are you planning to add support for the new 'enable auto-updates' WordPress feature? https://make.wordpress.org/core/2020/07/15/controlling-plugin-and-theme-auto-updates-ui-in-wordpress-5-5/

Thanks.

YahnisElsts commented 4 years ago

The current release should already support that feature. If you're using the latest version (4.10), you should see an "enable auto-updates" link next to your plugin.

Naturally, this will only work while your plugin/theme is active - the update checker needs to be running to provide updates.

rajatvarlani commented 4 years ago

@YahnisElsts In the version 4.10, the plugin using this library is showing the link "enable auto-updates" and the message - "Automatic update scheduled in 6 hours.". But it's not auto-updating the plugin even though next version is available. Is there anything else we need to do to make it work?

YahnisElsts commented 4 years ago

No, I don't think you need to do anything more. I tested it on one of my live sites just a few days ago and WordPress successfully updated the plugin and sent me a "Some plugins were automatically updated" notification.

Are you doing anything special with your updates, like requiring a license key, or only initialising the update checker when is_admin() is true, or anything like that? If so, make sure that PUC is also initialised and a download link is available in the context of an unattended update.

rajatvarlani commented 4 years ago

Yes, there is a condition if ( is_admin() && isset( $options['license_key'] ) && $options['license_key'] != '' ) which needs to be true to call Puc_v4_Factory::buildUpdateChecker. Even if this condition is met, add-on is not being auto-updated. Can you guide me in the right direction how am I supposed to use the auto-update feature of WordPress in this case?

YahnisElsts commented 4 years ago

I can't answer that with confidence as I'm not very familiar with the internal workings of automatic updates. However, one simple thing that I would recommend is to try removing the is_admin() condition. My guess would be that automatic updates happen inside a cron request and is_admin() may be false in that case.

DavidAnderson684 commented 4 years ago

Yahnis is absolutely right; is_admin() will return false when the WP auto-updates cron job is running.

rajatvarlani commented 4 years ago

Thanks. Removing the is_admin() condition made it work.