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

Multisite - Plugin only activated on single Site #406

Open danielbarenkamp opened 3 years ago

danielbarenkamp commented 3 years ago

Hi there,

Env: multisite

When a plugin is ONLY activated in one subsite, but not network wide, it does not show the update. Is there any workaround for this?

YahnisElsts commented 3 years ago

As far as I know, the only viable workaround would be to make a new plugin that just runs the update checker, then activate that plugin either network wide or at least on the main network site.

danielbarenkamp commented 3 years ago

That would be a solution! We got a Framework plugin activated in multisite. But how can we run each plugins updater? Is there a function to add more than 1 update URL? Or can we return more update JSON files? Maybe you got a short example?

YahnisElsts commented 3 years ago

You can just create multiple instances of the update checker and give each instance a different update URL and plugin file name / slug.

For example, if you normally initialise the update checker like this:

$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
    'http://example.com/path/to/plugin1.json',
    __FILE__,
    'plugin1'
);

You could rewrite it not to rely on the __FILE__ constant and then have multiple similar blocks of code in one file:

$myUpdateChecker1 = Puc_v4_Factory::buildUpdateChecker(
    'http://example.com/path/to/plugin1.json',
    $pathToPlugin1,
    'plugin1'
);

$myUpdateChecker2 = Puc_v4_Factory::buildUpdateChecker(
    'http://example.com/path/to/plugin2.json',
    $pathToPlugin2,
    'plugin2'
);

Finding the correct plugin file name could be slightly complicated. If you don't need a perfect solution, you could probably just hardcode the directory name and PHP file name: $pathToPlugin1 = dirname(__DIR__) . '/plugin1/main-file.php