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

146 lines 3.1 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 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 return $recipients;
59 }
60
61 /**
62 * Gets email headers.
63 *
64 * @return string[]
65 */
66 protected function get_headers() {
67 return array(
68 'Content-Type: ' . ( $this->is_html ? 'text/html; charset=UTF-8' : 'text/plain' ),
69 'From: ' . get_bloginfo( 'name' ) . ' <' . get_bloginfo( 'admin_email' ) . '>',
70 );
71 }
72
73 /**
74 * Gets email content.
75 *
76 * @return string
77 */
78 protected function get_content() {
79 $args = $this->get_content_args();
80
81 /**
82 * Filters the summary email content args.
83 *
84 * @since 6.7
85 *
86 * @param array $args Content args.
87 * @param array $filter_args Contains `email_obj`: summary email object.
88 */
89 $args = apply_filters( 'frm_summary_email_content_args', $args, array( 'email_obj' => $this ) );
90
91 ob_start();
92 include $this->get_include_file( 'base' );
93 $content = ob_get_clean();
94
95 $content = str_replace( '%%INNER_CONTENT%%', $this->get_inner_content(), $content );
96
97 return $content;
98 }
99
100 /**
101 * Gets include file path from the given file name.
102 *
103 * @param string $file_name File name.
104 * @return string
105 */
106 protected function get_include_file( $file_name ) {
107 $suffix = $this->is_html ? '' : '-plain';
108 return FrmAppHelper::plugin_path() . '/classes/views/summary-emails/' . $file_name . $suffix . '.php';
109 }
110
111 /**
112 * Gets content args.
113 *
114 * @return array
115 */
116 protected function get_content_args() {
117 return array(
118 'subject' => $this->get_subject(),
119 'site_url' => home_url( '/' ),
120 'site_url_display' => home_url( '/' ),
121 'unsubscribe_url' => site_url() . '/wp-admin/admin.php?page=formidable-settings&t=misc_settings',
122 'support_url' => FrmEmailSummaryHelper::get_frm_url( 'new-topic', 'contact_support' ),
123 );
124 }
125
126 /**
127 * Sends email.
128 *
129 * @return bool
130 */
131 public function send() {
132 $recipients = $this->get_recipients();
133 $content = $this->get_content();
134 $subject = $this->get_subject();
135 $headers = $this->get_headers();
136
137 $sent = wp_mail( $recipients, $subject, $content, $headers );
138 if ( ! $sent ) {
139 $headers = implode( "\r\n", $headers );
140 $sent = mail( $recipients, $subject, $content, $headers );
141 }
142
143 return $sent;
144 }
145 }
146