@@ -44,8 +44,7 @@ public function __construct( WebhookRepositoryInterface $repository ) {
4444
4545 add_action ( 'admin_menu ' , [ $ this , 'add_admin_menu ' ] );
4646 add_action ( 'admin_enqueue_scripts ' , [ $ this , 'enqueue_assets ' ] );
47- add_action ( 'admin_post_graphql_webhook_save ' , [ $ this , 'handle_webhook_save ' ] );
48- add_action ( 'admin_init ' , [ $ this , 'handle_delete_actions ' ] );
47+ add_action ( 'admin_init ' , [ $ this , 'handle_actions ' ] );
4948 add_action ( 'wp_ajax_test_webhook ' , [ $ this , 'ajax_test_webhook ' ] );
5049 }
5150
@@ -204,39 +203,50 @@ public function handle_webhook_save() {
204203 }
205204
206205 /**
207- * Handles webhook delete actions (both single and bulk).
208- * Consolidates delete logic in one place for easier maintenance.
206+ * Handles admin actions from the webhooks page.
209207 *
210208 * @return void
211209 */
212- public function handle_delete_actions () {
213- // Only process on our admin page
210+ public function handle_actions (): void {
214211 if ( ! isset ( $ _REQUEST ['page ' ] ) || self ::ADMIN_PAGE_SLUG !== $ _REQUEST ['page ' ] ) {
215212 return ;
216213 }
217214
218- // Check if this is a delete action
219- $ is_single_delete = isset ( $ _GET ['action ' ] ) && 'delete ' === $ _GET ['action ' ] && isset ( $ _GET ['webhook ' ] );
220-
221- if ( ! $ is_single_delete ) {
222- return ;
215+ // Handle save action
216+ if ( isset ( $ _POST ['action ' ] ) && 'save_webhook ' === $ _POST ['action ' ] ) {
217+ $ this ->handle_webhook_save ();
223218 }
224219
225- // Verify permissions once
220+ // Handle delete action
221+ if ( isset ( $ _GET ['action ' ] ) && 'delete ' === $ _GET ['action ' ] && isset ( $ _GET ['webhook ' ] ) ) {
222+ $ this ->handle_webhook_delete ();
223+ }
224+ }
225+
226+ /**
227+ * Handles single webhook deletion.
228+ *
229+ * @return void
230+ */
231+ private function handle_webhook_delete (): void {
232+ // Verify permissions
226233 if ( ! $ this ->verify_admin_permission () ) {
227234 return ;
228235 }
229236
230- // Single delete
237+ // Get webhook ID
231238 $ webhook_id = intval ( $ _GET ['webhook ' ] );
232239 $ nonce = isset ( $ _GET ['_wpnonce ' ] ) ? $ _GET ['_wpnonce ' ] : '' ;
233240
241+ // Verify nonce
234242 if ( ! wp_verify_nonce ( $ nonce , 'delete-webhook- ' . $ webhook_id ) ) {
235243 wp_die ( __ ( 'Security check failed. ' , 'wp-graphql-headless-webhooks ' ) );
236244 }
237245
238- // Delete and redirect
246+ // Delete webhook
239247 $ deleted = $ this ->repository ->delete ( $ webhook_id ) ? 1 : 0 ;
248+
249+ // Redirect with result
240250 wp_redirect ( add_query_arg ( [ 'deleted ' => $ deleted ], remove_query_arg ( [ 'action ' , 'webhook ' , '_wpnonce ' ], $ this ->get_admin_url () ) ) );
241251 exit ;
242252 }
0 commit comments