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

Update requires version number change in both the update json file and the plugin's main php file #501

Closed kimaldis closed 1 year ago

kimaldis commented 1 year ago

Just checking that I have this right because the readme only mentions changing the version number in the .json file.

The only way I can get an update to happen is by changing the version number in the .json file and in the plugin's main php file before zipping it and uploading to my repository server. Is that correnct.

YahnisElsts commented 1 year ago

If you're just using a .json file, changing the version number in the .json file should be sufficient (though you will get strange results if that number doesn't match the actual plugin version number).

However, in other setups, you may need to do something else instead. What do you mean by "repository server" in this context? Is it a Git/SVN repository? Or are you perhaps using wp-update-server? Or something else?

kimaldis commented 1 year ago

I'm just dropping the zipped plugin and the .json file into a directory on my web site then:

require __DIR__ . '/plugin-update-checker/plugin-update-checker.php';

$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
    'http://<mysite>/WP_Repository/Peanut/peanut-plugin-updater.json',
    __FILE__, //Full path to the main plugin file or functions.php.
    'Peanut' // slug
);
YahnisElsts commented 1 year ago

In that case, you should only need to change the version number in the JSON file. That should be enough for the update checker to detect an update. Are you saying that this doesn't work, and the update only shows up if you also change the version number in the zipped plugin?

kimaldis commented 1 year ago

So, if I change just the version number in the JSON file, go to the plugins page and it tells me there's an update. So I update and the page refreshes and tells me the update has happened. However, next time I go to the plugins page, the plugin shows the old version and it's telling me I need to upgrade to the version I changed in the JSON file.

YahnisElsts commented 1 year ago

Ah, I think I see what the problem might be. The update checker will not automatically change the Version header in your main plugin file to match what's in the JSON file. You still need to do that manually when you're actually releasing a new version.

I didn't specifically call that out in the readme because, to me, that's just a routine part of plugin development that you always need to do, no matter what update checker you're using. You have to change the version number if your plugin is hosted on wordpress.org, if you're directly installing updates from a VCS repository, if you're using something like Freemius, etc.

As for the scenario that you described, that sounds like the expected behavior if you only change the version number in the JSON file and not the plugin. The update shows up, and you can successfully download and install the update. This can be useful for testing that updates work. Of course, since the "update" that you installed is not actually a new version (i.e. it has the old version number), the update checker soon checks for updates again, notices that the version in the JSON file is newer, and displays another update notification.

kimaldis commented 1 year ago

Yeah, that all makes sense. I just wanted to make sure I wasn't missing something obvious.

Thanks for your time.

YahnisElsts commented 1 year ago

All right, I'll close this now.