As you probably already know, WordPress has a mechanism that detects that the plugins, themes and the kernel itself WordPress have updates. Notify the user when they are available, to receive information about these updates and allows you to automatically install them. However, this only applies to plugins and templates so placed in repositories of WordPress.

Of course, there are ways to extend this mechanism for plugins and themes published on other servers. In the network there are many scripts for the ability to upgrade from GitHub and even from your own server. There are scripts to update with Market Envato (ThemeForest and CodeCanyon). However, all the scripts for the access to the Envato API, which are used today is obsolete because from June 2016 old Envato API will be closed. You must now use the new Envato API. I had to write the script yourself.

Script

The plan

All the upgrading data are provided by the server WordPress, i.e. When your blog requests this data from wordpress.org server, it gets all the necessary information. Envato Server also allows you to receive all the necessary information about updating the plugin that is sold on CodeCanyon (plugins on Envato Market), but with another data structure (other than from WordPress). Therefore our task is to:

  1. Obtain information of the availability of a new version of the plugin and notify WordPress about the existence of it
  2. Obtain information about the plugin for future viewing by the user of the plugin (blog administrator)
  3. Provide access to the file of the new version of the plugin on the server Envato to downloads and updates

All three point plan we can implement using three WordPress filters, namely pre_set_site_transient_update_pluginsplugins_api and upgrader_package_options.

Input Data

The script is implemented as a class (the PLO) and takes two startup parameter necessary for work. In principle, you can modify the class so that incoming data is defined in the class, but the class will lose its versatility.

To ensure the achievement of the objective, we need the following data:

  • $id — ID of the plugin on the Envato Market
  • $data[‘token’] — Personal Token of buyer
  • $data[‘version’] — plugin current version
  • $data[‘slug’] — slug of plugin (i.e.: sam-pro-lite)
  • $data[‘pluginSlug’] — full slug of plugin (plugin folder + name of main plugin file, i.e.: sam-pro-lite/sam-pro-lite.php)
  • $data[‘name’] — name of plugin
  • $data[‘homepage’] – plugin homepage URL, not required

The buyer of the plugin can generate a Personal Token on the website of the Envato API. The minimum set of permissions for the token should be:

token-required-permissions

The constructor of plugin accepts these data as two parameters: a string $id and array $data. After verifying input data constructor assigns methods of class checkUpdate, checkInfo and setUpdatePackage as handlers of filters.

  • pre_set_site_transient_update_plugins — checkUpdate
  • plugins_api — checkInfo
  • upgrader_package_options — getUpdatePackage

Getting Data from Envato API

For getting data from Envato API requires only ID of plugin (Envato Market) and Personal Token of the buyer:

Version Request

This script uses filter pre_set_site_transient_update_plugins for getting available version of plugin from Envato Market. And, if version of plugin on the Envato is greater than current version, reports WordPress on the need to update the plugin.

The result of filter handling:

envato-plugin-update-2

envato-plugin-update

Plugin Info Request

When user (blog admin) clicks “View Details” this class requests Envato API to getting detail plugin information.

The result of filter handling:

envato-plugin-info

Upgrading Plugin

Identifying your plugin using “package” field of options array, previously set to Plugin Slug value. Getting a link to the plugin archive file from Envato and assign it to “package” field.

The result of filter handling:
envato-plugin-upgrade-finish

Class Usage

Include this class into your plugin using “init” action.

Full Script Code

Just include this file in your project and use it.

© 2016, minimus. All rights reserved.