Skip to content

Commit 660de70

Browse files
committed
Fix headers
1 parent 9cc8176 commit 660de70

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public function init(): void {
4242
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
4343
add_action( 'admin_init', array( $this, 'handle_actions' ) );
4444
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
45+
46+
// Register admin-post.php handlers
47+
add_action( 'admin_post_graphql_webhook_save', array( $this, 'handle_webhook_save' ) );
4548
}
4649

4750
/**
@@ -103,6 +106,7 @@ public function enqueue_assets( string $hook_suffix ): void {
103106
'restUrl' => rest_url( 'graphql-webhooks/v1/' ),
104107
'nonce' => wp_create_nonce( 'wp_rest' ),
105108
'headerTemplate' => $this->get_header_row_template(),
109+
'confirmDelete' => __( 'Are you sure you want to delete this webhook?', 'wp-graphql-headless-webhooks' ),
106110
)
107111
);
108112
}
@@ -126,12 +130,7 @@ public function handle_actions(): void {
126130
return;
127131
}
128132

129-
if ( isset( $_POST['action'] ) ) {
130-
if ( 'save_webhook' === $_POST['action'] ) {
131-
$this->handle_webhook_save();
132-
}
133-
}
134-
133+
// Only handle delete action here since save is handled by admin-post.php
135134
if ( isset( $_GET['action'] ) && 'delete' === $_GET['action'] ) {
136135
$this->handle_webhook_delete();
137136
}
@@ -168,8 +167,8 @@ private function verify_nonce( string $action, string $nonce_field = '_wpnonce'
168167
/**
169168
* Handle webhook save
170169
*/
171-
private function handle_webhook_save(): void {
172-
if ( ! $this->verify_admin_permission() || ! $this->verify_nonce( 'webhook_save' ) ) {
170+
public function handle_webhook_save(): void {
171+
if ( ! $this->verify_admin_permission() || ! $this->verify_nonce( 'graphql_webhook_save', 'graphql_webhook_nonce' ) ) {
173172
return;
174173
}
175174

@@ -272,13 +271,15 @@ public function render_admin_page(): void {
272271

273272
// Set default values for new webhook
274273
if ( 'add' === $action ) {
274+
$webhook_id = 0;
275275
$name = '';
276276
$event = '';
277277
$url = '';
278278
$method = 'POST';
279279
$headers = array();
280280
} else {
281281
// Extract values from webhook entity
282+
$webhook_id = $webhook->id;
282283
$name = $webhook->name;
283284
$event = $webhook->event;
284285
$url = $webhook->url;

plugins/wp-graphql-headless-webhooks/src/Admin/assets/admin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
$( '#add-header' ).on(
1212
'click',
1313
function () {
14-
var headerRow = $( graphqlWebhooksAdmin.headerRowTemplate );
14+
var headerRow = $( wpGraphQLWebhooks.headerTemplate );
1515
$( '#webhook-headers' ).append( headerRow );
1616
}
1717
);
@@ -37,7 +37,7 @@
3737
$( '.delete-webhook' ).on(
3838
'click',
3939
function (e) {
40-
if ( ! confirm( graphqlWebhooksAdmin.confirmDelete )) {
40+
if ( ! confirm( wpGraphQLWebhooks.confirmDelete )) {
4141
e.preventDefault();
4242
}
4343
}

plugins/wp-graphql-headless-webhooks/src/Admin/views/partials/webhook-header-row.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
$value = isset( $value ) ? $value : '';
1818
?>
1919
<div class="webhook-header-row">
20-
<input type="text" name="webhook_header_key[]" value="<?php echo esc_attr( $key ); ?>" placeholder="<?php esc_attr_e( 'Header name', 'wp-graphql-headless-webhooks' ); ?>" class="regular-text">
21-
<input type="text" name="webhook_header_value[]" value="<?php echo esc_attr( $value ); ?>" placeholder="<?php esc_attr_e( 'Header value', 'wp-graphql-headless-webhooks' ); ?>" class="regular-text">
20+
<input type="text" name="webhook_headers[name][]" value="<?php echo esc_attr( $key ); ?>" placeholder="<?php esc_attr_e( 'Header name', 'wp-graphql-headless-webhooks' ); ?>" class="regular-text">
21+
<input type="text" name="webhook_headers[value][]" value="<?php echo esc_attr( $value ); ?>" placeholder="<?php esc_attr_e( 'Header value', 'wp-graphql-headless-webhooks' ); ?>" class="regular-text">
2222
<button type="button" class="button remove-header"><?php esc_html_e( 'Remove', 'wp-graphql-headless-webhooks' ); ?></button>
2323
</div>

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<?php esc_html_e( 'Add New', 'wp-graphql-headless-webhooks' ); ?>
2121
</a>
2222
<hr class="wp-header-end">
23-
23+
<br>
2424
<?php if ( empty( $webhooks ) ) : ?>
2525
<div class="webhooks-empty-state">
2626
<p><?php esc_html_e( 'No webhooks found. Create your first webhook to get started.', 'wp-graphql-headless-webhooks' ); ?></p>
@@ -36,6 +36,7 @@
3636
<th><?php esc_html_e( 'Event', 'wp-graphql-headless-webhooks' ); ?></th>
3737
<th><?php esc_html_e( 'URL', 'wp-graphql-headless-webhooks' ); ?></th>
3838
<th><?php esc_html_e( 'Method', 'wp-graphql-headless-webhooks' ); ?></th>
39+
<th><?php esc_html_e( 'Headers', 'wp-graphql-headless-webhooks' ); ?></th>
3940
<th><?php esc_html_e( 'Actions', 'wp-graphql-headless-webhooks' ); ?></th>
4041
</tr>
4142
</thead>
@@ -51,6 +52,12 @@
5152
</td>
5253
<td><?php echo esc_html( $webhook->url ); ?></td>
5354
<td><?php echo esc_html( $webhook->method ); ?></td>
55+
<td>
56+
<?php
57+
$header_count = is_array( $webhook->headers ) ? count( $webhook->headers ) : 0;
58+
echo esc_html( $header_count );
59+
?>
60+
</td>
5461
<td>
5562
<a href="
5663
<?php

0 commit comments

Comments
 (0)