-
Notifications
You must be signed in to change notification settings - Fork 0
/
discord.php
33 lines (28 loc) · 867 Bytes
/
discord.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
/**
* Send_message_to_discord
*
* @param string $message The message to send.
*
* @return void
*/
function send_message_to_discord( $message = 'undefined' ) {
// Get your webhook URL from Discord.
$url = 'https://discordapp.com/api/webhooks/your-webhook-id-here';
$current_date = gmdate( 'l F dS Y h:i:sa' );
$data = array(
'content' => $message . ' - ' . $current_date
);
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => 'Content-Type: application/json',
'method' => 'POST',
'content' => json_encode( $data ),
),
);
$context = stream_context_create( $options );
$result = file_get_contents( $url, false, $context );
}
add_action( 'wp_ajax_discord_message', 'send_message_to_discord' );
add_action( 'wp_ajax_nopriv_discord_message', 'send_message_to_discord' );