Last active
December 29, 2024 22:21
-
-
Save mariovalney/3f6f4ea6f864239c9f7b327e75b201e9 to your computer and use it in GitHub Desktop.
Format data to send a webhook to discord
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
Hey. Check new version.
We have custom body now.