PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / trunk
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress vtrunk
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 4 months ago MSFunctions.php 7 months ago PPressBFnote.php 7 months ago Shogun.php 1 year ago custom-settings-api.php 7 months ago
MSFunctions.php
996 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 if ( ! $currency) {
474 $currency = ppress_get_currency();
475 }
476
477 $symbols = ppress_get_currency_symbols();
478
479 $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '';
480
481 return apply_filters('ppress_currency_symbol', $currency_symbol, $currency);
482 }
483
484
485 /**
486 * Get the name of a currency
487 *
488 * @param string $code The currency code
489 *
490 * @return string The currency's name
491 */
492 function ppress_get_currency_name($code = '')
493 {
494 if ( ! $code) {
495 $code = ppress_get_currency();
496 }
497
498 $currencies = ppress_get_currencies();
499 $name = isset($currencies[$code]) ? $currencies[$code] : $code;
500
501 return apply_filters('ppress_currency_name', $name);
502 }
503
504 /**
505 * Accepts an amount (ideally from the database, unmodified) and formats it
506 * for display. The amount itself is formatted and the currency prefix/suffix
507 * is applied and positioned.
508 *
509 * @param string $amount
510 * @param string $currency
511 *
512 * @return string
513 *
514 */
515 function ppress_display_amount($amount, $currency = '')
516 {
517 return (new CurrencyFormatter($amount, $currency))->format()->apply_symbol()->val();
518 }
519
520 /**
521 *
522 * @param $amount
523 *
524 * @return string
525 */
526 function ppress_sanitize_amount($amount)
527 {
528 return (new CurrencyFormatter($amount))->sanitize()->val();
529 }
530
531 /**
532 * Converts price, fee or amount in cent to decimal
533 *
534 * @param $amount
535 *
536 * @return string
537 */
538 function ppress_cent_to_decimal($amount)
539 {
540 return ppress_sanitize_amount(Calculator::init($amount)->dividedBy('100')->val());
541 }
542
543 /**
544 * Converts price, fee or amount in decimal to cent
545 *
546 * @param $amount
547 *
548 * @return string
549 */
550 function ppress_decimal_to_cent($amount)
551 {
552 return (int)Calculator::init($amount)->toScale(2)->multipliedBy(100)->toScale(0)->val();
553 }
554
555 /**
556 * Force https for urls.
557 *
558 * @param mixed $content
559 *
560 * @return string
561 */
562 function ppress_force_https_url($content)
563 {
564 if (is_ssl()) {
565 if (is_array($content)) {
566 $content = array_map('ppress_force_https_url', $content);
567 } else {
568 $content = str_replace('http:', 'https:', $content);
569 }
570 }
571
572 return $content;
573 }
574
575 function ppress_is_test_mode()
576 {
577 return ppress_var(get_option(PPRESS_PAYMENT_METHODS_OPTION_NAME, []), 'test_mode') == 'true';
578 }
579
580 function ppress_get_payment_mode()
581 {
582 return ppress_cache_transform('ppress_get_payment_mode', function () {
583 return ppress_is_test_mode() ? OrderMode::TEST : OrderMode::LIVE;
584 });
585 }
586
587 /**
588 * Converts a date/time to UTC
589 */
590 function ppress_local_datetime_to_utc($date, $format = 'Y-m-d H:i:s')
591 {
592 try {
593 return (new DateTimeImmutable($date, wp_timezone()))
594 ->setTimezone(new DateTimeZone('UTC'))
595 ->format($format);
596 } catch (\Exception $e) {
597 return false;
598 }
599 }
600
601 /**
602 * Formats UTC datetime according to WordPress date/time format and using WordPress site timezone.
603 *
604 * Expects time/timestamp to be in UTC
605 *
606 * @param string $timestamp timestamp or datetime in UTC
607 *
608 * @param string $format
609 *
610 * @return string datetime in WP timezone
611 */
612 function ppress_format_date_time($timestamp, $format = '')
613 {
614 /**
615 * force strtotime to use date as UTC.
616 * @see https://stackoverflow.com/a/6275660/2648410
617 */
618 $timestamp = ! is_numeric($timestamp) ? strtotime($timestamp . ' UTC') : $timestamp;
619
620 $format = empty($format) ? get_option('date_format') . ' ' . get_option('time_format') : $format;
621
622 return wp_date($format, $timestamp);
623 }
624
625 /**
626 * Formats UTC date according to WordPress date format and using WordPress site timezone.
627 *
628 * @param string $timestamp timestamp or datetime in UTC
629 * @param string $format
630 *
631 * @return string date in WP timezone
632 */
633 function ppress_format_date($timestamp, $format = '')
634 {
635 if (empty($timestamp)) return '';
636
637 /**
638 * force strtotime to use date as UTC.
639 * @see https://stackoverflow.com/a/6275660/2648410
640 */
641 $timestamp = ! is_numeric($timestamp) ? strtotime($timestamp . ' UTC') : $timestamp;
642
643 $format = empty($format) ? get_option('date_format') : $format;
644
645 return wp_date($format, $timestamp);
646 }
647
648 function ppress_update_payment_method_setting($key, $value)
649 {
650 $data = get_option(PPRESS_PAYMENT_METHODS_OPTION_NAME, []);
651 $data[$key] = $value;
652 update_option(PPRESS_PAYMENT_METHODS_OPTION_NAME, $data);
653 }
654
655 function ppress_get_payment_method_setting($key = '', $default = false, $is_empty = false)
656 {
657 static $data = null;
658
659 if (is_null($data)) {
660 $data = get_option(PPRESS_PAYMENT_METHODS_OPTION_NAME, []);
661 }
662
663 if ($is_empty === true) {
664 return isset($data[$key]) && ( ! empty($data[$key]) || ppress_is_boolean($data[$key])) ? $data[$key] : $default;
665 }
666
667 return isset($data[$key]) ? $data[$key] : $default;
668 }
669
670 function ppress_get_file_downloads_setting($key = '', $default = false, $is_empty = false)
671 {
672 static $data = null;
673
674 if (is_null($data)) {
675 $data = get_option(PPRESS_FILE_DOWNLOADS_OPTION_NAME, []);
676 }
677
678 if ($is_empty === true) {
679 return isset($data[$key]) && ( ! empty($data[$key]) || ppress_is_boolean($data[$key])) ? $data[$key] : $default;
680 }
681
682 return isset($data[$key]) ? $data[$key] : $default;
683 }
684
685 /**
686 * @return PPRESS_Session
687 */
688 function ppress_session()
689 {
690 return PPRESS_Session::get_instance();
691 }
692
693 function ppress_is_checkout()
694 {
695 $page_id = ppress_settings_by_key('checkout_page_id', 0, true);
696
697 return ($page_id && is_page($page_id)) || ppress_post_content_has_shortcode('profilepress-checkout');
698 }
699
700 function ppress_is_success_page()
701 {
702 $page_id = ppress_settings_by_key('payment_success_page_id', 0, true);
703
704 return ($page_id && is_page($page_id));
705 }
706
707 /**
708 * @param $order_key
709 * @param $payment_method
710 *
711 * @return string
712 */
713 function ppress_get_success_url($order_key = '', $payment_method = '')
714 {
715 $url = get_permalink(
716 absint(ppress_settings_by_key('payment_success_page_id'))
717 );
718
719 $url = ! $url ? home_url() : $url;
720
721 if ( ! empty($order_key)) {
722 $url = add_query_arg(['order_key' => $order_key], $url);
723 }
724
725 if ( ! empty($payment_method)) {
726 $url = add_query_arg(['payment_method' => $payment_method], $url);
727 }
728
729 return apply_filters('ppress_get_success_url', esc_url_raw($url), $order_key);
730 }
731
732 /**
733 * @param $order_key
734 *
735 * @return string
736 */
737 function ppress_get_cancel_url($order_key = '')
738 {
739 $url = get_permalink(
740 absint(ppress_settings_by_key('payment_failure_page_id'))
741 );
742
743 $url = ! $url ? home_url() : $url;
744
745 if ( ! empty($order_key)) {
746 $url = add_query_arg(['order_key' => $order_key], $url);
747 }
748
749 return apply_filters('ppress_get_cancel_url', esc_url_raw($url), $order_key);
750 }
751
752 function ppress_business_name()
753 {
754 return ppress_settings_by_key('business_name', '', true);
755 }
756
757 function ppress_business_address($default = '')
758 {
759 return ppress_settings_by_key('business_address', $default, true);
760 }
761
762 function ppress_business_city($default = '')
763 {
764 return ppress_settings_by_key('business_city', $default, true);
765 }
766
767 function ppress_business_country($default = '')
768 {
769 return ppress_settings_by_key('business_country', $default, true);
770 }
771
772 function ppress_business_state($default = '')
773 {
774 return ppress_settings_by_key('business_state', $default, true);
775 }
776
777 function ppress_business_postal_code($default = '')
778 {
779 return ppress_settings_by_key('business_postal_code', $default, true);
780 }
781
782 function ppress_business_full_address()
783 {
784 $billing_address = ppress_business_address();
785
786 if (empty($billing_address)) return '';
787
788 $business_country = ppress_business_country();
789
790 $state = ppress_var(ppress_array_of_world_states($business_country), ppress_business_state(), ppress_business_state(), true);
791
792 $address = [trim($billing_address)];
793 $address[] = trim(ppress_business_city() . ' ' . $state);
794 $address[] = ppress_business_postal_code();
795 $address[] = ppress_array_of_world_countries($business_country);
796
797 return implode(', ', array_filter($address));
798 }
799
800 function ppress_business_tax_id($default = '')
801 {
802 return ppress_settings_by_key('business_tin', $default, true);
803 }
804
805 /**
806 * Check if a user/customer has an active subscription to a membership plan.
807 *
808 * @param int $user_id
809 * @param int $plan_id
810 * @param bool $by_customer_id
811 *
812 * @return bool
813 */
814 function ppress_has_active_subscription($user_id, $plan_id, $by_customer_id = false)
815 {
816 if (false === $by_customer_id) {
817 $customer = CustomerFactory::fromUserId($user_id);
818 } else {
819 $customer = CustomerFactory::fromId($user_id);
820 }
821
822 return $customer->has_active_subscription($plan_id);
823 }
824
825 /**
826 * Checks whether function is disabled.
827 *
828 * @param string $function Name of the function.
829 *
830 * @return bool Whether or not function is disabled.
831 */
832 function ppress_is_func_disabled($function)
833 {
834 $disabled = explode(',', @ini_get('disable_functions'));
835
836 return in_array($function, $disabled, true);
837 }
838
839 /**
840 * Ignore the time limit set by the server (likely from php.ini.)
841 *
842 * This is usually only necessary during upgrades and exports. If you need to
843 * use this function directly, please be careful in doing so.
844 *
845 * The $time_limit parameter is filterable, but infinite values are not allowed
846 * so any erroneous processes are able to terminate normally.
847 *
848 * @param boolean $ignore_user_abort Whether to call ignore_user_about( true )
849 * @param int $time_limit How long to set the time limit to. Cannot be 0. Default 6 hours.
850 */
851 function ppress_set_time_limit($ignore_user_abort = true, $time_limit = 21600)
852 {
853 // Default time limit is 6 hours
854 $default = HOUR_IN_SECONDS * 6;
855
856 // Only abort if true and if function is enabled
857 if ((true === $ignore_user_abort) && ! ppress_is_func_disabled('ignore_user_abort')) {
858 @ignore_user_abort(true);
859 }
860
861 // Disallow infinite values
862 if (empty($time_limit)) $time_limit = $default;
863
864 // Set time limit to non-infinite value if function is enabled
865 if ( ! ppress_is_func_disabled('set_time_limit')) {
866 @set_time_limit($time_limit);
867 }
868
869 wp_raise_memory_limit('ppress');
870 }
871
872 /**
873 * @param $user_id
874 *
875 * @return int|WP_Error
876 */
877 function ppress_create_customer($user_id)
878 {
879 $customer = CustomerFactory::fromUserId($user_id);
880
881 $customer_id = $customer->get_id();
882
883 if ( ! $customer->exists()) {
884 $customer->user_id = $user_id;
885 $customer_id = $customer->save();
886 if ( ! $customer_id) {
887 return new WP_Error('customer_creation_failure', esc_html__('Unable to create customer. Please try again', 'wp-user-avatar'));
888 }
889 }
890
891 return $customer_id;
892 }
893
894 /**
895 * Subscribe a customer to a membership plan while creating the corresponding order and subscription entity.
896 *
897 * @param int $plan_id
898 * @param int $customer_id
899 * @param array $order_data
900 * @param bool $send_receipt
901 *
902 * @return array|WP_Error
903 */
904 function ppress_subscribe_user_to_plan($plan_id, $customer_id, $order_data = [], $send_receipt = false)
905 {
906 global $wpdb;
907
908 $plan_obj = ppress_get_plan((int)$plan_id);
909
910 if (CustomerFactory::fromId($customer_id)->has_active_subscription($plan_obj->id)) {
911
912 return new WP_Error(
913 'subscribe_user_to_plan_error',
914 sprintf(__('Customer already has an active subscription for %s.', 'wp-user-avatar'), $plan_obj->name)
915 );
916 }
917
918 $order_data = wp_parse_args(array_filter($order_data), [
919 'date_created' => current_time('mysql', true),
920 'payment_method' => StoreGateway::get_instance()->get_id(),
921 'amount' => '0',
922 'order_status' => OrderStatus::COMPLETED,
923 'transaction_id' => ''
924 ]);
925
926 $order = new OrderEntity();
927 $order->plan_id = $plan_obj->id;
928 $order->customer_id = $customer_id;
929 $order->subtotal = ppress_sanitize_amount($order_data['amount']);
930 $order->total = ppress_sanitize_amount($order_data['amount']);
931 $order->status = sanitize_text_field($order_data['order_status']);
932 $order->payment_method = sanitize_text_field($order_data['payment_method']);
933 $order->transaction_id = sanitize_text_field($order_data['transaction_id']);
934 $order->date_created = $order_data['date_created'];
935 $order_id = $order->save();
936
937 if ( ! $order_id) {
938
939 return new WP_Error(
940 'subscribe_user_to_plan_error',
941 ! empty($wpdb->last_error) ? $wpdb->last_error : esc_html__('Unable to add new order. Please try again', 'wp-user-avatar')
942 );
943 }
944
945 $subscription = new SubscriptionEntity();
946 $subscription->parent_order_id = $order_id;
947 $subscription->customer_id = $customer_id;
948 $subscription->plan_id = (int)$plan_id;
949 $subscription->billing_frequency = $plan_obj->billing_frequency;
950 $subscription->initial_amount = ppress_sanitize_amount($order_data['amount']);
951 $subscription->recurring_amount = $plan_obj->price;
952 $subscription->expiration_date = SubscriptionService::init()->get_plan_expiration_datetime($plan_obj->id);
953
954 if ($order->is_completed()) {
955 if ($subscription->has_trial()) {
956 $subscription_id = $subscription->enable_subscription_trial();
957 } else {
958 $subscription_id = $subscription->activate_subscription();
959 }
960
961 } else {
962 $subscription_id = $subscription->save();
963 }
964
965 if ( ! $subscription_id) {
966
967 return new WP_Error(
968 'subscribe_user_to_plan_error',
969 ! empty($wpdb->last_error) ? $wpdb->last_error : esc_html__('Unable to add new subscription. Please try again', 'wp-user-avatar')
970 );
971 }
972
973 $order->id = $order_id;
974 $order->subscription_id = $subscription_id;
975
976 if ($order->is_completed()) {
977 $order->date_completed = $order_data['date_created'];
978 }
979
980 $order->save();
981
982 if ($send_receipt && $order->is_completed()) {
983 // important we call complete_order with synced/updated order object.
984 OrderFactory::fromId($order_id)->complete_order();
985 }
986
987 return [
988 'order_id' => $order_id,
989 'subscription_id' => $subscription_id
990 ];
991 }
992
993 function ppress_is_redirect_to_referrer_after_checkout()
994 {
995 return apply_filters('ppress_checkout_redirect_to_referrer_after_payment', false);
996 }