1111 */
1212class WebhookHandler implements Handler {
1313
14- /**
15- * Handle the event payload for a specific webhook.
16- *
17- * @param Webhook $webhook The Webhook entity instance.
18- * @param array $payload The event payload data.
19- *
20- * @return void
21- */
22- public function handle ( Webhook $ webhook , array $ payload ): void {
23- $ args = [
24- 'headers ' => $ webhook ->headers ?: [ 'Content-Type ' => 'application/json ' ],
25- 'timeout ' => 5 ,
26- 'blocking ' => false ,
27- ];
28-
29- if ( strtoupper ( $ webhook ->method ) === 'GET ' ) {
30- $ url = add_query_arg ( $ payload , $ webhook ->url );
31- $ args ['method ' ] = 'GET ' ;
32- } else {
33- $ url = $ webhook ->url ;
34- $ args ['method ' ] = 'POST ' ;
35- $ args ['body ' ] = wp_json_encode ( $ payload );
36- if ( empty ( $ args ['headers ' ]['Content-Type ' ] ) ) {
37- $ args ['headers ' ]['Content-Type ' ] = 'application/json ' ;
38- }
39- }
40-
41- /**
42- * Filter the payload before sending.
43- */
14+ /**
15+ * Handle the event payload for a specific webhook.
16+ *
17+ * @param Webhook $webhook The Webhook entity instance.
18+ * @param array $payload The event payload data.
19+ *
20+ * @return void
21+ */
22+ public function handle ( Webhook $ webhook , array $ payload ): void {
23+ $ args = [
24+ 'headers ' => $ webhook ->headers ?: [ 'Content-Type ' => 'application/json ' ],
25+ 'timeout ' => 5 ,
26+ 'blocking ' => false ,
27+ ];
4428 $ payload = apply_filters ( 'graphql_webhooks_payload ' , $ payload , $ webhook );
45- wp_remote_request ( $ url , $ args );
46- do_action ( 'graphql_webhooks_sent ' , $ webhook , $ payload );
47- }
29+
30+ if ( strtoupper ( $ webhook ->method ) === 'GET ' ) {
31+ $ url = add_query_arg ( $ payload , $ webhook ->url );
32+ $ args ['method ' ] = 'GET ' ;
33+ } else {
34+ $ url = $ webhook ->url ;
35+ $ args ['method ' ] = 'POST ' ;
36+ $ args ['body ' ] = wp_json_encode ( $ payload );
37+ if ( empty ( $ args ['headers ' ]['Content-Type ' ] ) ) {
38+ $ args ['headers ' ]['Content-Type ' ] = 'application/json ' ;
39+ }
40+ }
41+ wp_remote_request ( $ url , $ args );
42+ do_action ( 'graphql_webhooks_sent ' , $ webhook , $ payload );
43+ }
4844}
0 commit comments