PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.21
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.21
1.10.22 1.10.21 1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 All 166 releases
woocommerce-pos / includes / wcpos-functions.php

wcpos-functions.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.21, at includes/wcpos-functions.php

721 lines 23.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Global helper functions for WCPOS.
4 *
5 * @author Paul Kilmurray <[email protected]>
6 *
7 * @see http://wcpos.com
8 * @package WCPOS\WooCommercePOS
9 */
10
11 use WCPOS\WooCommercePOS\Admin\Permalink;
12 use WCPOS\WooCommercePOS\Logger;
13 use WCPOS\WooCommercePOS\Services\Settings;
14 use WCPOS\WooCommercePOS\Template_Router;
15 use const WCPOS\WooCommercePOS\PLUGIN_PATH;
16 use const WCPOS\WooCommercePOS\SHORT_NAME;
17 use const WCPOS\WooCommercePOS\VERSION;
18
19 /*
20 * ============================================================================
21 * WCPOS Functions
22 * ============================================================================
23 *
24 * Primary functions using the wcpos_ prefix.
25 */
26
27 /*
28 * getallheaders() is an alias of apache_response_headers()
29 * This function provides compatibility for nginx servers
30 */
31 if ( ! \function_exists( 'getallheaders' ) ) {
32 /**
33 * Polyfill for getallheaders() on nginx servers.
34 *
35 * @return array The request headers.
36 */
37 function getallheaders(): array { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- polyfill for missing PHP function.
38 $headers = array();
39 foreach ( $_SERVER as $name => $value ) {
40 // RFC2616 (HTTP/1.1) defines header fields as case-insensitive entities.
41 if ( 'http_' == strtolower( substr( $name, 0, 5 ) ) ) {
42 $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
43 }
44 }
45
46 return $headers;
47 }
48 }
49
50 /*
51 * Resolve the URL scheme for POS permalinks.
52 *
53 * @return string|null 'https' when force_ssl is enabled, null for the home scheme.
54 */
55 if ( ! \function_exists( 'wcpos_url_scheme' ) ) {
56 /**
57 * Resolve the URL scheme for POS permalinks.
58 *
59 * See Settings::url_scheme() for the policy.
60 *
61 * @return string|null 'https' when force_ssl is enabled, null for the home scheme.
62 */
63 function wcpos_url_scheme(): ?string { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- uses wcpos_ prefix.
64 return Settings::instance()->url_scheme();
65 }
66 }
67
68 /*
69 * Construct the POS permalink.
70 *
71 * @param string $page Page slug.
72 * @return string POS URL.
73 */
74 if ( ! \function_exists( 'wcpos_url' ) ) {
75 /**
76 * Construct the POS permalink.
77 *
78 * The trailing slash follows the site's permalink structure, via
79 * user_trailingslashit().
80 *
81 * @param string $page Page slug.
82 *
83 * @return string POS URL.
84 */
85 function wcpos_url( $page = '' ): string { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- uses wcpos_ prefix.
86 $slug = Permalink::get_slug();
87
88 return home_url( user_trailingslashit( $slug . '/' . $page ), wcpos_url_scheme() );
89 }
90 }
91
92 /*
93 * Construct a POS checkout permalink.
94 *
95 * @param string $path Path relative to the wcpos-checkout endpoint.
96 * @return string POS checkout URL.
97 */
98 if ( ! \function_exists( 'wcpos_checkout_url' ) ) {
99 /**
100 * Construct a POS checkout permalink.
101 *
102 * Respects the force_ssl setting, like wcpos_url(), so checkout and receipt
103 * links work when the site home URL is http but the POS is served over https,
104 * eg: behind an SSL-terminating proxy.
105 *
106 * Like home_url(), this performs no encoding — pass trusted path segments
107 * only and escape the result on output.
108 *
109 * The trailing slash follows the site's permalink structure, via
110 * user_trailingslashit(). Slash-less URLs can trip origin rewrite rules
111 * that force a trailing slash — some redirect to a hardcoded http://
112 * target, which the browser then blocks as mixed content. The slash is
113 * appended to the end of the string, so $path must not contain a query
114 * string or fragment; append query args to the returned URL instead.
115 *
116 * @param string $path Path relative to the wcpos-checkout endpoint, eg: 'order-pay/123'.
117 *
118 * @return string POS checkout URL.
119 */
120 function wcpos_checkout_url( $path = '' ): string { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- uses wcpos_ prefix.
121 $full_path = Template_Router::CHECKOUT_PATH . '/' . ltrim( $path, '/' );
122
123 return home_url( user_trailingslashit( $full_path ), wcpos_url_scheme() );
124 }
125 }
126
127 /*
128 * Test for POS requests to the server.
129 *
130 * @param string $type Request type: 'query_var', 'header', or 'all'.
131 * @return bool Whether this is a POS request.
132 */
133 if ( ! \function_exists( 'wcpos_request' ) ) {
134 /**
135 * Test for POS requests to the server.
136 *
137 * Core's rest_api_loaded() reads this query var, which remains the original
138 * outer route during internal re-dispatches; this behavior is load-bearing.
139 *
140 * @param string $type Request type: 'query_var', 'header', 'rest_route', or 'all'.
141 *
142 * @return bool Whether this is a POS request.
143 */
144 function wcpos_request( $type = 'all' ): bool { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- uses wcpos_ prefix.
145 // check query_vars, eg: ?wcpos=1 or /pos rewrite rule.
146 if ( 'all' == $type || 'query_var' == $type ) {
147 global $wp;
148 if ( 1 == isset( $wp->query_vars[ SHORT_NAME ] ) && $wp->query_vars[ SHORT_NAME ] ) {
149 return true;
150 }
151 }
152
153 // check headers, eg: from ajax request.
154 if ( 'all' == $type || 'header' == $type ) {
155 $headers = array_change_key_case( getallheaders() ); // convert headers to lowercase.
156 if ( 1 == isset( $headers[ 'x-' . SHORT_NAME ] ) && $headers[ 'x-' . SHORT_NAME ] ) {
157 return true;
158 }
159 }
160
161 if ( ( 'all' == $type || 'rest_route' == $type ) && isset( $GLOBALS['wp']->query_vars['rest_route'] ) ) {
162 $route = '/' . ltrim( (string) $GLOBALS['wp']->query_vars['rest_route'], '/' );
163 return 1 === preg_match( '#^/' . preg_quote( SHORT_NAME, '#' ) . '/v\d+(?:/|$)#', $route );
164 }
165
166 return false;
167 }
168 }
169
170 /*
171 * Check for POS admin requests.
172 *
173 * @return mixed Admin request header value or false.
174 */
175 if ( ! \function_exists( 'wcpos_admin_request' ) ) {
176 /**
177 * Check for POS admin requests.
178 *
179 * @return mixed Admin request header value or false.
180 */
181 function wcpos_admin_request() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- uses wcpos_ prefix.
182 if ( \function_exists( 'getallheaders' ) ) {
183 $headers = getallheaders();
184 if ( $headers && isset( $headers['X-WC-POS-ADMIN'] ) ) {
185 return $headers['X-WC-POS-ADMIN'];
186 }
187 }
188 if ( isset( $_SERVER['HTTP_X_woocommerce_pos_ADMIN'] ) ) {
189 return sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_woocommerce_pos_ADMIN'] ) );
190 }
191
192 return false;
193 }
194 }
195
196 /*
197 * Helper function to get WCPOS settings.
198 *
199 * @param string $id Settings ID.
200 * @param string $key Optional settings key.
201 * @return mixed Settings value.
202 */
203 if ( ! \function_exists( 'wcpos_get_settings' ) ) {
204 /**
205 * Helper function to get WCPOS settings.
206 *
207 * @param string $id Settings ID.
208 * @param string $key Optional settings key.
209 *
210 * @return mixed Settings value.
211 */
212 function wcpos_get_settings( $id, $key = null ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- uses wcpos_ prefix.
213 $settings_service = Settings::instance();
214
215 return $settings_service->get_settings( $id, $key );
216 }
217 }
218
219 /*
220 * Determine whether WCPOS Pro is active.
221 *
222 * @return bool Whether WCPOS Pro is active.
223 */
224 if ( ! \function_exists( 'wcpos_is_pro_active' ) ) {
225 /**
226 * Determine whether WCPOS Pro is active.
227 */
228 function wcpos_is_pro_active(): bool { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- uses wcpos_ prefix.
229 return (bool) apply_filters( 'woocommerce_pos_is_pro_active', \defined( 'WCPOS\WooCommercePOSPro\VERSION' ) );
230 }
231 }
232
233 if ( ! \function_exists( 'wcpos_get_site_identity_home' ) ) {
234 /**
235 * Get the site address as an identity: no scheme, no `www.`, no trailing
236 * slash; the host lower-cased; the port and the case-sensitive path kept,
237 * so `example.com/staging` is another site and `www.example.com` is not.
238 *
239 * @return string Normalised home address.
240 */
241 function wcpos_get_site_identity_home(): string { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- uses wcpos_ prefix.
242 $parts = wp_parse_url( '//' . preg_replace( '#^(?:https?:)?//#i', '', home_url() ) );
243 $host = preg_replace( '#^www\.#', '', strtolower( (string) ( $parts['host'] ?? '' ) ) );
244 $port = isset( $parts['port'] ) ? ':' . $parts['port'] : '';
245
246 return untrailingslashit( $host . $port . ( $parts['path'] ?? '' ) );
247 }
248 }
249
250 if ( ! \function_exists( 'wcpos_site_identity_home_row' ) ) {
251 /**
252 * Read the persisted home marker straight from the options table.
253 *
254 * The option cache answers get_option() for the rest of the request, and a
255 * same-value update_option() leaves it untouched; this is the only read that can tell a
256 * marker another request already advanced from one whose write failed.
257 *
258 * @return string|null The stored marker, or null when absent.
259 */
260 function wcpos_site_identity_home_row(): ?string { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- uses wcpos_ prefix.
261 global $wpdb;
262 $row = $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- bypasses the option cache on purpose, see docblock.
263 $wpdb->prepare( "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", 'woocommerce_pos_uuid_home' ) // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- core table name.
264 );
265
266 return \is_string( $row ) ? $row : null;
267 }
268 }
269
270 /*
271 * Get the site UUID (Plugin State), tied to the site address.
272 *
273 * @return string Site UUID.
274 */
275 if ( ! \function_exists( 'wcpos_get_site_uuid' ) ) {
276 /**
277 * Get the site UUID, generating it on first use or when the address changes.
278 *
279 * Single owner for the woocommerce_pos_uuid option — the
280 * generate-if-missing logic previously lived in three places (REST index,
281 * POS frontend, analytics) and could race.
282 * The saved home prevents database clones sharing a live store's identity.
283 * On upgrade, an absent home is recorded without changing the existing UUID.
284 *
285 * @return string Site UUID.
286 */
287 function wcpos_get_site_uuid(): string { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- uses wcpos_ prefix.
288 $home = wcpos_get_site_identity_home();
289 $stored_home = get_option( 'woocommerce_pos_uuid_home' );
290 if ( false === $stored_home ) {
291 // Keep the first writer's home if another request wins the race.
292 $stored_home = add_option( 'woocommerce_pos_uuid_home', $home )
293 ? $home
294 : get_option( 'woocommerce_pos_uuid_home' );
295 }
296
297 if ( $stored_home !== $home ) {
298 // A moved address is a new identity. Two requests can both land
299 // here; the last write wins and each returns what is stored, so the
300 // REST response never advertises a uuid the database does not hold.
301 // The home marker advances only behind a persisted uuid: a vetoed or
302 // failed write would otherwise hand out an identity that the next
303 // call, seeing a matching home, no longer returns.
304 $previous = get_option( 'woocommerce_pos_uuid', '' );
305 $minted = \Ramsey\Uuid\Uuid::uuid4()->toString();
306 if ( update_option( 'woocommerce_pos_uuid', $minted ) ) {
307 // update_option() also answers false when the row already holds
308 // $home: a concurrent request finished the move between this one's
309 // read and its write. That is a completed move, not a failed one,
310 // and rolling back would leave the old uuid behind the new marker
311 // for good, since every later call sees a matching home. This
312 // request's option cache still holds the old marker (the same-value
313 // UPDATE touched no row, so nothing refreshed it), so the check
314 // reads the row itself and, when the move is confirmed, drops the
315 // stale cache so a later call in this request does not mint again,
316 // and drops the uuid this request cached from its own write so the
317 // value returned below is the one the other request left stored.
318 $marker_moved = update_option( 'woocommerce_pos_uuid_home', $home ) || wcpos_site_identity_home_row() === $home;
319 if ( $marker_moved && get_option( 'woocommerce_pos_uuid_home' ) !== $home ) {
320 wp_cache_delete( 'woocommerce_pos_uuid', 'options' );
321 wp_cache_delete( 'woocommerce_pos_uuid_home', 'options' );
322 wp_cache_delete( 'alloptions', 'options' );
323 }
324 if ( ! $marker_moved && \is_string( $previous ) && '' !== $previous ) {
325 // The marker did not move: put the previous uuid back so the next
326 // call retries the whole move, rather than minting again on top of
327 // a rotation the marker never recorded.
328 update_option( 'woocommerce_pos_uuid', $previous );
329 }
330 }
331
332 $stored = get_option( 'woocommerce_pos_uuid', '' );
333 if ( \is_string( $stored ) && '' !== $stored ) {
334 return $stored;
335 }
336 }
337
338 $uuid = get_option( 'woocommerce_pos_uuid', '' );
339 if ( \is_string( $uuid ) && '' !== $uuid ) {
340 return $uuid;
341 }
342
343 $uuid = \Ramsey\Uuid\Uuid::uuid4()->toString();
344
345 // add_option() is a no-op when the option already exists, so a
346 // concurrent request that won the race keeps its value.
347 if ( ! add_option( 'woocommerce_pos_uuid', $uuid ) ) {
348 $existing = get_option( 'woocommerce_pos_uuid', '' );
349 if ( \is_string( $existing ) && '' !== $existing ) {
350 return $existing;
351 }
352 update_option( 'woocommerce_pos_uuid', $uuid );
353 }
354
355 return $uuid;
356 }
357 }
358
359 /*
360 * Simple wrapper for json_encode.
361 *
362 * Use JSON_FORCE_OBJECT for PHP 5.3 or higher with fallback for
363 * PHP less than 5.3.
364 *
365 * @param mixed $data Data to encode.
366 * @return string|false JSON string or false on failure.
367 */
368 if ( ! \function_exists( 'wcpos_json_encode' ) ) {
369 /**
370 * Simple wrapper for json_encode with JSON_FORCE_OBJECT.
371 *
372 * @param mixed $data Data to encode.
373 *
374 * @return string|false JSON string or false on failure.
375 */
376 function wcpos_json_encode( $data ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- uses wcpos_ prefix.
377 $args = array( $data, JSON_FORCE_OBJECT );
378
379 return \call_user_func_array( 'json_encode', $args );
380 }
381 }
382
383 /*
384 * Return template path for a given template.
385 *
386 * @param string $template Template name.
387 * @return string|null Template path or null if not found.
388 */
389 if ( ! \function_exists( 'wcpos_locate_template' ) ) {
390 /**
391 * Return template path for a given template.
392 *
393 * @param string $template Template name.
394 *
395 * @return string|null Template path or null if not found.
396 */
397 function wcpos_locate_template( $template = '' ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- uses wcpos_ prefix.
398 // check theme directory first.
399 $path = locate_template(
400 array(
401 'woocommerce-pos/' . $template,
402 )
403 );
404
405 // if not, use plugin template.
406 if ( ! $path ) {
407 $path = PLUGIN_PATH . 'templates/' . $template;
408 }
409
410 /**
411 * Filters the template path.
412 *
413 * @hook woocommerce_pos_locate_template
414 *
415 * @since 1.0.0
416 *
417 * @param string $path The full path to the template.
418 * @param string $template The template name, eg: 'receipt.php'.
419 *
420 * @return string $path The full path to the template.
421 */
422 $filtered_path = apply_filters( 'woocommerce_pos_locate_template', $path, $template ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- legacy hook name.
423
424 // Check if the filtered template file exists.
425 if ( file_exists( $filtered_path ) ) {
426 return $filtered_path;
427 }
428
429 // Echo a message or handle the error as needed if the file path does not exist.
430 echo "The template file '" . esc_html( $filtered_path ) . "' does not exist.";
431
432 return null;
433 }
434 }
435
436 /*
437 * Remove newlines and code spacing.
438 *
439 * @param string $str HTML string to trim.
440 * @return string Trimmed string.
441 */
442 if ( ! \function_exists( 'wcpos_trim_html_string' ) ) {
443 /**
444 * Remove newlines and code spacing from an HTML string.
445 *
446 * @param string $str HTML string to trim.
447 *
448 * @return string Trimmed string.
449 */
450 function wcpos_trim_html_string( $str ): string { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- uses wcpos_ prefix.
451 return preg_replace( '/^\s+|\n|\r|\s+$/m', '', $str );
452 }
453 }
454
455 /*
456 * Get documentation URL.
457 *
458 * @param string $page Documentation page.
459 * @return string Documentation URL.
460 */
461 if ( ! \function_exists( 'wcpos_doc_url' ) ) {
462 /**
463 * Get documentation URL.
464 *
465 * @param string $page Documentation page.
466 *
467 * @return string Documentation URL.
468 */
469 function wcpos_doc_url( $page ): string { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- uses wcpos_ prefix.
470 return 'http://docs.wcpos.com/v/' . VERSION . '/en/' . $page;
471 }
472 }
473
474 /*
475 * Get FAQ URL.
476 *
477 * @param string $page FAQ page.
478 * @return string FAQ URL.
479 */
480 if ( ! \function_exists( 'wcpos_faq_url' ) ) {
481 /**
482 * Get FAQ URL.
483 *
484 * @param string $page FAQ page.
485 *
486 * @return string FAQ URL.
487 */
488 function wcpos_faq_url( $page ): string { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- uses wcpos_ prefix.
489 return 'http://faq.wcpos.com/v/' . VERSION . '/en/' . $page;
490 }
491 }
492
493 /*
494 * Helper function to check whether an order is a POS order.
495 *
496 * @param \WC_Order|int $order Order object or ID.
497 * @return bool Whether the order is a POS order.
498 */
499 if ( ! \function_exists( 'wcpos_is_pos_order' ) ) {
500 /**
501 * Helper function to check whether an order is a POS order.
502 *
503 * @param \WC_Order|int $order Order object or ID.
504 *
505 * @return bool Whether the order is a POS order.
506 */
507 function wcpos_is_pos_order( $order ): bool { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- uses wcpos_ prefix.
508 // Handle various input types and edge cases.
509 if ( ! $order instanceof WC_Order ) {
510 // Sometimes the order is passed as an ID.
511 if ( is_numeric( $order ) ) {
512 $order = wc_get_order( $order );
513 }
514
515 // If we still don't have a valid order, return false.
516 if ( ! $order instanceof WC_Order ) {
517 return false;
518 }
519 }
520
521 $legacy = $order->get_meta( '_pos', true );
522 $created_via = $order->get_created_via();
523
524 return 'woocommerce-pos' === $created_via || '1' === $legacy;
525 }
526 }
527
528 /*
529 * Get a default WooCommerce template.
530 *
531 * @param string $template_name Template name.
532 * @param array $args Arguments.
533 */
534 if ( ! \function_exists( 'wcpos_get_woocommerce_template' ) ) {
535 /**
536 * Get a default WooCommerce template.
537 *
538 * @param string $template_name Template name.
539 * @param array $args Arguments.
540 */
541 function wcpos_get_woocommerce_template( $template_name, $args = array() ): void { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- uses wcpos_ prefix.
542 $plugin_path = WC()->plugin_path();
543 $template = trailingslashit( $plugin_path . '/templates' ) . $template_name;
544
545 /**
546 * Filter the default WooCommerce template path.
547 *
548 * @param string $template Template path.
549 * @param string $template_name Template name.
550 * @param array $args Arguments.
551 */
552 $template = apply_filters( 'wcpos_locate_woocommerce_template', $template, $template_name, $args ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- uses wcpos_ prefix.
553
554 if ( ! file_exists( $template ) ) {
555 Logger::log( \sprintf( 'WooCommerce default template not found: %s', $template ) );
556
557 return;
558 }
559
560 if ( $args && \is_array( $args ) ) {
561 extract( $args ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
562 }
563
564 include $template;
565 }
566 }
567
568 /*
569 * ============================================================================
570 * Legacy Aliases
571 * ============================================================================
572 *
573 * These functions use the old woocommerce_pos_ prefix.
574 * They are kept for backwards compatibility but new code should use wcpos_ prefix.
575 *
576 * @deprecated Use wcpos_* functions instead.
577 */
578
579 if ( ! \function_exists( 'woocommerce_pos_url' ) ) {
580 /**
581 * Legacy alias for wcpos_url().
582 *
583 * @deprecated Use wcpos_url() instead.
584 *
585 * @param mixed $page The page slug.
586 */
587 function woocommerce_pos_url( $page = '' ): string {
588 return wcpos_url( $page );
589 }
590 }
591
592 if ( ! \function_exists( 'woocommerce_pos_request' ) ) {
593 /**
594 * Legacy alias for wcpos_request().
595 *
596 * @deprecated Use wcpos_request() instead.
597 *
598 * @param mixed $type The request type.
599 */
600 function woocommerce_pos_request( $type = 'all' ): bool {
601 return wcpos_request( $type );
602 }
603 }
604
605 if ( ! \function_exists( 'woocommerce_pos_admin_request' ) ) {
606 /**
607 * Legacy alias for wcpos_admin_request().
608 *
609 * @deprecated Use wcpos_admin_request() instead.
610 */
611 function woocommerce_pos_admin_request() {
612 return wcpos_admin_request();
613 }
614 }
615
616 if ( ! \function_exists( 'woocommerce_pos_get_settings' ) ) {
617 /**
618 * Legacy alias for wcpos_get_settings().
619 *
620 * @deprecated Use wcpos_get_settings() instead.
621 *
622 * @param mixed $id The settings ID.
623 * @param null|mixed $key The settings key.
624 */
625 function woocommerce_pos_get_settings( $id, $key = null ) {
626 return wcpos_get_settings( $id, $key );
627 }
628 }
629
630 if ( ! \function_exists( 'woocommerce_pos_get_anon_id' ) ) {
631 /**
632 * Returns the anonymous analytics id (wcpos_anon_id), creating it on first use.
633 *
634 * Supported accessor for the Pro plugin's licence-activation request and the
635 * wcpos.com purchase reconciler join (landing-experiments spec §5.3c).
636 *
637 * @return string v4 UUID.
638 */
639 function woocommerce_pos_get_anon_id(): string {
640 return ( new \WCPOS\WooCommercePOS\Services\Anon_ID() )->get();
641 }
642 }
643
644 if ( ! \function_exists( 'woocommerce_pos_json_encode' ) ) {
645 /**
646 * Legacy alias for wcpos_json_encode().
647 *
648 * @deprecated Use wcpos_json_encode() instead.
649 *
650 * @param mixed $data The data to encode.
651 */
652 function woocommerce_pos_json_encode( $data ) {
653 return wcpos_json_encode( $data );
654 }
655 }
656
657 if ( ! \function_exists( 'woocommerce_pos_locate_template' ) ) {
658 /**
659 * Legacy alias for wcpos_locate_template().
660 *
661 * @deprecated Use wcpos_locate_template() instead.
662 *
663 * @param mixed $template The template name.
664 */
665 function woocommerce_pos_locate_template( $template = '' ) {
666 return wcpos_locate_template( $template );
667 }
668 }
669
670 if ( ! \function_exists( 'woocommerce_pos_trim_html_string' ) ) {
671 /**
672 * Legacy alias for wcpos_trim_html_string().
673 *
674 * @deprecated Use wcpos_trim_html_string() instead.
675 *
676 * @param mixed $str The HTML string.
677 */
678 function woocommerce_pos_trim_html_string( $str ): string {
679 return wcpos_trim_html_string( $str );
680 }
681 }
682
683 if ( ! \function_exists( 'woocommerce_pos_doc_url' ) ) {
684 /**
685 * Legacy alias for wcpos_doc_url().
686 *
687 * @deprecated Use wcpos_doc_url() instead.
688 *
689 * @param mixed $page The documentation page.
690 */
691 function woocommerce_pos_doc_url( $page ): string {
692 return wcpos_doc_url( $page );
693 }
694 }
695
696 if ( ! \function_exists( 'woocommerce_pos_faq_url' ) ) {
697 /**
698 * Legacy alias for wcpos_faq_url().
699 *
700 * @deprecated Use wcpos_faq_url() instead.
701 *
702 * @param mixed $page The FAQ page.
703 */
704 function woocommerce_pos_faq_url( $page ): string {
705 return wcpos_faq_url( $page );
706 }
707 }
708
709 if ( ! \function_exists( 'woocommerce_pos_is_pos_order' ) ) {
710 /**
711 * Legacy alias for wcpos_is_pos_order().
712 *
713 * @deprecated Use wcpos_is_pos_order() instead.
714 *
715 * @param mixed $order The order object or ID.
716 */
717 function woocommerce_pos_is_pos_order( $order ): bool {
718 return wcpos_is_pos_order( $order );
719 }
720 }
721