Exceptions
2 years ago
Formatters
2 years ago
Payments
2 years ago
Routes
2 years ago
Schemas
2 years ago
Utilities
2 years ago
Authentication.php
2 years ago
Formatters.php
2 years ago
Legacy.php
2 years ago
RoutesController.php
2 years ago
SchemaController.php
2 years ago
SessionHandler.php
2 years ago
StoreApi.php
2 years ago
deprecated.php
2 years ago
functions.php
2 years ago
functions.php
88 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Helper functions for interacting with the Store API. |
| 4 | * |
| 5 | * This file is autoloaded via composer.json. |
| 6 | */ |
| 7 | |
| 8 | use Automattic\WooCommerce\StoreApi\StoreApi; |
| 9 | use Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema; |
| 10 | |
| 11 | if ( ! function_exists( 'woocommerce_store_api_register_endpoint_data' ) ) { |
| 12 | |
| 13 | /** |
| 14 | * Register endpoint data under a specified namespace. |
| 15 | * |
| 16 | * @see Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema::register_endpoint_data() |
| 17 | * |
| 18 | * @param array $args Args to pass to register_endpoint_data. |
| 19 | * @returns boolean|\WP_Error True on success, WP_Error on fail. |
| 20 | */ |
| 21 | function woocommerce_store_api_register_endpoint_data( $args ) { |
| 22 | try { |
| 23 | $extend = StoreApi::container()->get( ExtendSchema::class ); |
| 24 | $extend->register_endpoint_data( $args ); |
| 25 | } catch ( \Exception $error ) { |
| 26 | return new \WP_Error( 'error', $error->getMessage() ); |
| 27 | } |
| 28 | return true; |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | if ( ! function_exists( 'woocommerce_store_api_register_update_callback' ) ) { |
| 33 | |
| 34 | /** |
| 35 | * Add callback functions that can be executed by the cart/extensions endpoint. |
| 36 | * |
| 37 | * @see Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema::register_update_callback() |
| 38 | * |
| 39 | * @param array $args Args to pass to register_update_callback. |
| 40 | * @returns boolean|\WP_Error True on success, WP_Error on fail. |
| 41 | */ |
| 42 | function woocommerce_store_api_register_update_callback( $args ) { |
| 43 | try { |
| 44 | $extend = StoreApi::container()->get( ExtendSchema::class ); |
| 45 | $extend->register_update_callback( $args ); |
| 46 | } catch ( \Exception $error ) { |
| 47 | return new \WP_Error( 'error', $error->getMessage() ); |
| 48 | } |
| 49 | return true; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | if ( ! function_exists( 'woocommerce_store_api_register_payment_requirements' ) ) { |
| 54 | |
| 55 | /** |
| 56 | * Registers and validates payment requirements callbacks. |
| 57 | * |
| 58 | * @see Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema::register_payment_requirements() |
| 59 | * |
| 60 | * @param array $args Args to pass to register_payment_requirements. |
| 61 | * @returns boolean|\WP_Error True on success, WP_Error on fail. |
| 62 | */ |
| 63 | function woocommerce_store_api_register_payment_requirements( $args ) { |
| 64 | try { |
| 65 | $extend = StoreApi::container()->get( ExtendSchema::class ); |
| 66 | $extend->register_payment_requirements( $args ); |
| 67 | } catch ( \Exception $error ) { |
| 68 | return new \WP_Error( 'error', $error->getMessage() ); |
| 69 | } |
| 70 | return true; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | if ( ! function_exists( 'woocommerce_store_api_get_formatter' ) ) { |
| 75 | |
| 76 | /** |
| 77 | * Returns a formatter instance. |
| 78 | * |
| 79 | * @see Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema::get_formatter() |
| 80 | * |
| 81 | * @param string $name Formatter name. |
| 82 | * @return Automattic\WooCommerce\StoreApi\Formatters\FormatterInterface |
| 83 | */ |
| 84 | function woocommerce_store_api_get_formatter( $name ) { |
| 85 | return StoreApi::container()->get( ExtendSchema::class )->get_formatter( $name ); |
| 86 | } |
| 87 | } |
| 88 |