wp-update-server icon indicating copy to clipboard operation
wp-update-server copied to clipboard

Extension for packages list

Open KingMac21 opened this issue 2 years ago • 4 comments

Good morning, I would like to add a function to the server, I'm pretty handy with PHP, but I would need some initial help. I would like the server to create a custom file with the list of plugins / themes it handles reporting their respective versions.

Something like this: pluginOne -> '1.0.5' pluginTwo -> '3.6.2'

With a request similar to: SERVER_URL/?action=get_list | get_pluginList | get_packagesList

Any ideas on where to start?

Thank you very much.

KingMac21 avatar Jul 05 '23 10:07 KingMac21

How about to try another repository? See link below.

https://github.com/YahnisElsts/wp-update-server-stats

ddur avatar Jul 05 '23 16:07 ddur

How about to try another repository? See link below.

https://github.com/YahnisElsts/wp-update-server-stats

Thanks for the link, I did not know that repository. From what I've seen it does statistics on Downloads. I, on the other hand, would like to have "a page" where I am shown the versions of all the packages that the server manages.

KingMac21 avatar Jul 05 '23 18:07 KingMac21

You would probably need to create a subclass of Wpup_UpdateServer.

To add a new action, you could override the Wpup_UpdateServer::dispatch() method. Something simple like this would probably work:

if ($request->action === 'get_package_list') {
    /* your custom logic here */
} else {
    parent::dispatch($request);
}

There's no built-in way to get all available packages, but you could just try listing all .zip files in the $this->packageDirectory directory.

To load and parse a specific package from $filename (absolute file path):

//$slug should usually be the base file name without the path and the ".zip" extension.
$package = call_user_func($this->packageFileLoader, $filename, $slug, $this->cache);

Get the version number from a package:

$meta = $package->getMetadata();
$version = $meta['version'];

Finally, to output your custom response, you can just call $this->outputJson($whatever) and then exit.

YahnisElsts avatar Jul 07 '23 11:07 YahnisElsts

Thank you very much! I will work on it.

KingMac21 avatar Jul 07 '23 11:07 KingMac21