PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.17
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.17
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 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / includes / API / V2 / Proxy / Coupons_Proxy_Behavior.php

Coupons_Proxy_Behavior.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.17, at includes/API/V2/Proxy/Coupons_Proxy_Behavior.php

42 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Coupon catalog proxy behavior.
4 *
5 * @package WCPOS\WooCommercePOS\API\V2\Proxy
6 */
7
8 namespace WCPOS\WooCommercePOS\API\V2\Proxy;
9
10 /**
11 * Relaxes WooCommerce coupon read permission only during the forward.
12 */
13 final class Coupons_Proxy_Behavior extends Scoped_Proxy_Behavior {
14 /**
15 * Install this resource's hooks and return their removal tuples.
16 *
17 * @return array<int, array{0: string, 1: callable, 2: int}>
18 */
19 protected function install(): array {
20 $filter = static function ( $permission, $context, $object_id, $post_type ) {
21 if ( ! $permission && 'shop_coupon' === $post_type && 'read' === $context ) {
22 $permission = current_user_can( 'access_woocommerce_pos' );
23 }
24
25 return $permission;
26 };
27 add_filter( 'woocommerce_rest_check_permissions', $filter, 10, 4 );
28
29 // Coupon date/modified sorts tie routinely (imports share timestamps);
30 // pin the id tiebreak so multi-page walks stay stable (see Stable_Sort).
31 $stable_sort = static function ( $args ) {
32 return Stable_Sort::with_post_id_tiebreak( (array) $args );
33 };
34 add_filter( 'woocommerce_rest_shop_coupon_object_query', $stable_sort );
35
36 return array(
37 array( 'woocommerce_rest_check_permissions', $filter, 10 ),
38 array( 'woocommerce_rest_shop_coupon_object_query', $stable_sort, 10 ),
39 );
40 }
41 }
42