PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.28
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.28
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / models / FrmEmailSummary.php

FrmEmailSummary.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.28, at classes/models/FrmEmailSummary.php

205 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Summary email base class
4 *
5 * @since 6.7
6 *
7 * @package Formidable
8 */
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 die( 'You are not allowed to call this page directly.' );
12 }
13
14 abstract class FrmEmailSummary {
15
16 /**
17 * Name of the file with the HTML content, without the file extension.
18 *
19 * @since 6.15
20 *
21 * @var string
22 */
23 protected $template = 'base';
24
25 /**
26 * Is HTML email?
27 *
28 * @var bool
29 */
30 protected $is_html = true;
31
32 /**
33 * Gets email subject.
34 *
35 * @return string
36 */
37 abstract protected function get_subject();
38
39 /**
40 * Gets inner content.
41 *
42 * @since 6.15 Method isn't abstract anymore, returning an empty string by default.
43 *
44 * @return false|string
45 */
46 protected function get_inner_content() {
47 return '';
48 }
49
50 /**
51 * Constructor.
52 */
53 public function __construct() {
54 /**
55 * Enables HTML for summary emails.
56 *
57 * @since 6.7
58 *
59 * @param bool $enable Set to `true` to enable.
60 */
61 $this->is_html = apply_filters( 'frm_html_summary_emails', true );
62 }
63
64 /**
65 * Gets recipients.
66 *
67 * @return string
68 */
69 protected function get_recipients() {
70 $recipients = FrmAppHelper::get_settings()->summary_emails_recipients;
71 $recipients = str_replace( '[admin_email]', get_bloginfo( 'admin_email' ), $recipients );
72 FrmEmailSummaryHelper::maybe_remove_recipients_from_api( $recipients );
73 return $recipients;
74 }
75
76 /**
77 * Gets email headers.
78 *
79 * @return string[]
80 */
81 protected function get_headers() {
82 return array(
83 'Content-Type: ' . ( $this->is_html ? 'text/html; charset=UTF-8' : 'text/plain' ),
84 'From: ' . get_bloginfo( 'name' ) . ' <' . FrmEmailHelper::get_default_from_email() . '>',
85 );
86 }
87
88 /**
89 * Gets email content.
90 *
91 * @since 6.8 This can return `false` to skip sending email.
92 *
93 * @return false|string
94 */
95 protected function get_content() {
96 $args = $this->get_content_args();
97
98 if ( false === $args ) {
99 return false;
100 }
101
102 ob_start();
103 include $this->get_include_file( $this->template );
104 $content = ob_get_clean();
105
106 return str_replace( '%%INNER_CONTENT%%', $this->get_inner_content(), $content );
107 }
108
109 /**
110 * Gets include file path from the given file name.
111 *
112 * @param string $file_name File name.
113 *
114 * @return string
115 */
116 protected function get_include_file( $file_name ) {
117 $suffix = $this->is_html ? '' : '-plain';
118 return $this->get_include_folder() . $file_name . $suffix . '.php';
119 }
120
121 /**
122 * Gets the full path to the folder containing the email templates.
123 *
124 * @since 6.15
125 *
126 * @return string
127 */
128 protected function get_include_folder() {
129 return FrmAppHelper::plugin_path() . '/classes/views/summary-emails/';
130 }
131
132 /**
133 * Gets content args.
134 *
135 * @since 6.8 This can return `false` to skip sending email.
136 *
137 * @return array|false
138 */
139 protected function get_content_args() {
140 $args = array(
141 'subject' => $this->get_subject(),
142 'site_url' => home_url( '/' ),
143 'site_url_display' => home_url( '/' ),
144 'unsubscribe_url' => site_url() . '/wp-admin/admin.php?page=formidable-settings&t=misc_settings',
145 'support_url' => FrmEmailSummaryHelper::get_frm_url( 'new-topic', 'contact_support' ),
146 );
147
148 /**
149 * Filters the summary email content args.
150 *
151 * @since 6.7
152 *
153 * @param array $args Content args.
154 * @param array $filter_args Contains `email_obj`: summary email object.
155 */
156 return apply_filters( 'frm_summary_email_content_args', $args, array( 'email_obj' => $this ) );
157 }
158
159 /**
160 * Check if the email should be sent.
161 *
162 * @since 6.15
163 *
164 * @return bool
165 */
166 protected function should_send() {
167 return true;
168 }
169
170 /**
171 * Sends email.
172 *
173 * @return bool
174 */
175 public function send() {
176 if ( ! $this->should_send() ) {
177 return false;
178 }
179
180 $recipients = $this->get_recipients();
181
182 if ( ! $recipients ) {
183 // Return true to not try to send this email on the next day.
184 return true;
185 }
186
187 $content = $this->get_content();
188
189 if ( false === $content ) {
190 return true;
191 }
192
193 $subject = $this->get_subject();
194 $headers = $this->get_headers();
195 $sent = wp_mail( $recipients, $subject, $content, $headers );
196
197 if ( ! $sent ) {
198 $headers = implode( "\r\n", $headers );
199 $sent = mail( $recipients, $subject, $content, $headers );
200 }
201
202 return $sent;
203 }
204 }
205