Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
Automator_Send_Webhook_Ajax_Handler::call_webhook( $data, bool $legacy = false )
Send data to Webhook
Contents
Parameters Parameters
- $data
-
(Required)
- $legacy
-
(Optional)
Default value: false
- $is_sample
-
(Required)
Return Return
(void)
Source Source
File: src/core/lib/webhooks/class-automator-send-webhook-ajax-handler.php
private function call_webhook( $data, $legacy = false ) { $data_type = Automator()->send_webhook->get_data_type( $data ); $headers = Automator()->send_webhook->get_headers( $data ); $webhook_url = Automator()->send_webhook->get_url( $data, $legacy ); $fields = Automator()->send_webhook->get_fields( $data, $legacy, $data_type, array() ); $request_type = Automator()->send_webhook->request_type( $data ); $headers = Automator()->send_webhook->get_content_type( $data_type, $headers ); if ( empty( $webhook_url ) ) { wp_send_json( array( 'type' => 'error', 'message' => esc_attr__( 'Please enter valid fields.', 'uncanny-automator' ), ) ); } if ( empty( $fields ) ) { wp_send_json( array( 'type' => 'error', 'message' => esc_attr__( 'Please enter data in fields.', 'uncanny-automator' ), ) ); } $args = array( 'method' => $request_type, 'body' => $fields, 'timeout' => '30', ); if ( ! empty( $headers ) ) { $args['headers'] = $headers; } $response = Automator_Send_Webhook::call_webhook( $webhook_url, $args, $request_type ); if ( $response instanceof WP_Error ) { /* translators: 1. Webhook URL */ $error_message = esc_attr__( 'There was an issue sending data to:', 'uncanny-automator' ); $error_message .= sprintf( ' %s', $webhook_url ); $error_message .= '<h5>' . esc_attr__( 'Response:', 'uncanny-automator' ) . '</h5>'; $error_message .= sprintf( '%s', join( '- <br />', $response->get_error_messages() ) ); wp_send_json( array( 'type' => 'error', 'message' => $error_message, ) ); } /* translators: 1. Webhook URL */ // $body = wp_remote_retrieve_body( $response ); // $msg = wp_remote_retrieve_response_message( $response ); // $type = wp_remote_retrieve_header( $response, 'content-type' ); $success_message = esc_attr__( 'Data successfully sent to:', 'uncanny-automator' ); $success_message .= sprintf( ' %s', $webhook_url ); // $success_message .= '<h5>' . esc_attr__( 'Response:', 'uncanny-automator' ) . '</h5>'; // $success_message .= "<strong>Message:</strong> $msg"; // $success_message .= "<br /><strong>Contet-Type:</strong> $type"; // $success_message .= "<br /><strong>Body:</strong><pre>$body</pre>"; wp_send_json( array( 'type' => 'success', 'message' => $success_message, ) ); }
Expand full source code Collapse full source code View on Github