PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.4.2
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.4.2
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
← All changes | includes/api/class-weforms-form-notification-controller.php +256 -254 1.6.151.4.2 View file →
@@ -1,254 +1,256 @@
1 -<?php
2 -
3 -/**
4 - * Settings manager class
5 - *
6 - * @since 1.4.2
7 - */
8 -class Weforms_Form_Notification_Controller extends Weforms_REST_Controller {
9 -
10 - /**
11 - * Endpoint namespace
12 - *
13 - * @var string
14 - */
15 - protected $namespace = 'weforms/v1';
16 -
17 - /**
18 - * Route name
19 - *
20 - * @var string
21 - */
22 - protected $rest_base = 'forms';
23 -
24 - public function register_routes() {
25 - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<form_id>[\d]+)/notifications',
26 - [
27 - 'args' => [
28 - 'form_id' => [
29 - 'description' => __( 'Unique identifier for the object', 'weforms' ),
30 - 'type' => 'integer',
31 - 'sanitize_callback' => 'absint',
32 - 'validate_callback' => [ $this, 'is_form_exists' ],
33 - 'required' => true,
34 - ],
35 - ],
36 - [
37 - 'methods' => WP_REST_Server::READABLE,
38 - 'callback' => [ $this, 'get_item_notification' ],
39 - 'args' => [
40 - 'context' => $this->get_context_param( [ 'default' => 'view' ] ),
41 - ],
42 - 'permission_callback' => [ $this, 'get_item_permissions_check' ],
43 - ],
44 - [
45 - 'methods' => WP_REST_Server::CREATABLE,
46 - 'callback' => [ $this, 'add_item_notification' ],
47 - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
48 - 'permission_callback' => [ $this, 'get_item_permissions_check' ],
49 - ],
50 - [
51 - 'methods' => WP_REST_Server::EDITABLE,
52 - 'callback' => [ $this, 'update_item_notification' ],
53 - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
54 - 'permission_callback' => [ $this, 'get_item_permissions_check' ],
55 - ],
56 - ]
57 - );
58 -
59 - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<form_id>[\d]+)/notifications',
60 - [
61 - 'args' => [
62 - 'form_id' => [
63 - 'description' => __( 'Unique identifier for the object', 'weforms' ),
64 - 'type' => 'integer',
65 - 'sanitize_callback' => 'absint',
66 - 'validate_callback' => [ $this, 'is_form_exists' ],
67 - 'required' => true,
68 - ],
69 - 'index' => [
70 - 'description' => __( 'Unique identifier for the object', 'weforms' ),
71 - 'type' => 'array',
72 - 'items' => [
73 - 'type' => 'integer',
74 - ],
75 - 'required' => true,
76 - ],
77 - ],
78 - [
79 - 'methods' => WP_REST_Server::DELETABLE,
80 - 'callback' => [ $this, 'delete_item_notification' ],
81 - // 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::DELETABLE ),
82 - 'permission_callback' => [ $this, 'delete_item_permissions_check' ],
83 - ],
84 - ]
85 - );
86 - }
87 -
88 - /**
89 - * get item notification
90 - *
91 - * @since 1.4.2
92 - *
93 - * @param WP_REST_Request $request
94 - *
95 - * @return WP_REST_Response|WP_Error response object on success, or WP_Error object on failure
96 - */
97 - public function get_item_notification( $request ) {
98 - $form_id = $request->get_param( 'form_id' );
99 - $form = weforms()->form->get( $form_id );
100 - $data = $form->get_notifications();
101 -
102 - $response = $this->prepare_response_for_collection( $data, $request );
103 - $response = rest_ensure_response( $response );
104 - $response->header( 'X-WP-Total', (int) count( $data ) );
105 -
106 - return $response;
107 - }
108 -
109 - /**
110 - * add item notification
111 - *
112 - * @since 1.4.2
113 - *
114 - * @param WP_REST_Request $request
115 - *
116 - * @return WP_REST_Response|WP_Error response object on success, or WP_Error object on failure
117 - */
118 - public function add_item_notification( $request ) {
119 - $form_id = $request->get_param( 'form_id' );
120 - $notifications = $request->get_param( 'notifications' );
121 -
122 - $data = [
123 - 'form_id' => $form_id,
124 - 'notifications' => $notifications,
125 - ];
126 -
127 - $form = weforms()->form->get( $form_id );
128 - $new_form_notification = array_merge( $form->get_notifications(), $data['notifications'] );
129 -
130 - update_post_meta( $data['form_id'], 'notifications', $new_form_notification );
131 -
132 - $form = weforms()->form->get( $form_id );
133 -
134 - $response_data = [
135 - 'id' => $form->data->ID,
136 - 'notifications' => $form->get_notifications(),
137 - ];
138 -
139 - $response = rest_ensure_response( $response_data );
140 - $response->set_status( 201 );
141 -
142 - return $response;
143 - }
144 -
145 - /**
146 - * update item integrations
147 - *
148 - * @since 1.4.2
149 - *
150 - * @param WP_REST_Request $request
151 - *
152 - * @return WP_REST_Response|WP_Error response object on success, or WP_Error object on failure
153 - */
154 - public function update_item_notification( $request ) {
155 - $wpuf_form_id = $request->get_param( 'form_id' );
156 - $notifications = $request->get_param( 'notifications' );
157 -
158 - $data = [
159 - 'form_id' => $wpuf_form_id,
160 - 'notifications' => $notifications,
161 - ];
162 -
163 - $form = weforms()->form->get( $wpuf_form_id );
164 - $existing_notifications = $form->get_notifications();
165 -
166 - foreach ( $existing_notifications as $key => $notification ) {
167 - if ( array_key_exists( $key, $data['notifications'] ) ) {
168 - $existing_notifications[ $key ] = $data['notifications'][$key];
169 - }
170 - }
171 -
172 - update_post_meta( $data['form_id'], 'notifications', $existing_notifications );
173 -
174 - $form = weforms()->form->get( $wpuf_form_id );
175 -
176 - $response_data = [
177 - 'id' => $form->data->ID,
178 - 'notifications' => $form->get_notifications(),
179 - ];
180 -
181 - $response = rest_ensure_response( $response_data );
182 - $response->set_status( 201 );
183 - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $form->id ) ) );
184 -
185 - return $response;
186 - }
187 -
188 - /**
189 - * delete item notification
190 - *
191 - * @since 1.4.2
192 - *
193 - * @param WP_REST_Request $request
194 - *
195 - * @return WP_REST_Response|WP_Error response object on success, or WP_Error object on failure
196 - */
197 - public function delete_item_notification( $request ) {
198 - $form_id = $request->get_param( 'form_id' );
199 - $notification_ids = $request->get_param( 'index' );
200 - $form = weforms()->form->get( $form_id );
201 - $form_notification = $form->get_notifications();
202 -
203 - foreach ( $notification_ids as $notification_id ) {
204 - unset( $form_notification[ $notification_id ] );
205 - }
206 -
207 - update_post_meta( $form_id, 'notifications', array_values( $form_notification ) );
208 -
209 - $form = weforms()->form->get( $form_id );
210 -
211 - $data = [
212 - 'id' => $form->data->ID,
213 - 'notifications' => $form->get_notifications(),
214 - ];
215 -
216 - $response = $this->prepare_response_for_collection( $data, $request );
217 - $response = rest_ensure_response( $response );
218 - $response->header( 'X-WP-Total', (int) count( $data['notifications'] ) );
219 -
220 - return $response;
221 - }
222 -
223 - /**
224 - * Get the Form's schema, conforming to JSON Schema
225 - *
226 - * @return array
227 - */
228 - public function get_item_schema() {
229 - $schema = [
230 - '$schema' => 'http://json-schema.org/draft-04/schema#',
231 - 'title' => 'forms',
232 - 'type' => 'object',
233 - 'properties' => [
234 - 'form_id' => [
235 - 'description' => __( 'Unique identifier for the object', 'weforms' ),
236 - 'type' => 'integer',
237 - 'sanitize_callback' => 'absint',
238 - 'validate_callback' => [ $this, 'is_form_exists' ],
239 - 'context' => [ 'embed', 'view', 'edit' ],
240 - 'required' => true,
241 - 'readonly' => true,
242 - ],
243 - 'notifications' => [
244 - 'description' => __( '', 'weforms' ),
245 - 'type' => 'object',
246 - 'context' => [ 'edit', 'view'],
247 - 'required' => false,
248 - ],
249 - ],
250 - ];
251 -
252 - return $schema;
253 - }
254 -}
1 +<?php
2 +
3 +/**
4 + * Settings manager class
5 + *
6 + * @since 1.4.2
7 + */
8 +
9 +class Weforms_Form_Notification_Controller extends Weforms_REST_Controller {
10 +
11 + /**
12 + * Endpoint namespace
13 + *
14 + * @var string
15 + */
16 + protected $namespace = 'weforms/v1';
17 +
18 + /**
19 + * Route name
20 + *
21 + * @var string
22 + */
23 + protected $rest_base = 'forms';
24 +
25 + public function register_routes() {
26 + register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<form_id>[\d]+)/notifications',
27 + array(
28 + 'args' => array(
29 + 'form_id' => array(
30 + 'description' => __( 'Unique identifier for the object', 'weforms' ),
31 + 'type' => 'integer',
32 + 'sanitize_callback' => 'absint',
33 + 'validate_callback' => array( $this, 'is_form_exists' ),
34 + 'required' => true,
35 + ),
36 + ),
37 + array(
38 + 'methods' => WP_REST_Server::READABLE,
39 + 'callback' => array( $this, 'get_item_notification' ),
40 + 'args' => array(
41 + 'context' => $this->get_context_param( [ 'default' => 'view' ] )
42 + ),
43 + 'permission_callback' => array( $this, 'get_item_permissions_check' ),
44 + ),
45 + array(
46 + 'methods' => WP_REST_Server::CREATABLE,
47 + 'callback' => array( $this, 'add_item_notification' ),
48 + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
49 + 'permission_callback' => array( $this, 'get_item_permissions_check' ),
50 + ),
51 + array(
52 + 'methods' => WP_REST_Server::EDITABLE,
53 + 'callback' => array( $this, 'update_item_notification' ),
54 + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
55 + 'permission_callback' => array( $this, 'get_item_permissions_check' ),
56 + ),
57 + )
58 + );
59 +
60 + register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<form_id>[\d]+)/notifications',
61 + array(
62 + 'args' => array(
63 + 'form_id' => array(
64 + 'description' => __( 'Unique identifier for the object', 'weforms' ),
65 + 'type' => 'integer',
66 + 'sanitize_callback' => 'absint',
67 + 'validate_callback' => array( $this, 'is_form_exists' ),
68 + 'required' => true,
69 + ),
70 + 'index' => array(
71 + 'description' => __( 'Unique identifier for the object', 'weforms' ),
72 + 'type' => 'array',
73 + 'items' => array(
74 + 'type' => 'integer',
75 + ),
76 + 'required' => true,
77 + ),
78 + ),
79 + array(
80 + 'methods' => WP_REST_Server::DELETABLE,
81 + 'callback' => array( $this, 'delete_item_notification' ),
82 + // 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::DELETABLE ),
83 + 'permission_callback' => array( $this, 'delete_item_permissions_check' ),
84 + ),
85 + )
86 + );
87 + }
88 +
89 +
90 + /**
91 + * get item notification
92 + *
93 + * @since 1.4.2
94 + *
95 + * @param WP_REST_Request $request
96 + *
97 + * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
98 + */
99 + public function get_item_notification( $request ) {
100 + $form_id = $request->get_param( 'form_id' );
101 + $form = weforms()->form->get( $form_id );
102 + $data = $form->get_notifications();
103 +
104 + $response = $this->prepare_response_for_collection( $data, $request );
105 + $response = rest_ensure_response( $response );
106 + $response->header( 'X-WP-Total', (int) count( $data ) );
107 +
108 + return $response;
109 + }
110 +
111 + /**
112 + * add item notification
113 + *
114 + * @since 1.4.2
115 + *
116 + * @param WP_REST_Request $request
117 + *
118 + * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
119 + */
120 + public function add_item_notification( $request ) {
121 + $form_id = $request->get_param( 'form_id' );
122 + $notifications = $request->get_param('notifications');
123 +
124 + $data = array(
125 + 'form_id' => $form_id,
126 + 'notifications' => $notifications
127 + );
128 +
129 + $form = weforms()->form->get( $form_id );
130 + $new_form_notification = array_merge( $form->get_notifications(), $data['notifications'] );
131 +
132 + update_post_meta( $data['form_id'], 'notifications', $new_form_notification );
133 +
134 + $form = weforms()->form->get( $form_id );
135 +
136 + $response_data = array(
137 + 'id' => $form->data->ID,
138 + 'notifications' => $form->get_notifications(),
139 + );
140 +
141 + $response = rest_ensure_response( $response_data );
142 + $response->set_status( 201 );
143 +
144 + return $response;
145 + }
146 +
147 + /**
148 + * update item integrations
149 + *
150 + * @since 1.4.2
151 + *
152 + * @param WP_REST_Request $request
153 + *
154 + * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
155 + */
156 + public function update_item_notification( $request ) {
157 + $wpuf_form_id = $request->get_param('form_id');
158 + $notifications = $request->get_param('notifications');
159 +
160 + $data = array(
161 + 'form_id' => $wpuf_form_id,
162 + 'notifications' => $notifications
163 + );
164 +
165 + $form = weforms()->form->get( $wpuf_form_id );
166 + $existing_notifications = $form->get_notifications();
167 +
168 + foreach ( $existing_notifications as $key => $notification ) {
169 + if( array_key_exists( $key , $data['notifications'] ) ) {
170 + $existing_notifications[ $key ] = $data['notifications'][$key];
171 + }
172 + }
173 +
174 + update_post_meta( $data['form_id'], 'notifications', $existing_notifications );
175 +
176 + $form = weforms()->form->get( $wpuf_form_id );
177 +
178 + $response_data = array(
179 + 'id' => $form->data->ID,
180 + 'notifications' => $form->get_notifications(),
181 + );
182 +
183 + $response = rest_ensure_response( $response_data );
184 + $response->set_status( 201 );
185 + $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $form->id ) ) );
186 +
187 + return $response;
188 + }
189 +
190 + /**
191 + * delete item notification
192 + *
193 + * @since 1.4.2
194 + *
195 + * @param WP_REST_Request $request
196 + *
197 + * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
198 + */
199 + public function delete_item_notification( $request ) {
200 + $form_id = $request->get_param( 'form_id' );
201 + $notification_ids = $request->get_param( 'index' );
202 + $form = weforms()->form->get( $form_id );
203 + $form_notification = $form->get_notifications();
204 +
205 + foreach ($notification_ids as $notification_id) {
206 + unset( $form_notification[ $notification_id ] );
207 + }
208 +
209 + update_post_meta( $form_id, 'notifications', array_values( $form_notification ) );
210 +
211 + $form = weforms()->form->get( $form_id );
212 +
213 + $data = array(
214 + 'id' => $form->data->ID,
215 + 'notifications' => $form->get_notifications(),
216 + );
217 +
218 + $response = $this->prepare_response_for_collection( $data, $request );
219 + $response = rest_ensure_response( $response );
220 + $response->header( 'X-WP-Total', (int) count( $data['notifications'] ) );
221 +
222 + return $response;
223 + }
224 +
225 + /**
226 + * Get the Form's schema, conforming to JSON Schema
227 + *
228 + * @return array
229 + */
230 + public function get_item_schema() {
231 + $schema = array(
232 + '$schema' => 'http://json-schema.org/draft-04/schema#',
233 + 'title' => 'forms',
234 + 'type' => 'object',
235 + 'properties' => array(
236 + 'form_id' => array(
237 + 'description' => __( 'Unique identifier for the object', 'weforms' ),
238 + 'type' => 'integer',
239 + 'sanitize_callback' => 'absint',
240 + 'validate_callback' => array( $this, 'is_form_exists' ),
241 + 'context' => array( 'embed', 'view', 'edit' ),
242 + 'required' => true,
243 + 'readonly' => true,
244 + ),
245 + "notifications" => array(
246 + 'description' => __( '', 'weforms' ),
247 + 'type' => 'object',
248 + 'context' => [ 'edit' ,'view'],
249 + 'required' => false,
250 + ),
251 + ),
252 + );
253 +
254 + return $schema;
255 + }
256 +}