updates package er in

This commit is contained in:
Daan Meijer 2025-08-22 08:54:40 +02:00
parent 91ad91473c
commit 4e8270e882
2 changed files with 91 additions and 0 deletions

View File

@ -26,3 +26,4 @@ add_action('wp_enqueue_scripts', function(){
\CampingCareWidget\Widget::init();
\CampingCareWidget\Admin::init();
\CampingCareWidget\Updates::init();

90
src/Updates.php Normal file
View File

@ -0,0 +1,90 @@
<?php
namespace CampingCareWidget;
class Updates
{
public static function init()
{
add_filter('plugins_api', [static::class, 'get_plugin_info'], 20, 3);
}
/*
* $res empty at this step
* $action 'plugin_information'
* $args stdClass Object ( [slug] => woocommerce [is_ssl] => [fields] => Array ( [banners] => 1 [reviews] => 1 [downloaded] => [active_installs] => 1 ) [per_page] => 24 [locale] => en_US )
*/
function get_plugin_info($res, $action, $args)
{
// do nothing if this is not about getting plugin information
if ('plugin_information' !== $action) {
return $res;
}
$pluginName = plugin_basename(__DIR__);
// do nothing if it is not our plugin
if ($pluginName !== $args->slug) {
return $res;
}
// info.json is the file with the actual plugin information on your server
$remote = wp_remote_get(
'https://wordpress-plugin-repository.exp.sforum.nl/plugins/' . urlencode($pluginName) . '/info.json',
array(
'timeout' => 10,
'headers' => array(
'Accept' => 'application/json'
)
)
);
// do nothing if we don't get the correct response from the server
if (
is_wp_error($remote)
|| 200 !== wp_remote_retrieve_response_code($remote)
|| empty(wp_remote_retrieve_body($remote))
) {
return $res;
}
$res = json_decode(wp_remote_retrieve_body($remote));
return $res;
//
// $res = (object)[];
// $res->name = $remote->name;
// $res->slug = $remote->slug;
// $res->author = $remote->author;
// $res->author_profile = $remote->author_profile;
// $res->version = $remote->version;
// $res->tested = $remote->tested;
// $res->requires = $remote->requires;
// $res->requires_php = $remote->requires_php;
// $res->download_link = $remote->download_url;
// $res->trunk = $remote->download_url;
// $res->last_updated = $remote->last_updated;
// $res->sections = array(
// 'description' => $remote->sections->description,
// 'installation' => $remote->sections->installation,
// 'changelog' => $remote->sections->changelog
// // you can add your custom sections (tabs) here
// );
// // in case you want the screenshots tab, use the following HTML format for its content:
// // <ol><li><a href="IMG_URL" target="_blank"><img src="IMG_URL" alt="CAPTION" /></a><p>CAPTION</p></li></ol>
// if (!empty($remote->sections->screenshots)) {
// $res->sections['screenshots'] = $remote->sections->screenshots;
// }
//
// $res->banners = array(
// 'low' => $remote->banners->low,
// 'high' => $remote->banners->high
// );
//
// return $res;
}
}