PluginProbe
Ultimate FAQ Accordion Plugin / trunk
Ultimate FAQ Accordion Plugin vtrunk
2.4.14 2.4.13 2.4.12 2.4.11 2.4.10 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 All 241 releases
ultimate-faqs / includes / Notifications.class.php

Notifications.class.php in Ultimate FAQ Accordion Plugin trunk, at includes/Notifications.class.php

135 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class to handle sending notifications when an FAQ is submitted
5 */
6
7 if ( !defined( 'ABSPATH' ) )
8 exit;
9
10 if ( !class_exists( 'ewdufaqNotifications' ) ) {
11 class ewdufaqNotifications {
12
13 public function __construct() {
14
15 add_action( 'ewd_ufaq_insert_faq', array( $this, 'admin_notification_email' ) );
16 add_action( 'ewd_ufaq_insert_faq', array( $this, 'user_submission_email' ) );
17 }
18
19 /**
20 * Send an email to the site admin when an FAQ is submitted, if selected
21 *
22 * @since 2.0.0
23 */
24 public function admin_notification_email( $faq ) {
25 global $ewd_ufaq_controller;
26
27 if ( ! $ewd_ufaq_controller->settings->get_setting( 'admin-question-notification' ) ) { return; }
28
29 $admin_emails = $ewd_ufaq_controller->settings->get_setting( 'admin-notification-email' ) ? explode( ',', $ewd_ufaq_controller->settings->get_setting( 'admin-notification-email' ) ) : (array) get_option( 'admin_email' );
30
31 $faq_link = site_url() . '/wp-admin/post.php?post=' . $faq->ID . '&action=edit';
32
33 $subject_line = __( 'New Question Received', 'ultimate-faqs' );
34
35 $message_body = __( 'Hello Admin,', 'ultimate-faqs' ) . '<br/><br/>';
36 $message_body .= __( 'You\'ve received a new question titled ', 'ultimate-faqs' ) . $faq->question . '.<br/><br/>';
37
38 if ( ! empty( $faq->answer ) ) {
39
40 $message_body .= __( 'The answer reads:<br>', 'ultimate-faqs' );
41 $message_body .= esc_html( $faq->answer ) . '<br><br><br>';
42 }
43
44 $message_body .= __( 'You can view the question in the admin area by going to the following link:<br>', 'ultimate-faqs' );
45 $message_body .= '<a href=\'' . $faq_link . '\'>' . __( 'See the FAQ', 'ultimate-faqs' ) . '</a><br/><br/>';
46 $message_body .= __( 'Have a great day,', 'ultimate-faqs' ) . '<br/><br/>';
47 $message_body .= __( 'Ultimate FAQs Team', 'ultimate-faqs' );
48
49 $headers = array( 'Content-Type: text/html; charset=UTF-8' );
50
51 foreach ( $admin_emails as $admin_email ) {
52
53 $success = wp_mail( $admin_email, $subject_line, $message_body, $headers );
54 }
55
56 return $success;
57 }
58
59 /**
60 * Send an email to the FAQ author using UWPM when an FAQ is submitted, if selected
61 *
62 * @since 2.0.0
63 */
64 public function user_submission_email( $faq ) {
65 global $ewd_ufaq_controller;
66
67 if ( ! $ewd_ufaq_controller->settings->get_setting( 'submit-faq-email' ) ) { return; }
68
69 $params = array(
70 'email_id' => $ewd_ufaq_controller->settings->get_setting( 'submit-faq-email' ),
71 'email_address' => $faq->faq_author_email,
72 'post_id' => $faq->ID
73 );
74
75 if ( function_exists( 'ewd_uwpm_send_email' ) ) {
76
77 ewd_uwpm_send_email( $params );
78 }
79 else {
80
81 $author_emails = $faq->faq_author_email ? explode( ',', $faq->faq_author_email ) : array();
82
83 $subject_line = apply_filters( 'ewd_ufaq_user_question_submitted_subject_line', __( 'New Question', 'ultimate-faqs' ) );
84
85 $message_body = __( 'Hello,', 'ultimate-faqs' ) . '<br/><br/>';
86 $message_body .= sprintf( __( 'Thank you for submitting your FAQ, %s. ', 'ultimate-faqs' ), $faq->question ) . '<br/><br/>';
87 $message_body .= get_bloginfo( 'name' );
88
89 $message_body = apply_filters( 'ewd_ufaq_user_question_submitted_message_body', $message_body );
90
91 $headers = array( 'Content-Type: text/html; charset=UTF-8' );
92
93 foreach ( $author_emails as $author_email ) {
94
95 if ( ! filter_var( $author_email, FILTER_VALIDATE_EMAIL ) ) { continue;}
96
97 $success = wp_mail( $author_email, $subject_line, $message_body, $headers );
98 }
99
100 return $success;
101 }
102 }
103
104 /**
105 * Send an email to the FAQ author once their question has been answered
106 *
107 * @since 2.4.0
108 */
109 public function user_question_updated( $faq ) {
110
111 $author_emails = $faq->faq_author_email ? explode( ',', $faq->faq_author_email ) : array();
112
113 $subject_line = apply_filters( 'ewd_ufaq_user_question_answered_subject_line', __( 'New Question Answer', 'ultimate-faqs' ) );
114
115 $message_body = __( 'Hello,', 'ultimate-faqs' ) . '<br/><br/>';
116 $message_body .= sprintf( __( 'Your FAQ, %s, has received a new question answer: ', 'ultimate-faqs' ), $faq->question ) . '<br/><br/>' . $faq->answer . '<br/><br/>';
117 $message_body .= __( 'Thank You,', 'ultimate-faqs' ) . '<br/><br/>';
118
119 $message_body = apply_filters( 'ewd_ufaq_user_question_answered_message_body', $message_body, $faq );
120
121 $headers = array( 'Content-Type: text/html; charset=UTF-8' );
122
123 foreach ( $author_emails as $author_email ) {
124
125 if ( ! filter_var( $author_email, FILTER_VALIDATE_EMAIL ) ) { continue;}
126
127 $success = wp_mail( $author_email, $subject_line, $message_body, $headers );
128 }
129
130 return $success;
131 }
132 }
133 } // endif;
134
135