PluginProbe
Tiered Pricing Table for WooCommerce / trunk
Tiered Pricing Table for WooCommerce vtrunk
7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 All 90 releases
tier-pricing-table / src / Addons / RequestAQuote / API / FormsEndpoint.php

FormsEndpoint.php in Tiered Pricing Table for WooCommerce trunk, at src/Addons/RequestAQuote/API/FormsEndpoint.php

47 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Addons\RequestAQuote\API;
2
3 use WP_REST_Controller;
4 use WP_REST_Server;
5
6 class FormsEndpoint extends WP_REST_Controller {
7
8 protected $namespace = 'tier-pricing-table/v1';
9 protected $restBase = 'quote-forms';
10
11 public function register_routes() {
12 register_rest_route( $this->namespace, '/' . $this->restBase, array(
13 array(
14 'methods' => WP_REST_Server::READABLE,
15 'callback' => array( $this, 'get_items' ),
16 'permission_callback' => array( $this, 'permissions_check' ),
17 ),
18 array(
19 'methods' => WP_REST_Server::CREATABLE,
20 'callback' => array( $this, 'create_item' ),
21 'permission_callback' => array( $this, 'permissions_check' ),
22 ),
23 ) );
24 }
25
26 public function permissions_check( $request ) {
27 return current_user_can( 'manage_woocommerce' );
28 }
29
30 public function get_items( $request ) {
31 $forms = get_option( 'tier_pricing_table_quote_forms', array() );
32 return rest_ensure_response( $forms );
33 }
34
35 public function create_item( $request ) {
36 $forms = $request->get_param( 'forms' );
37
38 if ( ! is_array( $forms ) ) {
39 return new \WP_Error( 'invalid_data', 'Forms must be an array', array( 'status' => 400 ) );
40 }
41
42 update_option( 'tier_pricing_table_quote_forms', $forms );
43
44 return rest_ensure_response( $forms );
45 }
46 }
47