Skip to content

Commit 166eae6

Browse files
committed
Add native WordPress filters
1 parent b5044e0 commit 166eae6

File tree

2 files changed

+190
-101
lines changed

2 files changed

+190
-101
lines changed

plugins/wp-graphql-headless-webhooks/src/Admin/WebhooksAdmin.php

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function init(): void {
4545

4646
// Register admin-post.php handlers
4747
add_action( 'admin_post_graphql_webhook_save', array( $this, 'handle_webhook_save' ) );
48+
add_action( 'admin_post_graphql_webhook_bulk_delete', array( $this, 'handle_bulk_delete' ) );
4849

4950
// Register AJAX handlers
5051
add_action( 'wp_ajax_test_webhook', array( $this, 'handle_test_webhook' ) );
@@ -230,6 +231,43 @@ public function handle_webhook_delete(): void {
230231
exit;
231232
}
232233

234+
/**
235+
* Handle bulk delete action
236+
*/
237+
public function handle_bulk_delete(): void {
238+
if ( ! $this->verify_admin_permission() || ! $this->verify_nonce( 'bulk_delete_webhooks' ) ) {
239+
return;
240+
}
241+
242+
$bulk_action = $_POST['bulk_action'] ?? $_POST['bulk_action2'] ?? '';
243+
$webhook_ids = $_POST['webhook_ids'] ?? array();
244+
245+
if ( 'delete' === $bulk_action && ! empty( $webhook_ids ) ) {
246+
$deleted_count = 0;
247+
foreach ( $webhook_ids as $webhook_id ) {
248+
$webhook_id = intval( $webhook_id );
249+
if ( $webhook_id > 0 && $this->repository->delete( $webhook_id ) ) {
250+
$deleted_count++;
251+
}
252+
}
253+
254+
$redirect_args = array();
255+
if ( $deleted_count > 0 ) {
256+
$redirect_args['deleted'] = 'true';
257+
$redirect_args['count'] = $deleted_count;
258+
} else {
259+
$redirect_args['error'] = __( 'Failed to delete webhooks.', 'wp-graphql-headless-webhooks' );
260+
}
261+
262+
wp_safe_redirect( $this->get_admin_url( $redirect_args ) );
263+
exit;
264+
}
265+
266+
// If no valid action, redirect back
267+
wp_safe_redirect( $this->get_admin_url() );
268+
exit;
269+
}
270+
233271
/**
234272
* Handle webhook test via AJAX
235273
*/
@@ -394,8 +432,21 @@ public function render_admin_page(): void {
394432
}
395433

396434
if ( isset( $_GET['deleted'] ) ) {
397-
$message = __( 'Webhook deleted successfully.', 'wp-graphql-headless-webhooks' );
398-
$type = 'success';
435+
$count = isset( $_GET['count'] ) ? intval( $_GET['count'] ) : 1;
436+
if ( $count > 1 ) {
437+
$message = sprintf(
438+
_n(
439+
'%d webhook deleted successfully.',
440+
'%d webhooks deleted successfully.',
441+
$count,
442+
'wp-graphql-headless-webhooks'
443+
),
444+
$count
445+
);
446+
} else {
447+
$message = __( 'Webhook deleted successfully.', 'wp-graphql-headless-webhooks' );
448+
}
449+
$type = 'success';
399450
include __DIR__ . '/views/admin-notice.php';
400451
}
401452

plugins/wp-graphql-headless-webhooks/src/Admin/views/webhooks-list.php

Lines changed: 137 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -54,110 +54,148 @@
5454
<?php endif; ?>
5555

5656
<?php if ( ! empty( $webhooks ) ) : ?>
57-
<table class="wp-list-table widefat fixed striped table-view-list">
58-
<thead>
59-
<tr>
60-
<th scope="col" class="manage-column column-name column-primary">
61-
<?php esc_html_e( 'Name', 'wp-graphql-headless-webhooks' ); ?>
62-
</th>
63-
<th scope="col" class="manage-column column-event">
64-
<?php esc_html_e( 'Event', 'wp-graphql-headless-webhooks' ); ?>
65-
</th>
66-
<th scope="col" class="manage-column column-method">
67-
<?php esc_html_e( 'Method', 'wp-graphql-headless-webhooks' ); ?>
68-
</th>
69-
<th scope="col" class="manage-column column-url">
70-
<?php esc_html_e( 'URL', 'wp-graphql-headless-webhooks' ); ?>
71-
</th>
72-
<th scope="col" class="manage-column column-headers">
73-
<?php esc_html_e( 'Headers', 'wp-graphql-headless-webhooks' ); ?>
74-
</th>
75-
</tr>
76-
</thead>
77-
<tbody>
78-
<?php foreach ( $webhooks as $webhook ) : ?>
57+
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
58+
<?php wp_nonce_field( 'bulk_delete_webhooks' ); ?>
59+
<input type="hidden" name="action" value="graphql_webhook_bulk_delete">
60+
61+
<div class="tablenav top">
62+
<div class="alignleft actions bulkactions">
63+
<label for="bulk-action-selector-top" class="screen-reader-text"><?php esc_html_e( 'Select bulk action', 'wp-graphql-headless-webhooks' ); ?></label>
64+
<select name="bulk_action" id="bulk-action-selector-top">
65+
<option value=""><?php esc_html_e( 'Bulk actions', 'wp-graphql-headless-webhooks' ); ?></option>
66+
<option value="delete"><?php esc_html_e( 'Delete', 'wp-graphql-headless-webhooks' ); ?></option>
67+
</select>
68+
<input type="submit" class="button action" value="<?php esc_attr_e( 'Apply', 'wp-graphql-headless-webhooks' ); ?>">
69+
</div>
70+
</div>
71+
72+
<table class="wp-list-table widefat fixed striped table-view-list">
73+
<thead>
7974
<tr>
80-
<td class="column-name column-primary" data-colname="<?php esc_attr_e( 'Name', 'wp-graphql-headless-webhooks' ); ?>">
81-
<strong>
82-
<a href="<?php echo esc_url( $admin->get_admin_url( array( 'action' => 'edit', 'webhook_id' => $webhook->id ) ) ); ?>" class="row-title">
83-
<?php echo esc_html( $webhook->name ); ?>
84-
</a>
85-
</strong>
86-
<div class="row-actions">
87-
<span class="edit">
88-
<a href="<?php echo esc_url( $admin->get_admin_url( array( 'action' => 'edit', 'webhook_id' => $webhook->id ) ) ); ?>">
89-
<?php esc_html_e( 'Edit', 'wp-graphql-headless-webhooks' ); ?>
90-
</a> |
91-
</span>
92-
<span class="test">
93-
<a href="#" class="test-webhook" data-webhook-id="<?php echo esc_attr( $webhook->id ); ?>">
94-
<?php esc_html_e( 'Test', 'wp-graphql-headless-webhooks' ); ?>
95-
</a> |
96-
</span>
97-
<span class="trash">
98-
<a href="<?php echo esc_url( wp_nonce_url( $admin->get_admin_url( array( 'action' => 'delete', 'webhook_id' => $webhook->id ) ), 'delete_webhook_' . $webhook->id ) ); ?>" class="delete-webhook submitdelete">
99-
<?php esc_html_e( 'Delete', 'wp-graphql-headless-webhooks' ); ?>
100-
</a>
101-
</span>
102-
</div>
103-
<button type="button" class="toggle-row">
104-
<span class="screen-reader-text"><?php esc_html_e( 'Show more details', 'wp-graphql-headless-webhooks' ); ?></span>
105-
</button>
106-
</td>
107-
<td class="column-event" data-colname="<?php esc_attr_e( 'Event', 'wp-graphql-headless-webhooks' ); ?>">
108-
<code><?php echo esc_html( $webhook->event ); ?></code>
109-
</td>
110-
<td class="column-method" data-colname="<?php esc_attr_e( 'Method', 'wp-graphql-headless-webhooks' ); ?>">
111-
<strong><?php echo esc_html( strtoupper( $webhook->method ) ); ?></strong>
112-
</td>
113-
<td class="column-url" data-colname="<?php esc_attr_e( 'URL', 'wp-graphql-headless-webhooks' ); ?>">
114-
<code><?php echo esc_html( $webhook->url ); ?></code>
75+
<td class="manage-column column-cb check-column">
76+
<label class="screen-reader-text" for="cb-select-all-1"><?php esc_html_e( 'Select All', 'wp-graphql-headless-webhooks' ); ?></label>
77+
<input id="cb-select-all-1" type="checkbox">
11578
</td>
116-
<td class="column-headers" data-colname="<?php esc_attr_e( 'Headers', 'wp-graphql-headless-webhooks' ); ?>">
117-
<?php if ( ! empty( $webhook->headers ) ) : ?>
118-
<?php foreach ( $webhook->headers as $key => $value ) : ?>
119-
<div><code><?php echo esc_html( $key ); ?></code></div>
120-
<?php endforeach; ?>
121-
<?php else : ?>
122-
<span class="description"><?php esc_html_e( 'None', 'wp-graphql-headless-webhooks' ); ?></span>
123-
<?php endif; ?>
79+
<th scope="col" class="manage-column column-name column-primary">
80+
<?php esc_html_e( 'Name', 'wp-graphql-headless-webhooks' ); ?>
81+
</th>
82+
<th scope="col" class="manage-column column-event">
83+
<?php esc_html_e( 'Event', 'wp-graphql-headless-webhooks' ); ?>
84+
</th>
85+
<th scope="col" class="manage-column column-method">
86+
<?php esc_html_e( 'Method', 'wp-graphql-headless-webhooks' ); ?>
87+
</th>
88+
<th scope="col" class="manage-column column-url">
89+
<?php esc_html_e( 'URL', 'wp-graphql-headless-webhooks' ); ?>
90+
</th>
91+
<th scope="col" class="manage-column column-headers">
92+
<?php esc_html_e( 'Headers', 'wp-graphql-headless-webhooks' ); ?>
93+
</th>
94+
</tr>
95+
</thead>
96+
<tbody>
97+
<?php foreach ( $webhooks as $webhook ) : ?>
98+
<tr>
99+
<th scope="row" class="check-column">
100+
<label class="screen-reader-text" for="cb-select-<?php echo esc_attr( $webhook->id ); ?>">
101+
<?php printf( esc_html__( 'Select %s', 'wp-graphql-headless-webhooks' ), esc_html( $webhook->name ) ); ?>
102+
</label>
103+
<input id="cb-select-<?php echo esc_attr( $webhook->id ); ?>" type="checkbox" name="webhook_ids[]" value="<?php echo esc_attr( $webhook->id ); ?>">
104+
</th>
105+
<td class="column-name column-primary" data-colname="<?php esc_attr_e( 'Name', 'wp-graphql-headless-webhooks' ); ?>">
106+
<strong>
107+
<a href="<?php echo esc_url( $admin->get_admin_url( array( 'action' => 'edit', 'webhook_id' => $webhook->id ) ) ); ?>" class="row-title">
108+
<?php echo esc_html( $webhook->name ); ?>
109+
</a>
110+
</strong>
111+
<div class="row-actions">
112+
<span class="edit">
113+
<a href="<?php echo esc_url( $admin->get_admin_url( array( 'action' => 'edit', 'webhook_id' => $webhook->id ) ) ); ?>">
114+
<?php esc_html_e( 'Edit', 'wp-graphql-headless-webhooks' ); ?>
115+
</a> |
116+
</span>
117+
<span class="test">
118+
<a href="#" class="test-webhook" data-webhook-id="<?php echo esc_attr( $webhook->id ); ?>">
119+
<?php esc_html_e( 'Test', 'wp-graphql-headless-webhooks' ); ?>
120+
</a> |
121+
</span>
122+
<span class="trash">
123+
<a href="<?php echo esc_url( wp_nonce_url( $admin->get_admin_url( array( 'action' => 'delete', 'webhook_id' => $webhook->id ) ), 'delete_webhook_' . $webhook->id ) ); ?>" class="delete-webhook submitdelete">
124+
<?php esc_html_e( 'Delete', 'wp-graphql-headless-webhooks' ); ?>
125+
</a>
126+
</span>
127+
</div>
128+
<button type="button" class="toggle-row">
129+
<span class="screen-reader-text"><?php esc_html_e( 'Show more details', 'wp-graphql-headless-webhooks' ); ?></span>
130+
</button>
131+
</td>
132+
<td class="column-event" data-colname="<?php esc_attr_e( 'Event', 'wp-graphql-headless-webhooks' ); ?>">
133+
<code><?php echo esc_html( $webhook->event ); ?></code>
134+
</td>
135+
<td class="column-method" data-colname="<?php esc_attr_e( 'Method', 'wp-graphql-headless-webhooks' ); ?>">
136+
<strong><?php echo esc_html( strtoupper( $webhook->method ) ); ?></strong>
137+
</td>
138+
<td class="column-url" data-colname="<?php esc_attr_e( 'URL', 'wp-graphql-headless-webhooks' ); ?>">
139+
<code><?php echo esc_html( $webhook->url ); ?></code>
140+
</td>
141+
<td class="column-headers" data-colname="<?php esc_attr_e( 'Headers', 'wp-graphql-headless-webhooks' ); ?>">
142+
<?php if ( ! empty( $webhook->headers ) ) : ?>
143+
<?php foreach ( $webhook->headers as $key => $value ) : ?>
144+
<div><code><?php echo esc_html( $key ); ?></code></div>
145+
<?php endforeach; ?>
146+
<?php else : ?>
147+
<span class="description"><?php esc_html_e( 'None', 'wp-graphql-headless-webhooks' ); ?></span>
148+
<?php endif; ?>
149+
</td>
150+
</tr>
151+
<?php endforeach; ?>
152+
</tbody>
153+
<tfoot>
154+
<tr>
155+
<td class="manage-column column-cb check-column">
156+
<label class="screen-reader-text" for="cb-select-all-2"><?php esc_html_e( 'Select All', 'wp-graphql-headless-webhooks' ); ?></label>
157+
<input id="cb-select-all-2" type="checkbox">
124158
</td>
159+
<th scope="col" class="manage-column column-name column-primary">
160+
<?php esc_html_e( 'Name', 'wp-graphql-headless-webhooks' ); ?>
161+
</th>
162+
<th scope="col" class="manage-column column-event">
163+
<?php esc_html_e( 'Event', 'wp-graphql-headless-webhooks' ); ?>
164+
</th>
165+
<th scope="col" class="manage-column column-method">
166+
<?php esc_html_e( 'Method', 'wp-graphql-headless-webhooks' ); ?>
167+
</th>
168+
<th scope="col" class="manage-column column-url">
169+
<?php esc_html_e( 'URL', 'wp-graphql-headless-webhooks' ); ?>
170+
</th>
171+
<th scope="col" class="manage-column column-headers">
172+
<?php esc_html_e( 'Headers', 'wp-graphql-headless-webhooks' ); ?>
173+
</th>
125174
</tr>
126-
<?php endforeach; ?>
127-
</tbody>
128-
<tfoot>
129-
<tr>
130-
<th scope="col" class="manage-column column-name column-primary">
131-
<?php esc_html_e( 'Name', 'wp-graphql-headless-webhooks' ); ?>
132-
</th>
133-
<th scope="col" class="manage-column column-event">
134-
<?php esc_html_e( 'Event', 'wp-graphql-headless-webhooks' ); ?>
135-
</th>
136-
<th scope="col" class="manage-column column-method">
137-
<?php esc_html_e( 'Method', 'wp-graphql-headless-webhooks' ); ?>
138-
</th>
139-
<th scope="col" class="manage-column column-url">
140-
<?php esc_html_e( 'URL', 'wp-graphql-headless-webhooks' ); ?>
141-
</th>
142-
<th scope="col" class="manage-column column-headers">
143-
<?php esc_html_e( 'Headers', 'wp-graphql-headless-webhooks' ); ?>
144-
</th>
145-
</tr>
146-
</tfoot>
147-
</table>
148-
149-
<div class="tablenav bottom">
150-
<div class="alignleft actions">
151-
<p class="description">
152-
<?php
153-
printf(
154-
esc_html__( '%d webhooks configured', 'wp-graphql-headless-webhooks' ),
155-
count( $webhooks )
156-
);
157-
?>
158-
</p>
175+
</tfoot>
176+
</table>
177+
178+
<div class="tablenav bottom">
179+
<div class="alignleft actions bulkactions">
180+
<label for="bulk-action-selector-bottom" class="screen-reader-text"><?php esc_html_e( 'Select bulk action', 'wp-graphql-headless-webhooks' ); ?></label>
181+
<select name="bulk_action2" id="bulk-action-selector-bottom">
182+
<option value=""><?php esc_html_e( 'Bulk actions', 'wp-graphql-headless-webhooks' ); ?></option>
183+
<option value="delete"><?php esc_html_e( 'Delete', 'wp-graphql-headless-webhooks' ); ?></option>
184+
</select>
185+
<input type="submit" class="button action" value="<?php esc_attr_e( 'Apply', 'wp-graphql-headless-webhooks' ); ?>">
186+
</div>
187+
<div class="alignleft actions">
188+
<p class="description">
189+
<?php
190+
printf(
191+
esc_html__( '%d webhooks configured', 'wp-graphql-headless-webhooks' ),
192+
count( $webhooks )
193+
);
194+
?>
195+
</p>
196+
</div>
159197
</div>
160-
</div>
198+
</form>
161199
<?php else : ?>
162200
<div class="webhooks-empty-state">
163201
<p><?php esc_html_e( 'No webhooks configured yet.', 'wp-graphql-headless-webhooks' ); ?></p>

0 commit comments

Comments
 (0)