I have been working on an update to the UUPD which will officially version 1.2 and as well as all the updates that have been added in the past few months this allows for direct GitHub updates and means for a few of my GitHub only free plugins they should now be able to be updated straight from GitHub.
I have also created a simple gateway updater than checks the GitHub API and returns the bare minimum response the UUPD needs to an update this has several advantages but the most prominent one is I can include a Personal Access Token and that token can then increase checks from circa 60 per hour to 5000 per hour this may be necessary in the future for direct from GitHub updates, where I am heavily using those plugins on the same server / vps.
<?php
// Load configuration
$github_user = 'stingray82';
$token_file = 'github_token.txt'; // GitHub token securely stored
$cache_dir = __DIR__ . '/cache';
$cache_ttl = 3600; // 1 hour
// Get slug and action
$slug = $_GET['slug'] ?? '';
$action = $_GET['action'] ?? '';
$token = $_GET['token'] ?? '';
if ($action !== 'get_metadata' || !$slug) {
http_response_code(400);
echo json_encode(['error' => 'Invalid request']);
exit;
}
// Optional: Validate token here...
// Cache logic
$cache_file = "{$cache_dir}/{$slug}.json";
if (file_exists($cache_file) && time() - filemtime($cache_file) < $cache_ttl) {
echo file_get_contents($cache_file);
exit;
}
// Load GitHub token
if (!file_exists($token_file)) {
http_response_code(500);
echo json_encode(['error' => 'Missing GitHub token']);
exit;
}
$gh_token = trim(file_get_contents($token_file));
// Call GitHub API
$api_url = "https://api.github.com/repos/{$github_user}/{$slug}/releases/latest";
$ch = curl_init($api_url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'ReallyUsefulPlugins-Updater',
CURLOPT_HTTPHEADER => [
"Authorization: token {$gh_token}",
"Accept: application/vnd.github+json"
]
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
if (!isset($data['tag_name'], $data['assets'][0]['browser_download_url'])) {
http_response_code(404);
echo json_encode(['error' => 'No valid GitHub release found']);
exit;
}
$version = ltrim($data['tag_name'], 'v');
$downloadUrl = $data['assets'][0]['browser_download_url'];
$now = date('Y-m-d H:i:s');
$metadata = [
'name' => ucwords(str_replace('-', ' ', $slug)),
'version' => $version,
'author' => 'reallyusefulplugins.com',
'author_homepage' => 'https://reallyusefulplugins.com',
'slug' => $slug,
'download_url' => $downloadUrl,
'last_updated' => $now,
'sections' => [
'description' => '<p>GitHub release plugin</p>',
'changelog' => '<p>Version ' . $version . ' from GitHub</p>',
]
];
// Save to cache
if (!file_exists($cache_dir)) mkdir($cache_dir);
file_put_contents($cache_file, json_encode($metadata));
header('Content-Type: application/json');
echo json_encode($metadata);
PHPI’ve now also decided to test this out on one of my MainWP plugins the first which will use this will be MainWP-Bridge-to-Cloudflare-Bridge which will be pushed to V1.2 today and over the next week or so will slowly move up to V1.3 the purpose for this will be to test the updating directly with github through the gateway and test the caching system
I will add a new article once I am done with testing with my new plugin deploy.bat which allows direct GitHub deployment and to my local file for my wp-update-server instance via syncbackpro which will also form part of the above testing.
It does the following items
- Asks you to confirm the version number
- Name of the plugin
- Description of the plugin
- Required PHP and WP versions
- Tested Up to Version (defaulting to the latest)
- it then auto generates a readme file based off of the changelog and the fixed static data
- it then commits it with a version XXXX release message to github
- Zips it up and depending on the setup (private repo or github repo) will then either move the zip file for syncbackpro to upload or push a release and upload the zip file to github
Early testing seems to indicate I can push a simple version update in less than 30 seconds from my local machine with the update being available almost instantly regardless of repo type