satispress icon indicating copy to clipboard operation
satispress copied to clipboard

Check for inactive theme updates

Open bradyvercher opened this issue 5 years ago • 8 comments

Many commercial themes bundle their updaters, so a theme needs to be active in order for it to hook into the update process. WordPress is never aware of new releases for inactive themes, so updates can't be cached and made available to Composer, which means SatisPress is really only beneficial for a single theme at a time.

I'm thinking it might be possible to run a background process that cycles through the themes, filters the active theme, and checks for updates without affecting which theme is actually active for visitors to the site.

bradyvercher avatar Aug 31 '18 16:08 bradyvercher

This is somewhat trickier than I first thought.

Since a theme needs to be active for its codebase to be loaded (including the bundled updater), an event would need to be scheduled to loop through installed themes, which would then fire off an async request for each theme. The listener for the loopback request would filter the active theme to load its codebase, then trigger the update check process that the theme would hook into to check for its own updates.

I researched a few updaters and aside from WordPress.org, inactive WooCommerce and Envato themes are already handled by their respective updater plugins (the updaters aren't bundled in the themes). That leaves themes using the EDD updater, Genesis, and other custom updaters.

WordPress calls wp_update_themes() to check for theme updates, but doesn't provide any hooks, so most updaters hook into the site_transient_update_themes or pre_set_site_transient_update_themes filters. Since we don't want to ping wordpress.org, calling wp_update_themes() doesn't really provide any benefit and would require jumping through a bunch of hoops. Instead, reading the update_themes transient and saving it should trigger an update check for the active theme. It's not very precise, but that's the API WordPress gives us to work with.

The EDD updater appears to only run during admin requests, so the async loopback listener would probably have to mimic an admin request. As an aside, does that mean EDD doesn't check for updates during cron events?

Considering all the gotchas, I'm wondering if this is a worthwhile pursuit. Is anyone using SatisPress to make multiple themes available through Composer?

Also, making this a generic plugin independent of SatisPress might be a better route. That would make the functionality optional, but it could also provide security benefits for users that have a bunch of inactive themes and want to be aware of updates.

bradyvercher avatar Sep 07 '18 17:09 bradyvercher

GitHub Updater manages inactive theme updates.

I also have a setting to allow for using remote management services which basically also runs the code on index.php in addition to admin requests.

Feel free to borrow whatever code you may need.

afragen avatar Jan 30 '19 02:01 afragen

@afragen Thanks! I have some stuff in a local branch, but haven't tested it much. Do you have a link to where GitHub Updater handles updates for inactive themes? Also, have you run across issues with themes not updating if the code wasn't run on index.php?

bradyvercher avatar Jan 30 '19 17:01 bradyvercher

@bradyvercher GitHub Updater runs through the list of installed plugins and themes looking for the appropriate headers (eg. GitHub Plugin URI, GitHub Theme URI, etc.). Because the GitHub Updater plugin is active the plugins and themes don't need to be active. The Plugins.php and Themes.php classes are where this happens.

Take a look at the Remote Management tab in GitHub Updater. The settings all do the same thing. They add index.php to the list of pages that GitHub Updater runs. https://github.com/afragen/github-updater/blob/58a01a4728054507f4e8e0253d3a987d32c0bc11/src/GitHub_Updater/Remote_Management.php#L84

I also have a filter so you can add you pages of your choice. The above uses this filter. https://github.com/afragen/github-updater/blob/58a01a4728054507f4e8e0253d3a987d32c0bc11/src/GitHub_Updater/Init.php#L150

The only times I've seen issues with plugins/themes not running on index.php is for remote management services like, MainWP, ManageWP, etc. That's why I added it. If the update is being requested from the site the plugin (GitHub Updater or Satispress) is active on then this shouldn't be an issue.

This works for GitHub Updater because there is no bundled updater with the plugins/themes. FWIW, I also have a plugin to automatically add plugins/themes to GitHub Updater even if they don't contain the required headers. https://github.com/afragen/github-updater-additions

afragen avatar Jan 30 '19 18:01 afragen

@bradyvercher, any news on that?

Is anyone using SatisPress to make multiple themes available through Composer?

Yes. Currently, we have installed 4 premium themes.

tyrann0us avatar Oct 07 '19 12:10 tyrann0us

@bradyvercher Could a way around this be scripting WP-CLI to cycle through the list of installed plugins and activate / update / deactivate them one by one?

binaryfire avatar Jan 23 '20 20:01 binaryfire

@binaryfire It might be possible to do something with WP-CLI, but that would add an extra dependency and a manual step, which I'd like to avoid.

I've kept this issue open to gauge interest. Are you running into issues managing multiple premium themes?

bradyvercher avatar Jan 23 '20 22:01 bradyvercher

@bradyvercher Sorry about the delay in replying. Yeah, managing multiple premium themes has been an issue. Right now I've scripted a daily activation / deactivation cycle using WP-CLI as a workaround

binaryfire avatar May 08 '20 23:05 binaryfire