-
Notifications
You must be signed in to change notification settings - Fork 0
/
slacklient.php
57 lines (44 loc) · 1.39 KB
/
slacklient.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/*
Plugin Name: Slacklient plugin
Description: This plugin helps you to connect with your clients through a livechat using Slack.
Author: Désiré N'dri
Version: 0.1
License: GPL
*/
function mes_assets() {
wp_enqueue_script( 'slacklient-js', plugins_url( '/js/slacklient.js', __FILE__ ), $deps = array( 'jquery' ), $ver = false, $in_footer = true );
wp_localize_script('slacklient-js', 'ajaxurl', admin_url( 'admin-ajax.php' ) );
}
add_action( 'wp_enqueue_scripts', 'mes_assets' );
function mon_action() {
$post = [
'username' => $_POST['userName'],
'text' => $_POST['messageContent'],
];
//
// $test = json_encode($post);
$ch = curl_init('https://hooks.slack.com/services/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');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
// execute!
// $response = curl_exec($ch);
if(!curl_exec($ch)){
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}
// close the connection, release resources used
curl_close($ch);
//// do anything you want with your response
// var_dump($response);
//
//
//
//
//// var_dump($test);
// var_dump($_POST);
//// json_encode($_POST);
//// var_dump($_POST);
// die();
}
add_action( 'wp_ajax_post_slack', 'mon_action' );
add_action( 'wp_ajax_nopriv_post_slack', 'mon_action' );