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.
There was another issue though I am limited to 5000 API checks per hour per Personal Access Token (PAT), this wouldn’t be necessary for some of my smaller plugins that never need to check for an update or only I use they can use the direct to GitHub integration.
Given the number of free plugins I have on GitHub this is useful but I don’t want to have to issue a PAT for each plugin I had to find a way to bypass the 5000 limit for API checks per hour and the way I’ve done his is by building a simple caching gateway for those which means in theory this can handle 5000 plugins
<?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);
PHP
I’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 and 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.