PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.19.6
GiveWP – Donation Plugin and Fundraising Platform v2.19.6
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Promotions / InPluginUpsells / AddonsRepository.php
AddonsRepository.php
75 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Promotions\InPluginUpsells;
4
5 /**
6 * @since 2.17.0
7 */
8 class AddonsRepository
9 {
10 /**
11 * @var string
12 */
13 private $endpoint = 'https://givewp.com/downloads/upsells/addons.json';
14
15 /**
16 * @var string
17 */
18 private $transient = 'give-in-plugin-upsells';
19
20 /**
21 * @return array
22 */
23 private function fetchAddons()
24 {
25 $request = wp_remote_get($this->endpoint, [
26 'headers' => [
27 'Content-Type' => 'application/json',
28 ],
29 ]);
30
31 if (is_wp_error($request)) {
32 return [];
33 }
34
35 $body = wp_remote_retrieve_body($request);
36
37 if (empty($body)) {
38 return [];
39 }
40
41 $json = json_decode($body, true);
42
43 // Sanitize JSON
44 array_walk_recursive($json, function (&$item) {
45 $item = wp_kses($item, [
46 'strong' => [],
47 ]);
48 });
49
50 return $json;
51 }
52
53 /**
54 * @return array
55 */
56 public function getAddons()
57 {
58 $cache = get_transient($this->transient);
59
60 if (false === $cache) {
61 $addons = $this->fetchAddons();
62
63 set_transient(
64 $this->transient,
65 serialize($addons),
66 DAY_IN_SECONDS
67 );
68
69 return $addons;
70 }
71
72 return unserialize($cache);
73 }
74 }
75