WordPress Self-Hosted Plugin Update API

Have a plugin that can’t be submitted to the official repository?

Code is now on GitHub please see here for updated version.

Many reasons exist but the biggest is that the plugin/support is sold therefore can’t be downloaded for free. But why should the end user be punished after all they bought the plugin and updates should be just as seamless as from the official repo. With this script this can be accomplished. Examples and a package of sample code can be downloaded below.

The original idea and code came from konstruktors.com, but I’ve modified it to add more info and fixed a couple of errors with it. The package containing all the sample code can be downloaded here from GitHub.

First I’ll explain the code that goes onto the update server, this code is found in the api folder of the zip file. Basically you’ll just need to edit and upload the api/index.php file to your server somewhere and then in the update files of your theme/plugin point to that directory.

Theme Update

The theme in $packages[‘theme’] will need to replaced with your theme’s slug most likely it’s theme folder name. This is what is sent to the update server to check for updates. Next you have a versions array. You’ll need to change the 1.0 both places to match the version of the update that is available. Next is the date that the update was published. Not really used in theme updates but still handy to have. Next is the important part the url to the zip file for the update that will be pulled down by WordPress and installed. The info array below this is where you can specifiy a url that will display the theme and some info about it. Normally for themes from the offical repo this will display the page from the extend section.

// Theme with update info
$packages['theme'] = array(
	'versions' => array(
		'1.0' => array(
			'version' => '1.0',
			'date' => '2010-04-10',
			'package' => 'http://url_to_your_site/theme.zip'  // The zip file of the theme update
	'info' => array(
		'url' => 'http://url_to_your_theme_site'  // Website devoted to theme if available

Plugin Update

Now onto the plugin section of the api/index.php file. The plugin in $packages[‘plugin’] will need to be replaced with the plugin’s slug, usually the folder name of the plugin itself. Next is the versions array where 1.0 will need to replaced both time with the version that is in the zip file for the update.

  • version: version of the update
  • date: date the update was published this is used in the plugin details section.
  • author: full name of the author or company publishing the plugin.
  • requires: minimum version of WordPress needed for the plugin to function properly.
  • tested: the version of WordPress the plugin has been tested with.
  • homepage: authors homepage.
  • downloaded: download counter used by wordpress.org but not by the self update api, can be any number.
  • external: link to the page devoted to plugin.
  • package: url to the zip file for the update.
  • sections: is an array to hold the extra info for the plugin details page generated by WordPress.
    • description: Description of Plugin.
    • installation: Install Info
    • Any section can be added not just the ones listed. The first field in the array ie before the => is used as the title of the tab in the plugin info page. The next section is used in the body of the tab.
// Plugin with update info
$packages['plugin'] = array(
	'versions' => array(
		'1.0' => array(
			'version' => '1.0',
			'date' => '2010-04-10',
			'author' => 'Author Name',
			'requires' => '2.8',  // WP version required for plugin
			'tested' => '3.0.1',  // WP version tested with
			'homepage' => 'http://your_author_website',  // Your personal website
			'downloaded'=> '1000',  // Number of times downloaded
			'external' => 'http://your_plugin_website',  // Site devoted to your plugin if available
			'package' => 'http://url_to_your_site/plugin.zip',  // The zip file of the plugin update
			'sections' => array(
				'description' => 'Description of Plugin',
				'installation' => 'Install Info',
				'screen shots' => 'Screen Shots',
				'change log' => 'Change log',
				'faq' => 'FAQ',
				'other notes' => 'Other Notes'
	'info' => array(
		'url' => 'http://your_plugin_webiste'  // Site devoted to your plugin if available

Theme Update script

Now for the script that will need to be added to your theme for the theme to be able to check back to your server for updates. There is a folder called theme/theme-update/ that has a update.php file that is all that is needed. It need to be edited and included from your functions.php file. The value that needs to be edited is $api_url. $api_url is the url to the api/index.php file that you’ve uploaded to your server somewhere. There is also a debug function at the top to reset the transient used for theme updates so that WordPress will check every page load for updates. The should only be used for testing, and should be removed from actual production code, as it would cause massive amounts of traffic to your site.

// TEMP: Enable update check on every request. Normally you don't need this! This is for testing only!
//set_site_transient('update_themes', null);

add_filter('pre_set_site_transient_update_themes', 'check_for_update');

function check_for_update($checked_data) {
	global $wp_version;
	/******************Change this*******************/
	$api_url = 'http://UPDATE SERVER.com/';

Plugin Update script

In the zip package there is a folder test-plugin-update which contains a file called test-plugin-update.php Which is a full plugin but doesn’t do anything except check for updates to itself. The code can just be placed into existing plugin files or into a new file and included from the main plugin file. The plugin update only require one variable be changed $api_url which is the path to the api/index.php file on your update server. This also has the function to check for updates every page load and should be removed from production code. Basically the plugin update has two main functions. One checks for the update the other takes the info from the update check and places it into the plugin update details screen.

About Jeremy Clark

Small town IT worker with interests in all things technological and technical. Biggest interests are in web development especially the WordPress publishing platform and the community supporting it. Currently developing and maintain the free WordPress theme Techozoic. I'm also always available for hire.
This entry was posted in tips, wordpress and tagged , , , . Bookmark the permalink.

143 Responses to "WordPress Self-Hosted Plugin Update API"

Leave a replyLeave a Reply to How to make alert for new version on theme options? | DL-UAT

Comments will be sent to the moderation queue.