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

How to do a really automatic plugin update #487

Open carlosGedesprin opened 2 years ago

carlosGedesprin commented 2 years ago

I'm not familiar with this plugin but it seems to tick all my boxes, so thanks YahnisElsts to offer it. One of the things I'm looking for is a way to update my plugin without the need of "human intervention". I would like my plugin to detect if a new version is available and if so install it silently. Am I a fool?

YahnisElsts commented 2 years ago

That is technically possible, but this update checker doesn't provide it as a built-in feature. Instead, you would need to use some custom code to enable fully automatic updates for your plugin. WordPress has a few filters for that. See the Configuring Automatic Background Updates page for more information. The section "Plugin & Theme Updates via Filter" is particularly relevant:

https://wordpress.org/support/article/configuring-automatic-background-updates/#plugin-theme-updates-via-filter

carlosGedesprin commented 2 years ago

Thanks you so much for this info. As a suggestion, it could be great to improve so good plugin library with an option who does this. Unfortunately I'm not very good with WP plugins otherwise I would offer to do it.

YahnisElsts commented 2 years ago

That has been suggested before in #121. Personally, I still think it seems too simple to be worth adding as an option: if someone knows enough about PHP and plugin development to successfully set up and use a custom update checker, they can probably write 4-5 lines of code to enable automatic background updates.

That said, I'll add this idea to the list of possible future enhancements.

ddur commented 2 years ago

Actually, WordPress built-in automatic update does work for me.

But. Enable/Disable auto-update link (on Plugins page) does not appear (after first install or until first successful get-metadata, not sure now) until clicking on plugin "Check For Updates" or after first automatic update check (12h).

ddur commented 2 years ago

Activating (forcing) automatic updates is as simple as adding your plugin to array of automatic update basenames.

    $auto_updates = (array) get_site_option( 'auto_update_plugins', array() );
    if ( ! in_array( $plugin->get_basename(), $auto_updates, true ) ) {
        do something;
    }

Unfortunately I deleted update code, can't remember details. Because I decided to leave auto-update decision to plugin administrators, and just show warning notice when auto-update is not enabled.