PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 4.17.0
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v4.17.0
4.17.0 4.16.19 4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / src / Functions / MSFunctions.php
wp-user-avatar / src / Functions Last commit date
data 1 year ago FuseWPAdminNotice.php 2 years ago GlobalFunctions.php 5 months ago MSFunctions.php 6 days ago PPressBFnote.php 9 months ago Shogun.php 1 year ago custom-settings-api.php 8 months ago
MSFunctions.php
997 lines
1 <?php
2
3 use ProfilePress\Core\Base;
4 use ProfilePress\Core\Classes\PPRESS_Session;
5 use ProfilePress\Core\Membership\CurrencyFormatter;
6 use ProfilePress\Core\Membership\Models\Customer\CustomerFactory;
7 use ProfilePress\Core\Membership\Models\Order\OrderEntity;
8 use ProfilePress\Core\Membership\Models\Order\OrderFactory;
9 use ProfilePress\Core\Membership\Models\Order\OrderMode;
10 use ProfilePress\Core\Membership\Models\Order\OrderStatus;
11 use ProfilePress\Core\Membership\Models\Plan\PlanFactory;
12 use ProfilePress\Core\Membership\Models\Plan\PlanEntity;
13 use ProfilePress\Core\Membership\Models\Subscription\SubscriptionEntity;
14 use ProfilePress\Core\Membership\PaymentMethods\AbstractPaymentMethod;
15 use ProfilePress\Core\Membership\PaymentMethods\PaymentMethods;
16 use ProfilePress\Core\Membership\PaymentMethods\PaymentMethods as PaymentGateways;
17 use ProfilePress\Core\Membership\PaymentMethods\StoreGateway;
18 use ProfilePress\Core\Membership\Services\Calculator;
19 use ProfilePress\Core\Membership\Services\SubscriptionService;
20
21 /**
22 * @param $plan_id
23 *
24 * @return PlanEntity
25 */
26 function ppress_get_plan($plan_id)
27 {
28 return ppress_cache_transform('ppress_get_plan_' . $plan_id, function () use ($plan_id) {
29 return PlanFactory::fromId($plan_id);
30 });
31 }
32
33 /**
34 * @param $payment_method_id
35 *
36 * @return false|AbstractPaymentMethod
37 */
38 function ppress_get_payment_method($payment_method_id)
39 {
40 return PaymentMethods::get_instance()->get_by_id($payment_method_id);
41 }
42
43 /**
44 * Check if website has an active membership plan.
45 *
46 * @return bool
47 */
48 function ppress_is_any_active_plan()
49 {
50 return ppress_cache_transform('ppress_is_any_active_plan', function () {
51
52 global $wpdb;
53
54 $table = Base::subscription_plans_db_table();
55
56 if ( ! $wpdb->get_var("SHOW TABLES LIKE '$table'")) return false;
57
58 return absint($wpdb->get_var("SELECT COUNT(id) FROM $table WHERE status = 'true'")) > 0;
59 });
60 }
61
62 /**
63 * Check if website has an active payment method.
64 *
65 * @return bool
66 */
67 function ppress_is_any_enabled_payment_method()
68 {
69 $check = PaymentGateways::get_instance()->get_enabled_methods(true);
70
71 return ! empty($check);
72 }
73
74 /**
75 * Check if website has an active coupon.
76 *
77 * @return bool
78 */
79 function ppress_is_any_active_coupon()
80 {
81 global $wpdb;
82
83 $table = Base::coupons_db_table();
84
85 return absint($wpdb->get_var("SELECT COUNT(id) FROM $table WHERE status = 'true'")) > 0;
86 }
87
88 function ppress_get_currency()
89 {
90 return apply_filters('ppress_currency', ppress_settings_by_key('payment_currency', 'USD', true));
91 }
92
93 /**
94 * Get full list of currency codes.
95 *
96 * Currency symbols and names should follow the Unicode CLDR recommendation (http://cldr.unicode.org/translation/currency-names)
97 *
98 * @return array
99 */
100 function ppress_get_currencies()
101 {
102 static $currencies;
103
104 if ( ! isset($currencies)) {
105 $currencies = array_unique(
106 apply_filters(
107 'ppress_currencies',
108 [
109 'USD' => __('United States (US) dollar', 'wp-user-avatar'),
110 'EUR' => __('Euro', 'wp-user-avatar'),
111 'GBP' => __('Pound sterling', 'wp-user-avatar'),
112 'AED' => __('United Arab Emirates dirham', 'wp-user-avatar'),
113 'AFN' => __('Afghan afghani', 'wp-user-avatar'),
114 'ALL' => __('Albanian lek', 'wp-user-avatar'),
115 'AMD' => __('Armenian dram', 'wp-user-avatar'),
116 'ANG' => __('Netherlands Antillean guilder', 'wp-user-avatar'),
117 'AOA' => __('Angolan kwanza', 'wp-user-avatar'),
118 'ARS' => __('Argentine peso', 'wp-user-avatar'),
119 'AUD' => __('Australian dollar', 'wp-user-avatar'),
120 'AWG' => __('Aruban florin', 'wp-user-avatar'),
121 'AZN' => __('Azerbaijani manat', 'wp-user-avatar'),
122 'BAM' => __('Bosnia and Herzegovina convertible mark', 'wp-user-avatar'),
123 'BBD' => __('Barbadian dollar', 'wp-user-avatar'),
124 'BDT' => __('Bangladeshi taka', 'wp-user-avatar'),
125 'BGN' => __('Bulgarian lev', 'wp-user-avatar'),
126 'BHD' => __('Bahraini dinar', 'wp-user-avatar'),
127 'BIF' => __('Burundian franc', 'wp-user-avatar'),
128 'BMD' => __('Bermudian dollar', 'wp-user-avatar'),
129 'BND' => __('Brunei dollar', 'wp-user-avatar'),
130 'BOB' => __('Bolivian boliviano', 'wp-user-avatar'),
131 'BRL' => __('Brazilian real', 'wp-user-avatar'),
132 'BSD' => __('Bahamian dollar', 'wp-user-avatar'),
133 'BTC' => __('Bitcoin', 'wp-user-avatar'),
134 'BTN' => __('Bhutanese ngultrum', 'wp-user-avatar'),
135 'BWP' => __('Botswana pula', 'wp-user-avatar'),
136 'BYR' => __('Belarusian ruble (old)', 'wp-user-avatar'),
137 'BYN' => __('Belarusian ruble', 'wp-user-avatar'),
138 'BZD' => __('Belize dollar', 'wp-user-avatar'),
139 'CAD' => __('Canadian dollar', 'wp-user-avatar'),
140 'CDF' => __('Congolese franc', 'wp-user-avatar'),
141 'CHF' => __('Swiss franc', 'wp-user-avatar'),
142 'CLP' => __('Chilean peso', 'wp-user-avatar'),
143 'CNY' => __('Chinese yuan', 'wp-user-avatar'),
144 'COP' => __('Colombian peso', 'wp-user-avatar'),
145 'CRC' => __('Costa Rican col&oacute;n', 'wp-user-avatar'),
146 'CUC' => __('Cuban convertible peso', 'wp-user-avatar'),
147 'CUP' => __('Cuban peso', 'wp-user-avatar'),
148 'CVE' => __('Cape Verdean escudo', 'wp-user-avatar'),
149 'CZK' => __('Czech koruna', 'wp-user-avatar'),
150 'DJF' => __('Djiboutian franc', 'wp-user-avatar'),
151 'DKK' => __('Danish krone', 'wp-user-avatar'),
152 'DOP' => __('Dominican peso', 'wp-user-avatar'),
153 'DZD' => __('Algerian dinar', 'wp-user-avatar'),
154 'EGP' => __('Egyptian pound', 'wp-user-avatar'),
155 'ERN' => __('Eritrean nakfa', 'wp-user-avatar'),
156 'ETB' => __('Ethiopian birr', 'wp-user-avatar'),
157 'FJD' => __('Fijian dollar', 'wp-user-avatar'),
158 'FKP' => __('Falkland Islands pound', 'wp-user-avatar'),
159 'GEL' => __('Georgian lari', 'wp-user-avatar'),
160 'GGP' => __('Guernsey pound', 'wp-user-avatar'),
161 'GHS' => __('Ghana cedi', 'wp-user-avatar'),
162 'GIP' => __('Gibraltar pound', 'wp-user-avatar'),
163 'GMD' => __('Gambian dalasi', 'wp-user-avatar'),
164 'GNF' => __('Guinean franc', 'wp-user-avatar'),
165 'GTQ' => __('Guatemalan quetzal', 'wp-user-avatar'),
166 'GYD' => __('Guyanese dollar', 'wp-user-avatar'),
167 'HKD' => __('Hong Kong dollar', 'wp-user-avatar'),
168 'HNL' => __('Honduran lempira', 'wp-user-avatar'),
169 'HRK' => __('Croatian kuna', 'wp-user-avatar'),
170 'HTG' => __('Haitian gourde', 'wp-user-avatar'),
171 'HUF' => __('Hungarian forint', 'wp-user-avatar'),
172 'IDR' => __('Indonesian rupiah', 'wp-user-avatar'),
173 'ILS' => __('Israeli new shekel', 'wp-user-avatar'),
174 'IMP' => __('Manx pound', 'wp-user-avatar'),
175 'INR' => __('Indian rupee', 'wp-user-avatar'),
176 'IQD' => __('Iraqi dinar', 'wp-user-avatar'),
177 'IRR' => __('Iranian rial', 'wp-user-avatar'),
178 'IRT' => __('Iranian toman', 'wp-user-avatar'),
179 'ISK' => __('Icelandic kr&oacute;na', 'wp-user-avatar'),
180 'JEP' => __('Jersey pound', 'wp-user-avatar'),
181 'JMD' => __('Jamaican dollar', 'wp-user-avatar'),
182 'JOD' => __('Jordanian dinar', 'wp-user-avatar'),
183 'JPY' => __('Japanese yen', 'wp-user-avatar'),
184 'KES' => __('Kenyan shilling', 'wp-user-avatar'),
185 'KGS' => __('Kyrgyzstani som', 'wp-user-avatar'),
186 'KHR' => __('Cambodian riel', 'wp-user-avatar'),
187 'KMF' => __('Comorian franc', 'wp-user-avatar'),
188 'KPW' => __('North Korean won', 'wp-user-avatar'),
189 'KRW' => __('South Korean won', 'wp-user-avatar'),
190 'KWD' => __('Kuwaiti dinar', 'wp-user-avatar'),
191 'KYD' => __('Cayman Islands dollar', 'wp-user-avatar'),
192 'KZT' => __('Kazakhstani tenge', 'wp-user-avatar'),
193 'LAK' => __('Lao kip', 'wp-user-avatar'),
194 'LBP' => __('Lebanese pound', 'wp-user-avatar'),
195 'LKR' => __('Sri Lankan rupee', 'wp-user-avatar'),
196 'LRD' => __('Liberian dollar', 'wp-user-avatar'),
197 'LSL' => __('Lesotho loti', 'wp-user-avatar'),
198 'LYD' => __('Libyan dinar', 'wp-user-avatar'),
199 'MAD' => __('Moroccan dirham', 'wp-user-avatar'),
200 'MDL' => __('Moldovan leu', 'wp-user-avatar'),
201 'MGA' => __('Malagasy ariary', 'wp-user-avatar'),
202 'MKD' => __('Macedonian denar', 'wp-user-avatar'),
203 'MMK' => __('Burmese kyat', 'wp-user-avatar'),
204 'MNT' => __('Mongolian t&ouml;gr&ouml;g', 'wp-user-avatar'),
205 'MOP' => __('Macanese pataca', 'wp-user-avatar'),
206 'MRU' => __('Mauritanian ouguiya', 'wp-user-avatar'),
207 'MUR' => __('Mauritian rupee', 'wp-user-avatar'),
208 'MVR' => __('Maldivian rufiyaa', 'wp-user-avatar'),
209 'MWK' => __('Malawian kwacha', 'wp-user-avatar'),
210 'MXN' => __('Mexican peso', 'wp-user-avatar'),
211 'MYR' => __('Malaysian ringgit', 'wp-user-avatar'),
212 'MZN' => __('Mozambican metical', 'wp-user-avatar'),
213 'NAD' => __('Namibian dollar', 'wp-user-avatar'),
214 'NGN' => __('Nigerian naira', 'wp-user-avatar'),
215 'NIO' => __('Nicaraguan c&oacute;rdoba', 'wp-user-avatar'),
216 'NOK' => __('Norwegian krone', 'wp-user-avatar'),
217 'NPR' => __('Nepalese rupee', 'wp-user-avatar'),
218 'NZD' => __('New Zealand dollar', 'wp-user-avatar'),
219 'OMR' => __('Omani rial', 'wp-user-avatar'),
220 'PAB' => __('Panamanian balboa', 'wp-user-avatar'),
221 'PEN' => __('Sol', 'wp-user-avatar'),
222 'PGK' => __('Papua New Guinean kina', 'wp-user-avatar'),
223 'PHP' => __('Philippine peso', 'wp-user-avatar'),
224 'PKR' => __('Pakistani rupee', 'wp-user-avatar'),
225 'PLN' => __('Polish z&#x142;oty', 'wp-user-avatar'),
226 'PRB' => __('Transnistrian ruble', 'wp-user-avatar'),
227 'PYG' => __('Paraguayan guaran&iacute;', 'wp-user-avatar'),
228 'QAR' => __('Qatari riyal', 'wp-user-avatar'),
229 'RON' => __('Romanian leu', 'wp-user-avatar'),
230 'RSD' => __('Serbian dinar', 'wp-user-avatar'),
231 'RUB' => __('Russian ruble', 'wp-user-avatar'),
232 'RWF' => __('Rwandan franc', 'wp-user-avatar'),
233 'SAR' => __('Saudi riyal', 'wp-user-avatar'),
234 'SBD' => __('Solomon Islands dollar', 'wp-user-avatar'),
235 'SCR' => __('Seychellois rupee', 'wp-user-avatar'),
236 'SDG' => __('Sudanese pound', 'wp-user-avatar'),
237 'SEK' => __('Swedish krona', 'wp-user-avatar'),
238 'SGD' => __('Singapore dollar', 'wp-user-avatar'),
239 'SHP' => __('Saint Helena pound', 'wp-user-avatar'),
240 'SLL' => __('Sierra Leonean leone', 'wp-user-avatar'),
241 'SOS' => __('Somali shilling', 'wp-user-avatar'),
242 'SRD' => __('Surinamese dollar', 'wp-user-avatar'),
243 'SSP' => __('South Sudanese pound', 'wp-user-avatar'),
244 'STN' => __('S&atilde;o Tom&eacute; and Pr&iacute;ncipe dobra', 'wp-user-avatar'),
245 'SYP' => __('Syrian pound', 'wp-user-avatar'),
246 'SZL' => __('Swazi lilangeni', 'wp-user-avatar'),
247 'THB' => __('Thai baht', 'wp-user-avatar'),
248 'TJS' => __('Tajikistani somoni', 'wp-user-avatar'),
249 'TMT' => __('Turkmenistan manat', 'wp-user-avatar'),
250 'TND' => __('Tunisian dinar', 'wp-user-avatar'),
251 'TOP' => __('Tongan pa&#x2bb;anga', 'wp-user-avatar'),
252 'TRY' => __('Turkish lira', 'wp-user-avatar'),
253 'TTD' => __('Trinidad and Tobago dollar', 'wp-user-avatar'),
254 'TWD' => __('New Taiwan dollar', 'wp-user-avatar'),
255 'TZS' => __('Tanzanian shilling', 'wp-user-avatar'),
256 'UAH' => __('Ukrainian hryvnia', 'wp-user-avatar'),
257 'UGX' => __('Ugandan shilling', 'wp-user-avatar'),
258 'UYU' => __('Uruguayan peso', 'wp-user-avatar'),
259 'UZS' => __('Uzbekistani som', 'wp-user-avatar'),
260 'VEF' => __('Venezuelan bol&iacute;var', 'wp-user-avatar'),
261 'VES' => __('Bol&iacute;var soberano', 'wp-user-avatar'),
262 'VND' => __('Vietnamese &#x111;&#x1ed3;ng', 'wp-user-avatar'),
263 'VUV' => __('Vanuatu vatu', 'wp-user-avatar'),
264 'WST' => __('Samoan t&#x101;l&#x101;', 'wp-user-avatar'),
265 'XAF' => __('Central African CFA franc', 'wp-user-avatar'),
266 'XCD' => __('East Caribbean dollar', 'wp-user-avatar'),
267 'XOF' => __('West African CFA franc', 'wp-user-avatar'),
268 'XPF' => __('CFP franc', 'wp-user-avatar'),
269 'YER' => __('Yemeni rial', 'wp-user-avatar'),
270 'ZAR' => __('South African rand', 'wp-user-avatar'),
271 'ZMW' => __('Zambian kwacha', 'wp-user-avatar'),
272 ]
273 )
274 );
275 }
276
277 return array_map('ucwords', $currencies);
278 }
279
280 /**
281 * Get all available Currency symbols.
282 *
283 * Currency symbols and names should follow the Unicode CLDR recommendation (http://cldr.unicode.org/translation/currency-names)
284 *
285 * @return array
286 */
287 function ppress_get_currency_symbols()
288 {
289 $symbols = apply_filters(
290 'ppress_currency_symbols',
291 array(
292 'AED' => '&#x62f;.&#x625;',
293 'AFN' => '&#x60b;',
294 'ALL' => 'L',
295 'AMD' => 'AMD',
296 'ANG' => '&fnof;',
297 'AOA' => 'Kz',
298 'ARS' => '&#36;',
299 'AUD' => '&#36;',
300 'AWG' => 'Afl.',
301 'AZN' => 'AZN',
302 'BAM' => 'KM',
303 'BBD' => '&#36;',
304 'BDT' => '&#2547;&nbsp;',
305 'BGN' => '&#1083;&#1074;.',
306 'BHD' => '.&#x62f;.&#x628;',
307 'BIF' => 'Fr',
308 'BMD' => '&#36;',
309 'BND' => '&#36;',
310 'BOB' => 'Bs.',
311 'BRL' => '&#82;&#36;',
312 'BSD' => '&#36;',
313 'BTC' => '&#3647;',
314 'BTN' => 'Nu.',
315 'BWP' => 'P',
316 'BYR' => 'Br',
317 'BYN' => 'Br',
318 'BZD' => '&#36;',
319 'CAD' => '&#36;',
320 'CDF' => 'Fr',
321 'CHF' => '&#67;&#72;&#70;',
322 'CLP' => '&#36;',
323 'CNY' => '&yen;',
324 'COP' => '&#36;',
325 'CRC' => '&#x20a1;',
326 'CUC' => '&#36;',
327 'CUP' => '&#36;',
328 'CVE' => '&#36;',
329 'CZK' => '&#75;&#269;',
330 'DJF' => 'Fr',
331 'DKK' => 'DKK',
332 'DOP' => 'RD&#36;',
333 'DZD' => '&#x62f;.&#x62c;',
334 'EGP' => 'EGP',
335 'ERN' => 'Nfk',
336 'ETB' => 'Br',
337 'EUR' => '&euro;',
338 'FJD' => '&#36;',
339 'FKP' => '&pound;',
340 'GBP' => '&pound;',
341 'GEL' => '&#x20be;',
342 'GGP' => '&pound;',
343 'GHS' => '&#x20b5;',
344 'GIP' => '&pound;',
345 'GMD' => 'D',
346 'GNF' => 'Fr',
347 'GTQ' => 'Q',
348 'GYD' => '&#36;',
349 'HKD' => '&#36;',
350 'HNL' => 'L',
351 'HRK' => 'kn',
352 'HTG' => 'G',
353 'HUF' => '&#70;&#116;',
354 'IDR' => 'Rp',
355 'ILS' => '&#8362;',
356 'IMP' => '&pound;',
357 'INR' => '&#8377;',
358 'IQD' => '&#x62f;.&#x639;',
359 'IRR' => '&#xfdfc;',
360 'IRT' => '&#x062A;&#x0648;&#x0645;&#x0627;&#x0646;',
361 'ISK' => 'kr.',
362 'JEP' => '&pound;',
363 'JMD' => '&#36;',
364 'JOD' => '&#x62f;.&#x627;',
365 'JPY' => '&yen;',
366 'KES' => 'KSh',
367 'KGS' => '&#x441;&#x43e;&#x43c;',
368 'KHR' => '&#x17db;',
369 'KMF' => 'Fr',
370 'KPW' => '&#x20a9;',
371 'KRW' => '&#8361;',
372 'KWD' => '&#x62f;.&#x643;',
373 'KYD' => '&#36;',
374 'KZT' => '&#8376;',
375 'LAK' => '&#8365;',
376 'LBP' => '&#x644;.&#x644;',
377 'LKR' => '&#xdbb;&#xdd4;',
378 'LRD' => '&#36;',
379 'LSL' => 'L',
380 'LYD' => '&#x644;.&#x62f;',
381 'MAD' => '&#x62f;.&#x645;.',
382 'MDL' => 'MDL',
383 'MGA' => 'Ar',
384 'MKD' => '&#x434;&#x435;&#x43d;',
385 'MMK' => 'Ks',
386 'MNT' => '&#x20ae;',
387 'MOP' => 'P',
388 'MRU' => 'UM',
389 'MUR' => '&#x20a8;',
390 'MVR' => '.&#x783;',
391 'MWK' => 'MK',
392 'MXN' => '&#36;',
393 'MYR' => '&#82;&#77;',
394 'MZN' => 'MT',
395 'NAD' => 'N&#36;',
396 'NGN' => '&#8358;',
397 'NIO' => 'C&#36;',
398 'NOK' => '&#107;&#114;',
399 'NPR' => '&#8360;',
400 'NZD' => '&#36;',
401 'OMR' => '&#x631;.&#x639;.',
402 'PAB' => 'B/.',
403 'PEN' => 'S/',
404 'PGK' => 'K',
405 'PHP' => '&#8369;',
406 'PKR' => '&#8360;',
407 'PLN' => '&#122;&#322;',
408 'PRB' => '&#x440;.',
409 'PYG' => '&#8370;',
410 'QAR' => '&#x631;.&#x642;',
411 'RMB' => '&yen;',
412 'RON' => 'lei',
413 'RSD' => '&#1088;&#1089;&#1076;',
414 'RUB' => '&#8381;',
415 'RWF' => 'Fr',
416 'SAR' => '&#x631;.&#x633;',
417 'SBD' => '&#36;',
418 'SCR' => '&#x20a8;',
419 'SDG' => '&#x62c;.&#x633;.',
420 'SEK' => '&#107;&#114;',
421 'SGD' => '&#36;',
422 'SHP' => '&pound;',
423 'SLL' => 'Le',
424 'SOS' => 'Sh',
425 'SRD' => '&#36;',
426 'SSP' => '&pound;',
427 'STN' => 'Db',
428 'SYP' => '&#x644;.&#x633;',
429 'SZL' => 'L',
430 'THB' => '&#3647;',
431 'TJS' => '&#x405;&#x41c;',
432 'TMT' => 'm',
433 'TND' => '&#x62f;.&#x62a;',
434 'TOP' => 'T&#36;',
435 'TRY' => '&#8378;',
436 'TTD' => '&#36;',
437 'TWD' => '&#78;&#84;&#36;',
438 'TZS' => 'Sh',
439 'UAH' => '&#8372;',
440 'UGX' => 'UGX',
441 'USD' => '&#36;',
442 'UYU' => '&#36;',
443 'UZS' => 'UZS',
444 'VEF' => 'Bs F',
445 'VES' => 'Bs.S',
446 'VND' => '&#8363;',
447 'VUV' => 'Vt',
448 'WST' => 'T',
449 'XAF' => 'CFA',
450 'XCD' => '&#36;',
451 'XOF' => 'CFA',
452 'XPF' => 'Fr',
453 'YER' => '&#xfdfc;',
454 'ZAR' => '&#82;',
455 'ZMW' => 'ZK',
456 )
457 );
458
459 return apply_filters('ppress_currency_symbols', $symbols);
460 }
461
462 /**
463 * Get Currency symbol.
464 *
465 * Currency symbols and names should follow the Unicode CLDR recommendation (http://cldr.unicode.org/translation/currency-names)
466 *
467 * @param string $currency Currency. (default: '').
468 *
469 * @return string
470 */
471 function ppress_get_currency_symbol($currency = '')
472 {
473 return ppress_cache_transform('ppress_get_currency_symbol_'.$currency, function() use ($currency) {
474
475 if ( ! $currency) $currency = ppress_get_currency();
476
477 $symbols = ppress_get_currency_symbols();
478
479 $currency_symbol = $symbols[$currency] ?? '';
480
481 return apply_filters('ppress_currency_symbol', $currency_symbol, $currency);
482 });
483 }
484
485
486 /**
487 * Get the name of a currency
488 *
489 * @param string $code The currency code
490 *
491 * @return string The currency's name
492 */
493 function ppress_get_currency_name($code = '')
494 {
495 if ( ! $code) {
496 $code = ppress_get_currency();
497 }
498
499 $currencies = ppress_get_currencies();
500 $name = $currencies[$code] ?? $code;
501
502 return apply_filters('ppress_currency_name', $name);
503 }
504
505 /**
506 * Accepts an amount (ideally from the database, unmodified) and formats it
507 * for display. The amount itself is formatted and the currency prefix/suffix
508 * is applied and positioned.
509 *
510 * @param string $amount
511 * @param string $currency
512 *
513 * @return string
514 *
515 */
516 function ppress_display_amount($amount, $currency = '')
517 {
518 return (new CurrencyFormatter($amount, $currency))->format()->apply_symbol()->val();
519 }
520
521 /**
522 *
523 * @param $amount
524 *
525 * @return string
526 */
527 function ppress_sanitize_amount($amount)
528 {
529 return (new CurrencyFormatter($amount))->sanitize()->val();
530 }
531
532 /**
533 * Converts price, fee or amount in cent to decimal
534 *
535 * @param $amount
536 *
537 * @return string
538 */
539 function ppress_cent_to_decimal($amount)
540 {
541 return ppress_sanitize_amount(Calculator::init($amount)->dividedBy('100')->val());
542 }
543
544 /**
545 * Converts price, fee or amount in decimal to cent
546 *
547 * @param $amount
548 *
549 * @return string
550 */
551 function ppress_decimal_to_cent($amount)
552 {
553 return (int)Calculator::init($amount)->toScale(2)->multipliedBy(100)->toScale(0)->val();
554 }
555
556 /**
557 * Force https for urls.
558 *
559 * @param mixed $content
560 *
561 * @return string
562 */
563 function ppress_force_https_url($content)
564 {
565 if (is_ssl()) {
566 if (is_array($content)) {
567 $content = array_map('ppress_force_https_url', $content);
568 } else {
569 $content = str_replace('http:', 'https:', $content);
570 }
571 }
572
573 return $content;
574 }
575
576 function ppress_is_test_mode()
577 {
578 return ppress_var(get_option(PPRESS_PAYMENT_METHODS_OPTION_NAME, []), 'test_mode') == 'true';
579 }
580
581 function ppress_get_payment_mode()
582 {
583 return ppress_cache_transform('ppress_get_payment_mode', function () {
584 return ppress_is_test_mode() ? OrderMode::TEST : OrderMode::LIVE;
585 });
586 }
587
588 /**
589 * Converts a date/time to UTC
590 */
591 function ppress_local_datetime_to_utc($date, $format = 'Y-m-d H:i:s')
592 {
593 try {
594 return (new DateTimeImmutable($date, wp_timezone()))
595 ->setTimezone(new DateTimeZone('UTC'))
596 ->format($format);
597 } catch (\Exception $e) {
598 return false;
599 }
600 }
601
602 /**
603 * Formats UTC datetime according to WordPress date/time format and using WordPress site timezone.
604 *
605 * Expects time/timestamp to be in UTC
606 *
607 * @param string $timestamp timestamp or datetime in UTC
608 *
609 * @param string $format
610 *
611 * @return string datetime in WP timezone
612 */
613 function ppress_format_date_time($timestamp, $format = '')
614 {
615 /**
616 * force strtotime to use date as UTC.
617 * @see https://stackoverflow.com/a/6275660/2648410
618 */
619 $timestamp = ! is_numeric($timestamp) ? strtotime($timestamp . ' UTC') : $timestamp;
620
621 $format = empty($format) ? get_option('date_format') . ' ' . get_option('time_format') : $format;
622
623 return wp_date($format, $timestamp);
624 }
625
626 /**
627 * Formats UTC date according to WordPress date format and using WordPress site timezone.
628 *
629 * @param string $timestamp timestamp or datetime in UTC
630 * @param string $format
631 *
632 * @return string date in WP timezone
633 */
634 function ppress_format_date($timestamp, $format = '')
635 {
636 if (empty($timestamp)) return '';
637
638 /**
639 * force strtotime to use date as UTC.
640 * @see https://stackoverflow.com/a/6275660/2648410
641 */
642 $timestamp = ! is_numeric($timestamp) ? strtotime($timestamp . ' UTC') : $timestamp;
643
644 $format = empty($format) ? get_option('date_format') : $format;
645
646 return wp_date($format, $timestamp);
647 }
648
649 function ppress_update_payment_method_setting($key, $value)
650 {
651 $data = get_option(PPRESS_PAYMENT_METHODS_OPTION_NAME, []);
652 $data[$key] = $value;
653 update_option(PPRESS_PAYMENT_METHODS_OPTION_NAME, $data);
654 }
655
656 function ppress_get_payment_method_setting($key = '', $default = false, $is_empty = false)
657 {
658 static $data = null;
659
660 if (is_null($data)) {
661 $data = get_option(PPRESS_PAYMENT_METHODS_OPTION_NAME, []);
662 }
663
664 if ($is_empty === true) {
665 return isset($data[$key]) && ( ! empty($data[$key]) || ppress_is_boolean($data[$key])) ? $data[$key] : $default;
666 }
667
668 return isset($data[$key]) ? $data[$key] : $default;
669 }
670
671 function ppress_get_file_downloads_setting($key = '', $default = false, $is_empty = false)
672 {
673 static $data = null;
674
675 if (is_null($data)) {
676 $data = get_option(PPRESS_FILE_DOWNLOADS_OPTION_NAME, []);
677 }
678
679 if ($is_empty === true) {
680 return isset($data[$key]) && ( ! empty($data[$key]) || ppress_is_boolean($data[$key])) ? $data[$key] : $default;
681 }
682
683 return isset($data[$key]) ? $data[$key] : $default;
684 }
685
686 /**
687 * @return PPRESS_Session
688 */
689 function ppress_session()
690 {
691 return PPRESS_Session::get_instance();
692 }
693
694 function ppress_is_checkout()
695 {
696 $page_id = ppress_settings_by_key('checkout_page_id', 0, true);
697
698 return ($page_id && is_page($page_id)) || ppress_post_content_has_shortcode('profilepress-checkout');
699 }
700
701 function ppress_is_success_page()
702 {
703 $page_id = ppress_settings_by_key('payment_success_page_id', 0, true);
704
705 return ($page_id && is_page($page_id));
706 }
707
708 /**
709 * @param $order_key
710 * @param $payment_method
711 *
712 * @return string
713 */
714 function ppress_get_success_url($order_key = '', $payment_method = '')
715 {
716 $url = get_permalink(
717 absint(ppress_settings_by_key('payment_success_page_id'))
718 );
719
720 $url = ! $url ? home_url() : $url;
721
722 if ( ! empty($order_key)) {
723 $url = add_query_arg(['order_key' => $order_key], $url);
724 }
725
726 if ( ! empty($payment_method)) {
727 $url = add_query_arg(['payment_method' => $payment_method], $url);
728 }
729
730 return apply_filters('ppress_get_success_url', esc_url_raw($url), $order_key);
731 }
732
733 /**
734 * @param $order_key
735 *
736 * @return string
737 */
738 function ppress_get_cancel_url($order_key = '')
739 {
740 $url = get_permalink(
741 absint(ppress_settings_by_key('payment_failure_page_id'))
742 );
743
744 $url = ! $url ? home_url() : $url;
745
746 if ( ! empty($order_key)) {
747 $url = add_query_arg(['order_key' => $order_key], $url);
748 }
749
750 return apply_filters('ppress_get_cancel_url', esc_url_raw($url), $order_key);
751 }
752
753 function ppress_business_name()
754 {
755 return ppress_settings_by_key('business_name', '', true);
756 }
757
758 function ppress_business_address($default = '')
759 {
760 return ppress_settings_by_key('business_address', $default, true);
761 }
762
763 function ppress_business_city($default = '')
764 {
765 return ppress_settings_by_key('business_city', $default, true);
766 }
767
768 function ppress_business_country($default = '')
769 {
770 return ppress_settings_by_key('business_country', $default, true);
771 }
772
773 function ppress_business_state($default = '')
774 {
775 return ppress_settings_by_key('business_state', $default, true);
776 }
777
778 function ppress_business_postal_code($default = '')
779 {
780 return ppress_settings_by_key('business_postal_code', $default, true);
781 }
782
783 function ppress_business_full_address()
784 {
785 $billing_address = ppress_business_address();
786
787 if (empty($billing_address)) return '';
788
789 $business_country = ppress_business_country();
790
791 $state = ppress_var(ppress_array_of_world_states($business_country), ppress_business_state(), ppress_business_state(), true);
792
793 $address = [trim($billing_address)];
794 $address[] = trim(ppress_business_city() . ' ' . $state);
795 $address[] = ppress_business_postal_code();
796 $address[] = ppress_array_of_world_countries($business_country);
797
798 return implode(', ', array_filter($address));
799 }
800
801 function ppress_business_tax_id($default = '')
802 {
803 return ppress_settings_by_key('business_tin', $default, true);
804 }
805
806 /**
807 * Check if a user/customer has an active subscription to a membership plan.
808 *
809 * @param int $user_id
810 * @param int $plan_id
811 * @param bool $by_customer_id
812 *
813 * @return bool
814 */
815 function ppress_has_active_subscription($user_id, $plan_id, $by_customer_id = false)
816 {
817 if (false === $by_customer_id) {
818 $customer = CustomerFactory::fromUserId($user_id);
819 } else {
820 $customer = CustomerFactory::fromId($user_id);
821 }
822
823 return $customer->has_active_subscription($plan_id);
824 }
825
826 /**
827 * Checks whether function is disabled.
828 *
829 * @param string $function Name of the function.
830 *
831 * @return bool Whether or not function is disabled.
832 */
833 function ppress_is_func_disabled($function)
834 {
835 $disabled = explode(',', @ini_get('disable_functions'));
836
837 return in_array($function, $disabled, true);
838 }
839
840 /**
841 * Ignore the time limit set by the server (likely from php.ini.)
842 *
843 * This is usually only necessary during upgrades and exports. If you need to
844 * use this function directly, please be careful in doing so.
845 *
846 * The $time_limit parameter is filterable, but infinite values are not allowed
847 * so any erroneous processes are able to terminate normally.
848 *
849 * @param boolean $ignore_user_abort Whether to call ignore_user_about( true )
850 * @param int $time_limit How long to set the time limit to. Cannot be 0. Default 6 hours.
851 */
852 function ppress_set_time_limit($ignore_user_abort = true, $time_limit = 21600)
853 {
854 // Default time limit is 6 hours
855 $default = HOUR_IN_SECONDS * 6;
856
857 // Only abort if true and if function is enabled
858 if ((true === $ignore_user_abort) && ! ppress_is_func_disabled('ignore_user_abort')) {
859 @ignore_user_abort(true);
860 }
861
862 // Disallow infinite values
863 if (empty($time_limit)) $time_limit = $default;
864
865 // Set time limit to non-infinite value if function is enabled
866 if ( ! ppress_is_func_disabled('set_time_limit')) {
867 @set_time_limit($time_limit);
868 }
869
870 wp_raise_memory_limit('ppress');
871 }
872
873 /**
874 * @param $user_id
875 *
876 * @return int|WP_Error
877 */
878 function ppress_create_customer($user_id)
879 {
880 $customer = CustomerFactory::fromUserId($user_id);
881
882 $customer_id = $customer->get_id();
883
884 if ( ! $customer->exists()) {
885 $customer->user_id = $user_id;
886 $customer_id = $customer->save();
887 if ( ! $customer_id) {
888 return new WP_Error('customer_creation_failure', esc_html__('Unable to create customer. Please try again', 'wp-user-avatar'));
889 }
890 }
891
892 return $customer_id;
893 }
894
895 /**
896 * Subscribe a customer to a membership plan while creating the corresponding order and subscription entity.
897 *
898 * @param int $plan_id
899 * @param int $customer_id
900 * @param array $order_data
901 * @param bool $send_receipt
902 *
903 * @return array|WP_Error
904 */
905 function ppress_subscribe_user_to_plan($plan_id, $customer_id, $order_data = [], $send_receipt = false)
906 {
907 global $wpdb;
908
909 $plan_obj = ppress_get_plan((int)$plan_id);
910
911 if (CustomerFactory::fromId($customer_id)->has_active_subscription($plan_obj->id)) {
912
913 return new WP_Error(
914 'subscribe_user_to_plan_error',
915 sprintf(__('Customer already has an active subscription for %s.', 'wp-user-avatar'), $plan_obj->name)
916 );
917 }
918
919 $order_data = wp_parse_args(array_filter($order_data), [
920 'date_created' => current_time('mysql', true),
921 'payment_method' => StoreGateway::get_instance()->get_id(),
922 'amount' => '0',
923 'order_status' => OrderStatus::COMPLETED,
924 'transaction_id' => ''
925 ]);
926
927 $order = new OrderEntity();
928 $order->plan_id = $plan_obj->id;
929 $order->customer_id = $customer_id;
930 $order->subtotal = ppress_sanitize_amount($order_data['amount']);
931 $order->total = ppress_sanitize_amount($order_data['amount']);
932 $order->status = sanitize_text_field($order_data['order_status']);
933 $order->payment_method = sanitize_text_field($order_data['payment_method']);
934 $order->transaction_id = sanitize_text_field($order_data['transaction_id']);
935 $order->date_created = $order_data['date_created'];
936 $order_id = $order->save();
937
938 if ( ! $order_id) {
939
940 return new WP_Error(
941 'subscribe_user_to_plan_error',
942 ! empty($wpdb->last_error) ? $wpdb->last_error : esc_html__('Unable to add new order. Please try again', 'wp-user-avatar')
943 );
944 }
945
946 $subscription = new SubscriptionEntity();
947 $subscription->parent_order_id = $order_id;
948 $subscription->customer_id = $customer_id;
949 $subscription->plan_id = (int)$plan_id;
950 $subscription->billing_frequency = $plan_obj->billing_frequency;
951 $subscription->initial_amount = ppress_sanitize_amount($order_data['amount']);
952 $subscription->recurring_amount = $plan_obj->price;
953 $subscription->expiration_date = SubscriptionService::init()->get_plan_expiration_datetime($plan_obj->id);
954
955 if ($order->is_completed()) {
956 if ($subscription->has_trial()) {
957 $subscription_id = $subscription->enable_subscription_trial();
958 } else {
959 $subscription_id = $subscription->activate_subscription();
960 }
961
962 } else {
963 $subscription_id = $subscription->save();
964 }
965
966 if ( ! $subscription_id) {
967
968 return new WP_Error(
969 'subscribe_user_to_plan_error',
970 ! empty($wpdb->last_error) ? $wpdb->last_error : esc_html__('Unable to add new subscription. Please try again', 'wp-user-avatar')
971 );
972 }
973
974 $order->id = $order_id;
975 $order->subscription_id = $subscription_id;
976
977 if ($order->is_completed()) {
978 $order->date_completed = $order_data['date_created'];
979 }
980
981 $order->save();
982
983 if ($send_receipt && $order->is_completed()) {
984 // important we call complete_order with synced/updated order object.
985 OrderFactory::fromId($order_id)->complete_order();
986 }
987
988 return [
989 'order_id' => $order_id,
990 'subscription_id' => $subscription_id
991 ];
992 }
993
994 function ppress_is_redirect_to_referrer_after_checkout()
995 {
996 return apply_filters('ppress_checkout_redirect_to_referrer_after_payment', false);
997 }