Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Format data to send a webhook to discord
<?php
/**
*
* Plugin Name: CF7 to Webhook - Discord Integration
* Description: Format data to send a webhook to discord
* Version: 1.0.0
* Author: Mário Valney
* Author URI: https://mariovalney.com
* Text Domain: cf7-to-webhook-discord-integration
*
*/
add_filter( 'ctz_post_request_args', 'discord_ctz_post_request_args' );
function discord_ctz_post_request_args( $args ) {
if ( empty( $args['body'] ) ) {
return $args;
}
$body = json_decode( $args['body'], true );
// Validate data. Add your own validation to change only this form.
if ( empty( $body ) || empty( $body['your-name'] ) || empty( $body['your-discordtag'] ) || empty( $body['your-email'] ) || empty( $body['your-message'] ) ) {
return $args;
}
$discord_body = array(
'content' => 'New message from ' . $body['your-name'] . ' on your website.',
'embeds' => array(
"title" => "Contactform",
"description" => sprintf( "**Discord-Tag:** %s\n**E-Mail:** %s\n\n**Message**\n%s", $body['your-discordtag'], $body['your-email'], $body['your-message'] ),
"color" => 9291330,
"author" => array(
"name" => $body['your-name'],
"icon_url" => "https://ennorath.org/wp-content/uploads/2020/03/mail.png",
),
),
);
$args['body'] = json_encode( $discord_body );
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment