Advertisement
Guest User

Untitled

a guest
Mar 20th, 2015
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. <?php
  2. /**
  3. * Plugin Name: Slack Contact Form 7
  4. * Plugin URI: https://github.com/gedex/wp-contact-form-7
  5. * Description: This plugin allows you to send notifications to Slack channels whenever someone sent message through Contact Form 7.
  6. * Version: 0.1.0
  7. * Author: Akeda Bagus
  8. * Author URI: http://gedex.web.id
  9. * Text Domain: slack
  10. * Domain Path: /languages
  11. * License: GPL v2 or later
  12. * Requires at least: 3.6
  13. * Tested up to: 3.8
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. */
  25.  
  26. /**
  27. * Adds new event that send notification to Slack channel
  28. * when someone sent message through Contact Form 7.
  29. *
  30. * @param array $events
  31. * @return array
  32. *
  33. * @filter slack_get_events
  34. */
  35. function wp_slack_wpcf7_submit( $events ) {
  36.  
  37. $events['wpcf7_submit'] = array(
  38. // Action in Gravity Forms to hook in to get the message.
  39. 'action' => 'wpcf7_mail_sent',
  40.  
  41. // Description appears in integration setting.
  42. 'description' => __( 'When someone sent message through Contact Form 7', 'slack' ),
  43. // Message to deliver to channel. Returns false will prevent
  44. // notification delivery.
  45. 'message' => function( $form, $result ) {
  46. $submission = WPCF7_Submission::get_instance();
  47.  
  48. if ( $submission ) {
  49. $posted_data = $submission->get_posted_data();
  50. }
  51.  
  52. return apply_filters( 'slack_wpcf7_submit_message',
  53. sprintf(
  54. __( '*%s* just sent a message titled "*%s*" through *%s*. Check your email!', 'slack' ),
  55. $posted_data['your-name'],$posted_data['your-subject'],$form->title
  56. ),
  57.  
  58. $form,
  59. $result
  60. );
  61. }
  62. );
  63.  
  64. return $events;
  65. }
  66. add_filter( 'slack_get_events', 'wp_slack_wpcf7_submit' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement