updates aangepast
This commit is contained in:
parent
9c2f84dce4
commit
e591765947
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/*
|
||||
* Plugin name: Camping Care Widget
|
||||
* Version: 1.1.2
|
||||
* Version: 1.1.3
|
||||
* Author: Daan Meijer <daan@september.digital>
|
||||
*/
|
||||
|
||||
@ -26,4 +26,5 @@ add_action('wp_enqueue_scripts', function(){
|
||||
|
||||
\CampingCareWidget\Widget::init();
|
||||
\CampingCareWidget\Admin::init();
|
||||
\CampingCareWidget\Updates::init();
|
||||
|
||||
new \CampingCareWidget\Updates(basename(__DIR__));
|
||||
|
||||
@ -5,10 +5,14 @@ namespace CampingCareWidget;
|
||||
class Updates
|
||||
{
|
||||
|
||||
public static function init()
|
||||
const BASES = [
|
||||
'https://wordpress-plugin-updates.exp.sforum.nl/plugin',
|
||||
];
|
||||
|
||||
public function __construct(private string $plugin)
|
||||
{
|
||||
|
||||
add_filter('plugins_api', [static::class, 'get_plugin_info'], 20, 3);
|
||||
add_filter('update_plugins_'.$this->plugin, [$this, 'get_plugin_info'], 20, 3);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -16,74 +20,41 @@ class Updates
|
||||
* $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 )
|
||||
*/
|
||||
public static function get_plugin_info($res, $action, $args)
|
||||
public function get_plugin_info($res, $args)
|
||||
{
|
||||
|
||||
// do nothing if this is not about getting plugin information
|
||||
if ('plugin_information' !== $action) {
|
||||
return $res;
|
||||
}
|
||||
|
||||
$pluginName = plugin_basename(__DIR__);
|
||||
$pluginName = $this->plugin;
|
||||
|
||||
// do nothing if it is not our plugin
|
||||
if ($pluginName !== $args->slug) {
|
||||
if ($pluginName !== $args['UpdateURI']) {
|
||||
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'
|
||||
foreach(self::BASES as $base){
|
||||
$url = sprintf('%s/%s/info.json', $base, urlencode($pluginName));
|
||||
|
||||
$remote = wp_remote_get(
|
||||
$url,
|
||||
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;
|
||||
if( is_wp_error($remote)
|
||||
|| 200 !== wp_remote_retrieve_response_code($remote)
|
||||
|| empty(wp_remote_retrieve_body($remote))){
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$res = json_decode(wp_remote_retrieve_body($remote));
|
||||
break;
|
||||
}
|
||||
|
||||
$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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user