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

162 lines 3.5 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 * Is HTML email?
17 *
18 * @var bool
19 */
20 protected $is_html = true;
21
22 /**
23 * Gets email subject.
24 *
25 * @return string
26 */
27 abstract protected function get_subject();
28
29 /**
30 * Gets inner content.
31 *
32 * @return false|string
33 */
34 abstract protected function get_inner_content();
35
36 /**
37 * Constructor.
38 */
39 public function __construct() {
40 /**
41 * Enables HTML for summary emails.
42 *
43 * @since 6.7
44 *
45 * @param bool $enable Set to `true` to enable.
46 */
47 $this->is_html = apply_filters( 'frm_html_summary_emails', true );
48 }
49
50 /**
51 * Gets recipients.
52 *
53 * @return string
54 */
55 protected function get_recipients() {
56 $recipients = FrmAppHelper::get_settings()->summary_emails_recipients;
57 $recipients = str_replace( '[admin_email]', get_bloginfo( 'admin_email' ), $recipients );
58 FrmEmailSummaryHelper::maybe_remove_recipients_from_api( $recipients );
59 return $recipients;
60 }
61
62 /**
63 * Gets email headers.
64 *
65 * @return string[]
66 */
67 protected function get_headers() {
68 return array(
69 'Content-Type: ' . ( $this->is_html ? 'text/html; charset=UTF-8' : 'text/plain' ),
70 'From: ' . get_bloginfo( 'name' ) . ' <' . get_bloginfo( 'admin_email' ) . '>',
71 );
72 }
73
74 /**
75 * Gets email content.
76 *
77 * @since 6.8 This can return `false` to skip sending email.
78 *
79 * @return false|string
80 */
81 protected function get_content() {
82 $args = $this->get_content_args();
83 if ( false === $args ) {
84 return false;
85 }
86
87 ob_start();
88 include $this->get_include_file( 'base' );
89 $content = ob_get_clean();
90
91 $content = str_replace( '%%INNER_CONTENT%%', $this->get_inner_content(), $content );
92
93 return $content;
94 }
95
96 /**
97 * Gets include file path from the given file name.
98 *
99 * @param string $file_name File name.
100 * @return string
101 */
102 protected function get_include_file( $file_name ) {
103 $suffix = $this->is_html ? '' : '-plain';
104 return FrmAppHelper::plugin_path() . '/classes/views/summary-emails/' . $file_name . $suffix . '.php';
105 }
106
107 /**
108 * Gets content args.
109 *
110 * @since 6.8 This can return `false` to skip sending email.
111 *
112 * @return array|false
113 */
114 protected function get_content_args() {
115 $args = array(
116 'subject' => $this->get_subject(),
117 'site_url' => home_url( '/' ),
118 'site_url_display' => home_url( '/' ),
119 'unsubscribe_url' => site_url() . '/wp-admin/admin.php?page=formidable-settings&t=misc_settings',
120 'support_url' => FrmEmailSummaryHelper::get_frm_url( 'new-topic', 'contact_support' ),
121 );
122
123 /**
124 * Filters the summary email content args.
125 *
126 * @since 6.7
127 *
128 * @param array $args Content args.
129 * @param array $filter_args Contains `email_obj`: summary email object.
130 */
131 return apply_filters( 'frm_summary_email_content_args', $args, array( 'email_obj' => $this ) );
132 }
133
134 /**
135 * Sends email.
136 *
137 * @return bool
138 */
139 public function send() {
140 $recipients = $this->get_recipients();
141 if ( ! $recipients ) {
142 // Return true to not try to send this email on the next day.
143 return true;
144 }
145
146 $content = $this->get_content();
147 if ( false === $content ) {
148 return true;
149 }
150 $subject = $this->get_subject();
151 $headers = $this->get_headers();
152
153 $sent = wp_mail( $recipients, $subject, $content, $headers );
154 if ( ! $sent ) {
155 $headers = implode( "\r\n", $headers );
156 $sent = mail( $recipients, $subject, $content, $headers );
157 }
158
159 return $sent;
160 }
161 }
162