PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.15
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.15
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.15, at classes/models/FrmEmailSummary.php

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