Skip to main content

Updater

Plugin and theme updater module

Based on:

Source code​

https://github.com/tangibleinc/updater

Install​

Add as dependency in composer.json and run composer update.

{
"repositories": [
{
"type": "vcs",
"url": "[email protected]:tangibleinc/updater"
}
],
"require": {
"tangible/updater": "dev-main"
},
"minimum-stability": "dev"
}

Or install as a module in tangible.config.js.

export default {
install: [
{
git: '[email protected]:tangibleinc/updater',
dest: 'vendor/tangible/updater',
branch: 'main',
},
]
}

Use​

After loading the updater, its newest version instance is ready on plugins_loaded action.

use tangible\updater;

require_once __DIR__ . '/vendor/tangible/updater/index.php';

add_action('plugins_loaded', function() {

updater\register_plugin([
'name' => 'example-plugin',
'file' => __FILE__
]);
});

Register the plugin with its name and file path.

Framework​

When registering with the Framework module, the same plugin instance can be passed to the Updater.

use tangible\framework;
use tangible\updater;

require_once __DIR__ . '/vendor/tangible/framework/index.php';
require_once __DIR__ . '/vendor/tangible/updater/index.php';

add_action('plugins_loaded', function() {

$plugin = framework\register_plugin([
'name' => 'example-plugin',
// ...
]);

updater\register_plugin($plugin);
});

Cloud​

Optionally set the property cloud_id to pass additional parameters to the update server.

updater\register_plugin([
'name' => $plugin->name,
'file' => __FILE__,
'cloud_id' => '', // Plugin ID (Required)
'updater_url' => '', // Update server URL (Optional)
'activation_url' => '', // License activation URL (Optional)
]);

Licensing​

This feature requires a plugin to be registered with the Framework module, which adds a plugin settings page.

The plugin needs to register a settings tab for the user to enter a license key. The saved value is passed in the request to the update server.

use tangible\framework;
use tangible\updater;

$plugin = framework\register_plugin([ ... ]);

framework\register_plugin_settings($plugin, [
'tabs' => [
'license' => [
'title' => 'License',
'callback' => function($plugin) {
updater\render_license_page($plugin);
}
],
],
]);

Develop​

Prerequisites: Git, Node, Docker

Clone project and install dependencies.

git clone https://github.com/tangibleinc/updater
cd updater
npm install

Dev dependencies​

Optionally, install dev dependencies for testing.

npm run install:dev

To keep them updated, run:

npm run update:dev

Local site​

Start local dev server for WordPress test site using wp-env.

npm run start

When running the first time, install Composer dev dependencies for testing.

npm run composer:install

Run tests.

npm run test

Stop the server.

npm run stop

Remove Docker images and volumes for the sites.

npm run destroy

Customize environment​

Create a file named .wp-env.override.json to customize the WordPress environment. This file is listed in .gitignore so it's local to your setup.

It's useful for changing the site port numbers or mounting local folders into the virtual file system. For example, to link another plugin in the parent directory:

{
"mappings": {
"wp-content/plugins/example-plugin": "../example-plugin"
}
}