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