Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/wpgraphql-webhooks/.phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="graphql-webhooks"/>
<element value="wpgraphql-webhooks"/>
</property>
</properties>
</rule>
Expand Down
339 changes: 339 additions & 0 deletions plugins/wpgraphql-webhooks/LICENSE

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions plugins/wpgraphql-webhooks/activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

declare( strict_types = 1 );

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Runs when the plugin is activated.
*
Expand Down
2 changes: 1 addition & 1 deletion plugins/wpgraphql-webhooks/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wpengine/wpgraphql-webhooks",
"description": "Headless webhooks for WPGraphQL",
"type": "library",
"license": "GPL-2.0",
"license": "GPL-2.0-or-later",
"version": "0.0.7",
"authors": [
{
Expand Down
4 changes: 4 additions & 0 deletions plugins/wpgraphql-webhooks/deactivation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
* @package WPGraphql\Webhooks
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Runs when WPGraphQL Webhooks is de-activated.
*
Expand Down
4 changes: 2 additions & 2 deletions plugins/wpgraphql-webhooks/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Tested up to: 6.9
Requires PHP: 7.4
Requires WPGraphQL: 1.8.0
Stable tag: 0.0.7
License: GPL-3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

== Description ==
== Upgrade Notice ==
Expand Down
41 changes: 21 additions & 20 deletions plugins/wpgraphql-webhooks/src/Admin/WebhooksAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public function init(): void {
public function add_admin_menu(): void {
// Add submenu under GraphQL menu using the correct parent slug
add_menu_page(
__( 'Webhooks', 'graphql-webhooks' ),
__( 'Webhooks', 'graphql-webhooks' ),
__( 'Webhooks', 'wpgraphql-webhooks' ),
__( 'Webhooks', 'wpgraphql-webhooks' ),
'manage_options',
self::ADMIN_PAGE_SLUG,
[ $this, 'render_admin_page' ],
Expand All @@ -73,8 +73,8 @@ public function add_admin_menu(): void {
);
add_submenu_page(
'graphiql-ide',
__( 'GraphQL Webhooks', 'graphql-webhooks' ),
__( 'Webhooks', 'graphql-webhooks' ),
__( 'GraphQL Webhooks', 'wpgraphql-webhooks' ),
__( 'Webhooks', 'wpgraphql-webhooks' ),
'manage_options',
self::ADMIN_PAGE_SLUG,
[ $this, 'render_admin_page' ]
Expand Down Expand Up @@ -129,7 +129,7 @@ public function enqueue_assets( string $hook ): void {
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'restUrl' => rest_url( 'graphql-webhooks/v1/' ),
'nonce' => wp_create_nonce( 'wp_rest' ),
'confirmDelete' => __( 'Are you sure you want to delete this webhook?', 'graphql-webhooks' ),
'confirmDelete' => __( 'Are you sure you want to delete this webhook?', 'wpgraphql-webhooks' ),
'headerTemplate' => $this->get_header_row_template(),
]
);
Expand All @@ -154,7 +154,7 @@ private function get_header_row_template(): string {
*/
private function verify_admin_permission(): bool {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.', 'graphql-webhooks' ) );
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'wpgraphql-webhooks' ) );
return false;
}
return true;
Expand All @@ -169,7 +169,7 @@ private function verify_admin_permission(): bool {
*/
private function verify_nonce( string $nonce_name, string $action ): bool {
if ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( wp_unslash( $_REQUEST[ $nonce_name ] ), $action ) ) {
wp_die( __( 'Security check failed.', 'graphql-webhooks' ) );
wp_die( esc_html__( 'Security check failed.', 'wpgraphql-webhooks' ) );
return false;
}
return true;
Expand All @@ -182,7 +182,7 @@ private function verify_nonce( string $nonce_name, string $action ): bool {
*/
public function handle_webhook_save() {
if ( ! $this->verify_admin_permission() || ! $this->verify_nonce( 'webhook_nonce', 'webhook_save' ) ) {
wp_die( __( 'Unauthorized', 'graphql-webhooks' ) );
wp_die( esc_html__( 'Unauthorized', 'wpgraphql-webhooks' ) );
}

$webhook_id = isset( $_POST['webhook_id'] ) ? intval( $_POST['webhook_id'] ) : 0;
Expand All @@ -197,7 +197,7 @@ public function handle_webhook_save() {

$validation = $this->repository->validate( $webhook );
if ( is_wp_error( $validation ) ) {
wp_die( $validation->get_error_message() );
wp_die( esc_html( $validation->get_error_message() ) );
}

if ( $webhook_id > 0 ) {
Expand Down Expand Up @@ -251,7 +251,7 @@ private function handle_webhook_delete(): void {

// Verify nonce
if ( ! wp_verify_nonce( $nonce, 'delete-webhook-' . $webhook_id ) ) {
wp_die( __( 'Security check failed.', 'graphql-webhooks' ) );
wp_die( esc_html__( 'Security check failed.', 'wpgraphql-webhooks' ) );
}

// Delete webhook
Expand Down Expand Up @@ -300,8 +300,8 @@ private function render_list_page() {
*/
private function render_form_page( $action ) {
$webhook = null;
$form_title = 'add' === $action ? __( 'Add New Webhook', 'graphql-webhooks' ) : __( 'Edit Webhook', 'graphql-webhooks' );
$submit_text = 'add' === $action ? __( 'Add Webhook', 'graphql-webhooks' ) : __( 'Update Webhook', 'graphql-webhooks' );
$form_title = 'add' === $action ? __( 'Add New Webhook', 'wpgraphql-webhooks' ) : __( 'Edit Webhook', 'wpgraphql-webhooks' );
$submit_text = 'add' === $action ? __( 'Add Webhook', 'wpgraphql-webhooks' ) : __( 'Update Webhook', 'wpgraphql-webhooks' );

$name = '';
$event = '';
Expand All @@ -314,7 +314,7 @@ private function render_form_page( $action ) {
$webhook = $this->repository->get( $webhook_id );

if ( ! $webhook ) {
wp_die( __( 'Webhook not found.', 'graphql-webhooks' ) );
wp_die( esc_html__( 'Webhook not found.', 'wpgraphql-webhooks' ) );
}

$name = $webhook->name;
Expand Down Expand Up @@ -365,30 +365,30 @@ private function sanitize_headers( array $headers ): array {
public function ajax_test_webhook(): void {
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'wp_rest' ) ) {
wp_send_json_error( [
'message' => __( 'Invalid security token.', 'graphql-webhooks' ),
'message' => __( 'Invalid security token.', 'wpgraphql-webhooks' ),
'error_code' => 'invalid_nonce'
] );
}

if ( ! $this->verify_admin_permission() ) {
wp_send_json_error( [
'message' => __( 'You do not have permission to test webhooks.', 'graphql-webhooks' ),
'message' => __( 'You do not have permission to test webhooks.', 'wpgraphql-webhooks' ),
'error_code' => 'insufficient_permissions'
] );
}

$webhook_id = isset( $_POST['webhook_id'] ) ? intval( $_POST['webhook_id'] ) : 0;
if ( ! $webhook_id ) {
wp_send_json_error( [
'message' => __( 'Invalid webhook ID.', 'graphql-webhooks' ),
'message' => __( 'Invalid webhook ID.', 'wpgraphql-webhooks' ),
'error_code' => 'invalid_webhook_id'
] );
}

$webhook = $this->repository->get( $webhook_id );
if ( ! $webhook ) {
wp_send_json_error( [
'message' => __( 'Webhook not found.', 'graphql-webhooks' ),
'message' => __( 'Webhook not found.', 'wpgraphql-webhooks' ),
'error_code' => 'webhook_not_found'
] );
}
Expand Down Expand Up @@ -434,7 +434,8 @@ public function ajax_test_webhook(): void {
if ( is_wp_error( $response ) ) {
wp_send_json_error( [
'message' => sprintf(
__( 'Failed to send test webhook: %s', 'graphql-webhooks' ),
/* translators: %s: error message from the failed request */
__( 'Failed to send test webhook: %s', 'wpgraphql-webhooks' ),
$response->get_error_message()
),
'error_code' => $response->get_error_code(),
Expand All @@ -450,8 +451,8 @@ public function ajax_test_webhook(): void {
$response_data = [
'success' => $is_success,
'message' => $is_success
? sprintf( __( 'Test webhook sent successfully to %s', 'graphql-webhooks' ), $webhook->url )
: sprintf( __( 'Webhook returned HTTP %d', 'graphql-webhooks' ), $response_code ),
? sprintf( /* translators: %s: webhook URL */ __( 'Test webhook sent successfully to %s', 'wpgraphql-webhooks' ), $webhook->url )
: sprintf( /* translators: %d: HTTP status code */ __( 'Webhook returned HTTP %d', 'wpgraphql-webhooks' ), $response_code ),
'webhook_id' => $webhook->id,
'webhook_name' => $webhook->name,
'target_url' => $webhook->url,
Expand Down
34 changes: 19 additions & 15 deletions plugins/wpgraphql-webhooks/src/Admin/WebhooksListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

use WPGraphQL\Webhooks\Repository\WebhookRepository;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

// Include the WP_List_Table class if not already loaded
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
Expand All @@ -35,8 +39,8 @@ public function __construct( WebhookRepository $repository ) {
$this->repository = $repository;

parent::__construct( [
'singular' => __( 'Webhook', 'graphql-webhooks' ),
'plural' => __( 'Webhooks', 'graphql-webhooks' ),
'singular' => __( 'Webhook', 'wpgraphql-webhooks' ),
'plural' => __( 'Webhooks', 'wpgraphql-webhooks' ),
'ajax' => false,
] );
}
Expand All @@ -49,11 +53,11 @@ public function __construct( WebhookRepository $repository ) {
public function get_columns() {
return [
'cb' => '<input type="checkbox" />',
'name' => __( 'Name', 'graphql-webhooks' ),
'event' => __( 'Event', 'graphql-webhooks' ),
'method' => __( 'Method', 'graphql-webhooks' ),
'url' => __( 'URL', 'graphql-webhooks' ),
'headers' => __( 'Headers', 'graphql-webhooks' ),
'name' => __( 'Name', 'wpgraphql-webhooks' ),
'event' => __( 'Event', 'wpgraphql-webhooks' ),
'method' => __( 'Method', 'wpgraphql-webhooks' ),
'url' => __( 'URL', 'wpgraphql-webhooks' ),
'headers' => __( 'Headers', 'wpgraphql-webhooks' ),
];
}

Expand All @@ -77,7 +81,7 @@ public function get_sortable_columns() {
*/
public function get_bulk_actions() {
return [
'delete' => __( 'Delete', 'graphql-webhooks' ),
'delete' => __( 'Delete', 'wpgraphql-webhooks' ),
];
}

Expand All @@ -93,12 +97,12 @@ public function process_bulk_action() {

// Verify nonce
if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ), 'bulk-' . $this->_args['plural'] ) ) {
wp_die( esc_html__( 'Security check failed.', 'graphql-webhooks' ) );
wp_die( esc_html__( 'Security check failed.', 'wpgraphql-webhooks' ) );
}

// Check permissions
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'graphql-webhooks' ) );
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'wpgraphql-webhooks' ) );
}

// Get selected webhooks
Expand Down Expand Up @@ -194,7 +198,7 @@ public function column_default( $item, $column_name ) {
return '<span class="webhook-method">' . esc_html( $item->method ) . '</span>';
case 'headers':
$count = is_array( $item->headers ) ? count( $item->headers ) : 0;
return $count > 0 ? sprintf( __( '%d headers', 'graphql-webhooks' ), $count ) : '—';
return $count > 0 ? sprintf( /* translators: %d: number of headers */ _n( '%d header', '%d headers', $count, 'wpgraphql-webhooks' ), $count ) : '—';
default:
return '';
}
Expand Down Expand Up @@ -236,9 +240,9 @@ public function column_name( $item ) {
);

$actions = [
'edit' => sprintf( '<a href="%s">%s</a>', esc_url( $edit_url ), __( 'Edit', 'graphql-webhooks' ) ),
'test' => sprintf( '<a href="#" class="test-webhook" data-webhook-id="%d">%s</a>', $item->id, __( 'Test', 'graphql-webhooks' ) ),
'delete' => sprintf( '<a href="%s" class="submitdelete">%s</a>', esc_url( $delete_url ), __( 'Delete', 'graphql-webhooks' ) ),
'edit' => sprintf( '<a href="%s">%s</a>', esc_url( $edit_url ), __( 'Edit', 'wpgraphql-webhooks' ) ),
'test' => sprintf( '<a href="#" class="test-webhook" data-webhook-id="%d">%s</a>', $item->id, __( 'Test', 'wpgraphql-webhooks' ) ),
'delete' => sprintf( '<a href="%s" class="submitdelete">%s</a>', esc_url( $delete_url ), __( 'Delete', 'wpgraphql-webhooks' ) ),
];

return sprintf(
Expand All @@ -253,7 +257,7 @@ public function column_name( $item ) {
* Display when no items
*/
public function no_items() {
esc_html_e( 'No webhooks found.', 'graphql-webhooks' );
esc_html_e( 'No webhooks found.', 'wpgraphql-webhooks' );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
<input type="text"
name="webhook_headers[name][]"
value="<?php echo esc_attr( $header_name ); ?>"
placeholder="<?php esc_attr_e( 'Header Name', 'graphql-webhooks' ); ?>"
placeholder="<?php esc_attr_e( 'Header Name', 'wpgraphql-webhooks' ); ?>"
class="regular-text">
<input type="text"
name="webhook_headers[value][]"
value="<?php echo esc_attr( $header_value ); ?>"
placeholder="<?php esc_attr_e( 'Header Value', 'graphql-webhooks' ); ?>"
placeholder="<?php esc_attr_e( 'Header Value', 'wpgraphql-webhooks' ); ?>"
class="regular-text">
<button type="button" class="button remove-header">
<?php esc_html_e( 'Remove', 'graphql-webhooks' ); ?>
<?php esc_html_e( 'Remove', 'wpgraphql-webhooks' ); ?>
</button>
</div>
24 changes: 12 additions & 12 deletions plugins/wpgraphql-webhooks/src/Admin/views/webhook-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,44 +39,44 @@
<tbody>
<tr>
<th scope="row">
<label for="webhook_name"><?php esc_html_e( 'Name', 'graphql-webhooks' ); ?></label>
<label for="webhook_name"><?php esc_html_e( 'Name', 'wpgraphql-webhooks' ); ?></label>
</th>
<td>
<input type="text" id="webhook_name" name="webhook_name" value="<?php echo esc_attr( $name ); ?>" class="regular-text" required>
<p class="description"><?php esc_html_e( 'A descriptive name for this webhook (e.g., "Notify Slack on Post Publish")', 'graphql-webhooks' ); ?></p>
<p class="description"><?php esc_html_e( 'A descriptive name for this webhook (e.g., "Notify Slack on Post Publish")', 'wpgraphql-webhooks' ); ?></p>
</td>
</tr>

<tr>
<th scope="row">
<label for="webhook_event"><?php esc_html_e( 'Event', 'graphql-webhooks' ); ?></label>
<label for="webhook_event"><?php esc_html_e( 'Event', 'wpgraphql-webhooks' ); ?></label>
</th>
<td>
<select id="webhook_event" name="webhook_event" required>
<option value=""><?php esc_html_e( '— Select Event —', 'graphql-webhooks' ); ?></option>
<option value=""><?php esc_html_e( '— Select Event —', 'wpgraphql-webhooks' ); ?></option>
<?php foreach ( $events as $event_key => $event_label ) : ?>
<option value="<?php echo esc_attr( $event_key ); ?>" <?php selected( $event, $event_key ); ?>>
<?php echo esc_html( $event_label ); ?>
</option>
<?php endforeach; ?>
</select>
<p class="description"><?php esc_html_e( 'Choose which WordPress event will trigger this webhook', 'graphql-webhooks' ); ?></p>
<p class="description"><?php esc_html_e( 'Choose which WordPress event will trigger this webhook', 'wpgraphql-webhooks' ); ?></p>
</td>
</tr>

<tr>
<th scope="row">
<label for="webhook_url"><?php esc_html_e( 'URL', 'graphql-webhooks' ); ?></label>
<label for="webhook_url"><?php esc_html_e( 'URL', 'wpgraphql-webhooks' ); ?></label>
</th>
<td>
<input type="url" id="webhook_url" name="webhook_url" value="<?php echo esc_attr( $url ); ?>" class="large-text" required>
<p class="description"><?php esc_html_e( 'The endpoint URL where the webhook payload will be sent', 'graphql-webhooks' ); ?></p>
<p class="description"><?php esc_html_e( 'The endpoint URL where the webhook payload will be sent', 'wpgraphql-webhooks' ); ?></p>
</td>
</tr>

<tr>
<th scope="row">
<label for="webhook_method"><?php esc_html_e( 'HTTP Method', 'graphql-webhooks' ); ?></label>
<label for="webhook_method"><?php esc_html_e( 'HTTP Method', 'wpgraphql-webhooks' ); ?></label>
</th>
<td>
<select id="webhook_method" name="webhook_method" required>
Expand All @@ -91,7 +91,7 @@

<tr>
<th scope="row">
<?php esc_html_e( 'Headers', 'graphql-webhooks' ); ?>
<?php esc_html_e( 'Headers', 'wpgraphql-webhooks' ); ?>
</th>
<td>
<div class="webhook-headers">
Expand All @@ -105,9 +105,9 @@
?>
</div>
<button type="button" class="button" id="add-header">
<?php esc_html_e( 'Add Header', 'graphql-webhooks' ); ?>
<?php esc_html_e( 'Add Header', 'wpgraphql-webhooks' ); ?>
</button>
<p class="description"><?php esc_html_e( 'Optional HTTP headers to send with the webhook request', 'graphql-webhooks' ); ?></p>
<p class="description"><?php esc_html_e( 'Optional HTTP headers to send with the webhook request', 'wpgraphql-webhooks' ); ?></p>
</div>
</td>
</tr>
Expand All @@ -117,7 +117,7 @@
<p class="submit">
<input type="submit" name="submit" id="submit" class="button button-primary" value="<?php echo esc_attr( $submit_text ); ?>">
<a href="<?php echo esc_url( $admin->get_admin_url() ); ?>" class="button">
<?php esc_html_e( 'Cancel', 'graphql-webhooks' ); ?>
<?php esc_html_e( 'Cancel', 'wpgraphql-webhooks' ); ?>
</a>
</p>
</form>
Expand Down
Loading
Loading