Skip to content

Commit 927dd8f

Browse files
committed
v0.1.2
1 parent 4877605 commit 927dd8f

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

inc/Base/CookieUpdater.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Plugin update checker for GitHub releases.
4+
*/
5+
namespace Inc\Base;
6+
7+
class CookieUpdater
8+
{
9+
public function registerFunction()
10+
{
11+
add_filter('pre_set_site_transient_update_plugins', array($this, 'check_update'));
12+
}
13+
14+
public function check_update($transient)
15+
{
16+
if (empty($transient->checked)) {
17+
return $transient;
18+
}
19+
20+
$plugin_slug = $this->pluginName;
21+
$current_version = defined('COOKIE_VERSION') ? COOKIE_VERSION : null;
22+
23+
if (!$current_version) {
24+
return $transient;
25+
}
26+
27+
https://github.com/lokutus24/lion-cookie
28+
29+
$response = wp_remote_get('https://api.github.com/repos/lokutus24/lion-cookie/releases/latest');
30+
31+
if (!is_wp_error($response) && isset($response['response']['code']) && $response['response']['code'] == 200) {
32+
$data = json_decode(wp_remote_retrieve_body($response));
33+
34+
if (isset($data->tag_name) && version_compare($current_version, $data->tag_name, '<')) {
35+
36+
$package_url = $data->zipball_url;
37+
if (!empty($data->assets)) {
38+
foreach ($data->assets as $asset) {
39+
if (
40+
isset($asset->name)
41+
&& strpos($asset->name, 'mib-connector.zip') !== false
42+
&& isset($asset->browser_download_url)
43+
) {
44+
$package_url = $asset->browser_download_url;
45+
break;
46+
}
47+
}
48+
}
49+
50+
$transient->response[$plugin_slug] = (object) array(
51+
'slug' => dirname($plugin_slug),
52+
'plugin' => $plugin_slug,
53+
'new_version' => $data->tag_name,
54+
'url' => $data->html_url,
55+
'package' => $package_url,
56+
);
57+
}
58+
}
59+
60+
return $transient;
61+
}
62+
}

inc/LionCookieInit.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
$root = plugin_dir_path(__FILE__);
55

66
$classes = [
7+
'CookieUpdater' => 'Base/CookieUpdater.php',
78
'CookieActivate' => 'Base/CookieActivate.php',
89
'CookieDeactivate' => 'Base/CookieDeactivate.php',
910
'CookieEnqueue' => 'Base/CookieEnqueue.php',
@@ -40,6 +41,7 @@ public static function get_services(): array {
4041
CookieStatistics::class,
4142
CookieChangeDecision::class,
4243
TrackingCodeManagerBlocker::class,
44+
CookieUpdater::class,
4345
];
4446
}
4547

lion-cookie.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
defined('ABSPATH') or die('No script kiddies please!');
1212

13+
if (!defined('COOKIE_VERSION')) {
14+
define('COOKIE_VERSION', 'v0.1.2');
15+
}
16+
1317
require_once plugin_dir_path(__FILE__) . 'inc/LionCookieInit.php';
1418

1519
if (class_exists('LionCookieInit')) {

0 commit comments

Comments
 (0)