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