PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
4.16.8.1 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 All 254 releases
give / src / License / PremiumAddonsListManager.php

PremiumAddonsListManager.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/License/PremiumAddonsListManager.php

93 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\License;
4
5 /**
6 * Class PremiumAddonManager
7 * @package Give\License
8 *
9 * this class we use to manager premium addons list for licensing.
10 *
11 * @since 2.9.2
12 */
13 class PremiumAddonsListManager
14 {
15 /**
16 * Products list api url.
17 *
18 * @since 2.9.2
19 */
20 const PRODUCTS_LIST_API_URL = 'https://givewp.com/edd-api/products';
21
22 /**
23 * Cached addon values for the same request, prevents subsequent transient queries
24 *
25 * @since 2.11.3
26 */
27 private $addonIds;
28
29 /**
30 * Get premium addons slugs as addons ids.
31 *
32 * @since 2.11.3 Always cache to avoid timeouts on givewp.com
33 * @since 2.9.2
34 *
35 * @return array
36 */
37 private function getAddonsIds()
38 {
39 if (isset($this->addonIds)) {
40 return $this->addonIds;
41 }
42
43 $optionName = 'give_premium_addons_ids';
44 $cachedResult = get_transient($optionName);
45 if ($cachedResult !== false) {
46 return $this->addonIds = $cachedResult;
47 }
48
49 $response = wp_remote_get(
50 self::PRODUCTS_LIST_API_URL . '?number=-1',
51 [
52 'timeout' => 3,
53 ]
54 );
55 $productsInformation = wp_remote_retrieve_body($response);
56 $responseCode = wp_remote_retrieve_response_code($response);
57 if ( ! $productsInformation || $responseCode < 200 || $responseCode > 299) {
58 set_transient($optionName, [], HOUR_IN_SECONDS);
59
60 return $this->addonIds = [];
61 }
62
63 $productsInformation = json_decode($productsInformation, true);
64 $productsIds = [];
65 foreach ($productsInformation['products'] as $product) {
66 $productsIds[] = $product['info']['slug'];
67 }
68
69 if ($productsIds) {
70 set_transient($optionName, $productsIds, DAY_IN_SECONDS);
71 }
72
73 return $this->addonIds = $productsIds;
74 }
75
76 /**
77 * Return whether or not addon is premium addon.
78 *
79 * @since 2.9.2
80 *
81 * @param string $pluginURI
82 *
83 * @return bool
84 */
85 public function isPremiumAddons($pluginURI)
86 {
87 $addonId = basename($pluginURI);
88 $addonsIds = $this->getAddonsIds();
89
90 return in_array($addonId, $addonsIds, true);
91 }
92 }
93