PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.3.9
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.3.9
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
← All changes | includes/integrations/slack/class-integration-slack.php +108 -103 1.6.81.3.9 View file →
@@ -1,103 +1,108 @@
1 -<?php
2 -
3 -/**
4 - * Slack Integrations
5 - */
6 -class WeForms_Integration_Slack extends WeForms_Abstract_Integration {
7 -
8 - /**
9 - * Initialize the plugin
10 - */
11 - public function __construct() {
12 - $this->id = 'slack';
13 - $this->title = __( 'Slack', 'weforms' );
14 - $this->icon = WEFORMS_ASSET_URI . '/images/icon-slack.svg';
15 -
16 - $this->settings_fields = [
17 - 'enabled' => false,
18 - 'url' => '',
19 - ];
20 -
21 - add_action( 'weforms_entry_submission', [ $this, 'send_notification' ], 10, 4 );
22 - }
23 -
24 - /**
25 - * Subscribe a user when a form is submitted
26 - *
27 - * @param int $entry_id
28 - * @param int $form_id
29 - * @param int $page_id
30 - * @param array $form_settings
31 - *
32 - * @return void
33 - */
34 - public function send_notification( $entry_id, $form_id, $page_id, $form_settings ) {
35 - $integration = weforms_is_integration_active( $form_id, $this->id );
36 -
37 - if ( false === $integration ) {
38 - return;
39 - }
40 -
41 - if ( empty( $integration->url ) ) {
42 - return;
43 - }
44 -
45 - $attachment_fields = [];
46 - $title = sprintf( __( '#%d New submission on %s', 'weforms' ), $entry_id, get_post_field( 'post_title', $form_id ) );
47 - $form_data = weforms_get_entry_data( $entry_id );
48 -
49 - if ( false === $form_data ) {
50 - return;
51 - }
52 -
53 - // prepare the attachment data
54 - foreach ( $form_data['fields'] as $meta_key => $value ) {
55 - $is_short = true;
56 - $_value = $form_data['data'][ $meta_key ];
57 -
58 - if ( 'textarea' == $value['type'] ) {
59 - $is_short = false;
60 - $_value = html_entity_decode( $_value );
61 -
62 - // replace paragrphs and breaks
63 - $_value = str_replace( '<p>', '', $_value );
64 - $_value = str_replace( '<br />', '', $_value );
65 - $_value = str_replace( '</p>', "\n", $_value );
66 - }
67 -
68 - $attachment_fields[] = [
69 - 'title' => $value['label'],
70 - 'value' => $_value,
71 - 'short' => $is_short,
72 - ];
73 - }
74 -
75 - $data = [
76 - 'payload' => json_encode( [
77 - 'username' => 'weForms',
78 - 'icon_url' => '',
79 - 'attachments' => [
80 - [
81 - 'fallback' => $title,
82 - 'color' => '#36a64f',
83 - 'title' => $title,
84 - 'title_link' => sprintf( '%s#/form/%d/entries/%d', admin_url( 'admin.php?page=weforms' ), $form_id, $entry_id ),
85 - 'fields' => $attachment_fields,
86 - 'footer' => 'weForms',
87 - 'ts' => current_time( 'timestamp' ),
88 - ],
89 - ],
90 - ] ), ];
91 -
92 - $posting_to_slack = wp_remote_post( $integration->url, [
93 - 'method' => 'POST',
94 - 'timeout' => 30,
95 - 'redirection' => 5,
96 - 'httpversion' => '1.0',
97 - 'blocking' => false,
98 - 'headers' => [],
99 - 'body' => $data,
100 - 'cookies' => [],
101 - ] );
102 - }
103 -}
1 +<?php
2 +
3 +/**
4 + * Slack Integrations
5 + *
6 + * @package weForms\Integrations
7 + */
8 +class WeForms_Integration_Slack extends WeForms_Abstract_Integration {
9 +
10 + /**
11 + * Initialize the plugin
12 + */
13 + function __construct() {
14 + $this->id = 'slack';
15 + $this->title = __( 'Slack', 'weforms' );
16 + $this->icon = WEFORMS_ASSET_URI . '/images/icon-slack.svg';
17 +
18 + $this->settings_fields = array(
19 + 'enabled' => false,
20 + 'url' => '',
21 + );
22 +
23 + add_action( 'weforms_entry_submission', array( $this, 'send_notification' ), 10, 4 );
24 + }
25 +
26 + /**
27 + * Subscribe a user when a form is submitted
28 + *
29 + * @param int $entry_id
30 + * @param int $form_id
31 + * @param int $page_id
32 + * @param array $form_settings
33 + *
34 + * @return void
35 + */
36 + public function send_notification( $entry_id, $form_id, $page_id, $form_settings ) {
37 +
38 + $integration = weforms_is_integration_active( $form_id, $this->id );
39 +
40 + if ( false === $integration ) {
41 + return;
42 + }
43 +
44 + if ( empty( $integration->url ) ) {
45 + return;
46 + }
47 +
48 + $attachment_fields = array();
49 + $title = sprintf( __( "#%d New submission on %s", 'weforms' ), $entry_id, get_post_field( 'post_title', $form_id ) );
50 + $form_data = weforms_get_entry_data( $entry_id );
51 +
52 + if ( false === $form_data ) {
53 + return;
54 + }
55 +
56 + // prepare the attachment data
57 + foreach ( $form_data['fields'] as $meta_key => $value ) {
58 + $is_short = true;
59 + $_value = $form_data['data'][ $meta_key ];
60 +
61 + if ( 'textarea' == $value['type'] ) {
62 + $is_short = false;
63 + $_value = html_entity_decode( $_value );
64 +
65 + // replace paragrphs and breaks
66 + $_value = str_replace( '<p>', '', $_value );
67 + $_value = str_replace( '<br />', '', $_value );
68 + $_value = str_replace( '</p>', "\n", $_value );
69 + }
70 +
71 + $attachment_fields[] = array(
72 + 'title' => $value['label'],
73 + 'value' => $_value,
74 + 'short' => $is_short
75 + );
76 + }
77 +
78 + $data = array(
79 + 'payload' => json_encode( array(
80 + 'username' => 'weForms',
81 + 'icon_url' => '',
82 + 'attachments' => array(
83 + array(
84 + 'fallback' => $title,
85 + 'color' => '#36a64f',
86 + 'title' => $title,
87 + 'title_link' => sprintf( '%s#/form/%d/entries/%d', admin_url( 'admin.php?page=weforms' ), $form_id, $entry_id ),
88 + 'fields' => $attachment_fields,
89 + 'footer' => 'weForms',
90 + 'ts' => current_time( 'timestamp' )
91 + )
92 + )
93 + ) ) );
94 +
95 + $posting_to_slack = wp_remote_post( $integration->url, array(
96 + 'method' => 'POST',
97 + 'timeout' => 30,
98 + 'redirection' => 5,
99 + 'httpversion' => '1.0',
100 + 'blocking' => false,
101 + 'headers' => array(),
102 + 'body' => $data,
103 + 'cookies' => array()
104 + ) );
105 +
106 + }
107 +
108 +}