@@ -147,10 +147,6 @@ public function handle_actions(): void {
147147 if ( isset ( $ _POST ['action ' ] ) && 'save_webhook ' === $ _POST ['action ' ] ) {
148148 $ this ->handle_webhook_save ();
149149 }
150-
151- if ( isset ( $ _GET ['action ' ] ) && 'delete ' === $ _GET ['action ' ] && isset ( $ _GET ['webhook_id ' ] ) ) {
152- $ this ->handle_webhook_delete ();
153- }
154150 }
155151
156152 /**
@@ -186,7 +182,7 @@ private function verify_nonce( string $nonce_name, string $action ): bool {
186182 */
187183 public function handle_webhook_save () {
188184 // Verify permissions and nonce
189- if ( ! $ this ->verify_admin_permission () || ! $ this ->verify_nonce ( 'webhook_save ' , 'webhook_nonce ' ) ) {
185+ if ( ! $ this ->verify_admin_permission () || ! $ this ->verify_nonce ( 'webhook_nonce ' , 'webhook_save ' ) ) {
190186 wp_die ( __ ( 'Unauthorized ' , 'wp-graphql-webhooks ' ) );
191187 }
192188
@@ -200,7 +196,7 @@ public function handle_webhook_save() {
200196 ];
201197
202198 // Validate data
203- $ validation = $ this ->repository ->validate_data ( $ data );
199+ $ validation = $ this ->repository ->validate_data ( $ data[ ' event ' ], $ data [ ' url ' ], $ data [ ' method ' ] );
204200 if ( is_wp_error ( $ validation ) ) {
205201 wp_die ( $ validation ->get_error_message () );
206202 }
@@ -231,15 +227,44 @@ public function handle_webhook_delete() {
231227 * Handle admin actions
232228 */
233229 public function handle_admin_actions () {
234- // Handle bulk actions from WP_List_Table
235- if ( isset ( $ _REQUEST ['action ' ] ) && 'delete ' === $ _REQUEST ['action ' ] ||
236- isset ( $ _REQUEST ['action2 ' ] ) && 'delete ' === $ _REQUEST ['action2 ' ] ) {
230+ // Only process on our admin page
231+ if ( ! isset ( $ _GET ['page ' ] ) || self ::ADMIN_PAGE_SLUG !== $ _GET ['page ' ] ) {
232+ return ;
233+ }
234+
235+ // Handle single delete action
236+ if ( isset ( $ _GET ['action ' ] ) && 'delete ' === $ _GET ['action ' ] && isset ( $ _GET ['webhook ' ] ) ) {
237+ if ( ! $ this ->verify_admin_permission () ) {
238+ return ;
239+ }
240+
241+ $ webhook_id = intval ( $ _GET ['webhook ' ] );
242+ $ nonce = isset ( $ _GET ['_wpnonce ' ] ) ? $ _GET ['_wpnonce ' ] : '' ;
243+
244+ if ( ! wp_verify_nonce ( $ nonce , 'delete-webhook- ' . $ webhook_id ) ) {
245+ wp_die ( __ ( 'Security check failed. ' , 'wp-graphql-headless-webhooks ' ) );
246+ }
247+
248+ if ( $ this ->repository ->delete ( $ webhook_id ) ) {
249+ wp_redirect ( add_query_arg ( [ 'deleted ' => 1 ], remove_query_arg ( [ 'action ' , 'webhook ' , '_wpnonce ' ], $ this ->get_admin_url () ) ) );
250+ exit ;
251+ }
252+ }
253+
254+ // Handle bulk delete actions from WP_List_Table
255+ if ( isset ( $ _POST ['action ' ] ) && 'delete ' === $ _POST ['action ' ] ||
256+ isset ( $ _POST ['action2 ' ] ) && 'delete ' === $ _POST ['action2 ' ] ) {
237257
238- if ( ! $ this ->verify_admin_permission () || ! $ this -> verify_nonce ( ' bulk-webhooks ' , ' _wpnonce ' ) ) {
258+ if ( ! $ this ->verify_admin_permission () ) {
239259 return ;
240260 }
241261
242- $ webhook_ids = isset ( $ _REQUEST ['webhook ' ] ) ? array_map ( 'intval ' , (array ) $ _REQUEST ['webhook ' ] ) : [];
262+ // Check bulk action nonce
263+ if ( ! isset ( $ _POST ['_wpnonce ' ] ) || ! wp_verify_nonce ( $ _POST ['_wpnonce ' ], 'bulk-webhooks ' ) ) {
264+ wp_die ( __ ( 'Security check failed. ' , 'wp-graphql-headless-webhooks ' ) );
265+ }
266+
267+ $ webhook_ids = isset ( $ _POST ['webhook ' ] ) ? array_map ( 'intval ' , (array ) $ _POST ['webhook ' ] ) : [];
243268 $ deleted = 0 ;
244269
245270 foreach ( $ webhook_ids as $ webhook_id ) {
@@ -249,7 +274,7 @@ public function handle_admin_actions() {
249274 }
250275
251276 if ( $ deleted > 0 ) {
252- wp_redirect ( add_query_arg ( [ 'deleted ' => $ deleted ], $ this ->get_admin_url () ) );
277+ wp_redirect ( add_query_arg ( [ 'deleted ' => $ deleted ], remove_query_arg ( [ ' action ' , ' action2 ' , ' webhook ' , ' _wpnonce ' ], $ this ->get_admin_url () ) ) );
253278 exit ;
254279 }
255280 }
0 commit comments