How do I have my plugin pop up with that New version available. Upgrade Automatically
dialog to appear when my plugin has a new version? Specifically for plugins not hosted on the WP.org repository.
Leave a Reply
You must be logged in to post a comment.
This library integrates auto-updates for privately hosted plugins. Looks great.
The easiest way I can think of to do this is to have your plugin “phone home” to check a URL on your website that returns the current version of your plugin.
That way, your plugin (installed on another website) can check its version against the “current” version on your website to see if it’s the same or newer.
Edit: sample code
I should point out before you implement this: this will add a banner across the top of the screen. If you’re just looking to have your plugin show an update available in the menu down the left, I think it automagically does that when you upload the new version to the WordPress repository. If you do want the banner across the top, proceed.
I would create a template specifically for this page so that the header and footer were not included:
That way, all that will get printed is the page content, which is good for what we’re doing.
Next, set up a page that uses this template, say, “latest-plugin-version”. If you view this page in your browser now, all it should say is the text from the page with no extra html.
In your plugin, create a function that prints out your notice. I’ve used inline styles in the example, you can use classes if you want.
And then, to tie it in so that it runs the function:
Now, in your installation function, you should add an option for the version number to be saved in the user’s WordPress:
You can use update_option instead of add_option, as it will add the option if it doesn’t already exist.
That should about do it.
There is a free plugin that allows autoupgrade for privately hosted plugins:
https://github.com/meglio/wp-upgrademe