-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslack-gravityforms.php
More file actions
75 lines (67 loc) · 2.16 KB
/
slack-gravityforms.php
File metadata and controls
75 lines (67 loc) · 2.16 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* Plugin Name: Slack Gravity Forms
* Plugin URI: http://gedex.web.id/wp-slack-gravityforms/
* Description: This plugin allows you to send notifications to Slack channels whenever new submission entries, for Gravity Forms, are received.
* Version: 0.1.0
* Author: Akeda Bagus
* Author URI: http://gedex.web.id
* Text Domain: slack
* Domain Path: /languages
* License: GPL v2 or later
* Requires at least: 3.6
* Tested up to: 3.8
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/**
* Adds new event that send notification to Slack channel
* whenever new submission entries are received.
*
* @param array $events
* @return array
*
* @filter slack_get_events
*/
function wp_slack_gform_after_submission( $events ) {
$events['gform_after_submission'] = array(
// Action in Gravity Forms to hook in to get the message.
'action' => 'gform_after_submission',
// Description appears in integration setting.
'description' => __( 'When new submission entry, for Gravity Forms, received', 'slack' ),
// Message to deliver to channel. Returns false will prevent
// notification delivery.
'message' => function( $entry, $form ) {
$admin_url = add_query_arg(
array(
'page' => 'gf_entries',
'view' => 'entry',
'id' => $entry['form_id'],
'lid' => $entry['id'],
),
admin_url( 'admin.php' )
);
return apply_filters( 'slack_gform_after_submission_message',
sprintf(
__( 'New submission for *<%s|%s>* form on *%s*. *<%s|See entry>*.', 'slack' ),
$entry['source_url'],
$form['title'],
$entry['date_created'],
$admin_url
),
$entry,
$form
);
}
);
return $events;
}
add_filter( 'slack_get_events', 'wp_slack_gform_after_submission' );