← All changes
|
includes/API/V2/Proxy/Scoped_Proxy_Behavior.php
+13
-0
1.10.11
→
1.10.18
View file →
| @@ -6,8 +6,9 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace WCPOS\WooCommercePOS\API\V2\Proxy; |
| 9 | 9 | |
| 10 | +use WCPOS\WooCommercePOS\Services\Permission_Rules; | |
| 10 | 11 | use WP_REST_Request; |
| 11 | 12 | |
| 12 | 13 | /** |
| 13 | 14 | * Gives every resource the same install/run/finally/unwind discipline. |
| @@ -12,8 +13,14 @@ | ||
| 12 | 13 | /** |
| 13 | 14 | * Gives every resource the same install/run/finally/unwind discipline. |
| 14 | 15 | */ |
| 15 | 16 | abstract class Scoped_Proxy_Behavior implements Proxy_Behavior { |
| 17 | + /** Permission collection, when this resource has a POS-tier read grant. | |
| 18 | + * | |
| 19 | + * @var string|null | |
| 20 | + */ | |
| 21 | + protected $permission_collection; | |
| 22 | + | |
| 16 | 23 | /** |
| 17 | 24 | * Forward every param untouched. |
| 18 | 25 | * |
| 19 | 26 | * @param array $params Query parameters to forward. |
| @@ -33,12 +40,18 @@ | ||
| 33 | 40 | * @return mixed |
| 34 | 41 | */ |
| 35 | 42 | public function around( callable $forward ) { |
| 36 | 43 | $bindings = $this->install(); |
| 44 | + if ( $this->permission_collection ) { | |
| 45 | + Permission_Rules::install_wc_filter( $this->permission_collection ); | |
| 46 | + } | |
| 37 | 47 | |
| 38 | 48 | try { |
| 39 | 49 | return $this->run( $forward ); |
| 40 | 50 | } finally { |
| 51 | + if ( $this->permission_collection ) { | |
| 52 | + Permission_Rules::uninstall_wc_filter(); | |
| 53 | + } | |
| 41 | 54 | foreach ( array_reverse( $bindings ) as $binding ) { |
| 42 | 55 | remove_filter( $binding[0], $binding[1], $binding[2] ); |
| 43 | 56 | } |
| 44 | 57 | } |