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

Child themes only check when active? #486

Closed plueschpruem closed 2 years ago

plueschpruem commented 2 years ago

Not sure if this is expected or if I am missing something. I have a main theme and a child. The main theme always finds its' updates, the child only when active. I put some error_log() calls in both functions.php – the childs' functions.php doesn't seem to run when the child theme is inactive.

I call it like this:

$templateName = basename(dirname(__FILE__));
error_log("templateName=" . $templateName);
error_log("dirname=" . dirname(__FILE__));
require dirname(__FILE__) . '/plugin-update-checker/plugin-update-checker.php';
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
    'https://deploy.servername.com/wp-update-server-master/?action=get_metadata&slug=' . $templateName,
    __FILE__,
    $templateName
);

Great git by the way, thanks a lot!

YahnisElsts commented 2 years ago

In general, the update checker needs to be loaded and running for updates to work. This usually means that the theme that's using the update checker has to be active - an inactive theme can't run any code.

The only viable workaround that I'm aware of is to put the update checker in another theme or plugin. For example, you could have a helper plugin that handles updates for your theme (or multiple themes). The update checker code would be very similar, except you would need to specify the full path to functions.php or style.css instead of using the __FILE__ constant, and you would also need to set the template name differently.

plueschpruem commented 2 years ago

In general, the update checker needs to be loaded and running for updates to work. This usually means that the theme that's using the update checker has to be active - an inactive theme can't run any code.

Ah OK, thanks for clarifying. I thought I'd seen some themes notify me of updates, although they weren't active. But maybe that's a thing for themes from the WP repository only? But it makes sense – when the child is active, the parent is also active – so both see their updates. And I testted with another theme using your updater – only when active it will register updates – on the themes admin page, as well as on the system update page.

Thanks!