PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 5.4.2
WooCommerce Square v5.4.2
5.4.2 5.4.1 5.4.0 trunk 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.7.0 2.8.0 2.9.0 2.9.1 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.2.0 3.3.0 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.7.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 4.0.0 4.1.0 4.2.0 4.2.1 4.2.2 4.2.3 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.9.0 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 4.9.8 4.9.9 5.0.0 5.0.1 5.1.0 5.1.1 5.1.2 5.2.0 5.3.0 5.3.1 5.3.2 5.3.3
woocommerce-square / includes / Admin / Rest / WC_REST_Square_Gift_Cards_Settings_Controller.php
woocommerce-square / includes / Admin / Rest Last commit date
WC_REST_Square_Cash_App_Settings_Controller.php 2 years ago WC_REST_Square_Credit_Card_Payment_Settings_Controller.php 2 years ago WC_REST_Square_Gift_Cards_Settings_Controller.php 1 year ago WC_REST_Square_Settings_Controller.php 4 months ago WC_Square_REST_Base_Controller.php 2 years ago
WC_REST_Square_Gift_Cards_Settings_Controller.php
140 lines
1 <?php
2 /**
3 * Class WC_REST_Square_Gift_Cards_Settings_Controller file.
4 */
5
6 namespace WooCommerce\Square\Admin\Rest;
7
8 use WooCommerce\Square\Gateway\Gift_Card;
9 use WP_REST_Server;
10 use WP_REST_Request;
11 use WP_REST_Response;
12
13 defined( 'ABSPATH' ) || exit;
14
15 /**
16 * Class WC_REST_Square_Gift_Cards_Settings_Controller.
17 *
18 * @since 4.7.0
19 */
20 class WC_REST_Square_Gift_Cards_Settings_Controller extends WC_Square_REST_Base_Controller {
21
22 /**
23 * Endpoint path.
24 *
25 * @var string
26 */
27 protected $rest_base = 'wc_square/gift_cards_settings';
28
29 /**
30 * Allowed parameters.
31 *
32 * @var array
33 */
34 private $allowed_params;
35
36 /**
37 * Constructor.
38 */
39 public function __construct() {
40 $this->allowed_params = array(
41 'enabled',
42 'title',
43 'description',
44 'is_default_placeholder',
45 'placeholder_id',
46 );
47
48 add_action( 'rest_api_init', array( $this, 'register_routes' ) );
49 }
50
51 /**
52 * Register routes.
53 */
54 public function register_routes() {
55 register_rest_route(
56 $this->namespace,
57 '/' . $this->rest_base,
58 array(
59 'methods' => WP_REST_Server::READABLE,
60 'callback' => array( $this, 'get_settings' ),
61 'permission_callback' => array( $this, 'check_permission' ),
62 )
63 );
64 register_rest_route(
65 $this->namespace,
66 '/' . $this->rest_base,
67 array(
68 'methods' => WP_REST_Server::EDITABLE,
69 'callback' => array( $this, 'save_settings' ),
70 'permission_callback' => array( $this, 'check_permission' ),
71 'args' => array(
72 'enabled' => array(
73 'description' => __( 'Enable Square payment gateway.', 'woocommerce-square' ),
74 'type' => 'string',
75 'sanitize_callback' => '',
76 ),
77 'title' => array(
78 'description' => __( 'Square payment gateway title.', 'woocommerce-square' ),
79 'type' => 'string',
80 'sanitize_callback' => '',
81 ),
82 'description' => array(
83 'description' => __( 'Square payment gateway description.', 'woocommerce-square' ),
84 'type' => 'string',
85 'sanitize_callback' => '',
86 ),
87 'is_default_placeholder' => array(
88 'description' => __( 'Indicates if a Gift card product should use the default placeholder provided by the plugin.', 'woocommerce-square' ),
89 'type' => 'string',
90 'sanitize_callback' => '',
91 ),
92 'placeholder_id' => array(
93 'description' => __( 'ID of the placeholder media.', 'woocommerce-square' ),
94 'type' => 'integer',
95 'sanitize_callback' => '',
96 ),
97 ),
98 )
99 );
100 }
101
102 /**
103 * Get the data.
104 *
105 * @return WP_REST_Response
106 */
107 public function get_settings() {
108 $square_settings = get_option( Gift_Card::SQUARE_PAYMENT_SETTINGS_OPTION_NAME, array() );
109 $filtered_settings = array_intersect_key( $square_settings, array_flip( $this->allowed_params ) );
110
111 return new WP_REST_Response( $filtered_settings );
112 }
113
114 /**
115 * Update the data.
116 *
117 * @param WP_REST_Request $request Full data about the request.
118 */
119 public function save_settings( WP_REST_Request $request ) {
120 $settings = array();
121
122 foreach ( $this->allowed_params as $index => $key ) {
123 $new_value = wc_clean( wp_unslash( $request->get_param( $key ) ) );
124
125 $settings[ $key ] = $new_value;
126 }
127
128 update_option( Gift_Card::SQUARE_PAYMENT_SETTINGS_OPTION_NAME, $settings );
129
130 /**
131 * Action triggered when the Gift card payment settings are updated.
132 *
133 * @since 4.8.1
134 */
135 do_action( 'wc_square_' . Gift_Card::SQUARE_PAYMENT_SETTINGS_OPTION_NAME . '_settings_updated', $settings );
136
137 wp_send_json_success();
138 }
139 }
140