PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 All 211 releases
charitable / includes / emails / class-charitable-email-test.php

class-charitable-email-test.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.13, at includes/emails/class-charitable-email-test.php

219 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class that models a simple test email for diagnostics.
4 *
5 * @package Charitable/Classes/Charitable_Email_Test
6 * @author Claude Code
7 * @copyright Copyright (c) 2023, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.8.9.2
10 * @version 1.0.0
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Email_Test' ) ) :
18
19 /**
20 * Test Email for Diagnostics
21 *
22 * @since 1.8.9.2
23 */
24 class Charitable_Email_Test extends Charitable_Email {
25
26 /** Email ID */
27 const ID = 'test_email';
28
29 /**
30 * Target email address for the test.
31 *
32 * @since 1.8.9.2
33 *
34 * @var string
35 */
36 protected $test_recipient;
37
38 /**
39 * Array of supported object types (none needed for test).
40 *
41 * @since 1.8.9.2
42 *
43 * @var string[]
44 */
45 protected $object_types = array();
46
47 /**
48 * Instantiate the email class, defining its key values.
49 *
50 * @since 1.8.9.2
51 *
52 * @param array $objects an array containing test parameters.
53 */
54 public function __construct( $objects = array() ) {
55 parent::__construct( $objects );
56
57 $this->name = apply_filters( 'charitable_email_test_name', __( 'Test Email', 'charitable' ) );
58 $this->test_recipient = isset( $objects['recipient'] ) ? $objects['recipient'] : get_option( 'admin_email' );
59 }
60
61 /**
62 * Returns the current email's ID.
63 *
64 * @since 1.8.9.2
65 *
66 * @return string
67 */
68 public static function get_email_id() {
69 return self::ID;
70 }
71
72 /**
73 * Static method to send a test email to the admin email address.
74 *
75 * @since 1.8.9.2
76 *
77 * @param string $recipient_email Optional. Email address to send test to. Defaults to admin email.
78 * @return array Array with 'success' boolean and 'message' string.
79 */
80 public static function send_test_email( $recipient_email = '' ) {
81 if ( empty( $recipient_email ) ) {
82 $recipient_email = get_option( 'admin_email' );
83 }
84
85 if ( ! is_email( $recipient_email ) ) {
86 return array(
87 'success' => false,
88 'message' => sprintf( __( 'Invalid email address: %s', 'charitable' ), $recipient_email ),
89 );
90 }
91
92 $email = new self(
93 array(
94 'recipient' => $recipient_email,
95 )
96 );
97
98 $sent = $email->send();
99
100 if ( $sent ) {
101 return array(
102 'success' => true,
103 'message' => sprintf( __( 'Test email sent successfully to %s using Charitable\'s email system.', 'charitable' ), $recipient_email ),
104 );
105 } else {
106 return array(
107 'success' => false,
108 'message' => sprintf( __( 'Failed to send test email to %s. This indicates an issue with Charitable\'s email system or your server\'s email configuration.', 'charitable' ), $recipient_email ),
109 );
110 }
111 }
112
113 /**
114 * Return the recipient for the email.
115 *
116 * @since 1.8.9.2
117 *
118 * @return string
119 */
120 public function get_recipient() {
121 return apply_filters( 'charitable_email_test_recipient', $this->test_recipient, $this );
122 }
123
124 /**
125 * Return the default subject line for the email.
126 *
127 * @since 1.8.9.2
128 *
129 * @return string
130 */
131 protected function get_default_subject() {
132 $subject = sprintf( __( 'Test Email from %s - Charitable Plugin', 'charitable' ), get_bloginfo( 'name' ) );
133 return apply_filters( 'charitable_email_test_default_subject', $subject, $this );
134 }
135
136 /**
137 * Return the default headline for the email.
138 *
139 * @since 1.8.9.2
140 *
141 * @return string
142 */
143 protected function get_default_headline() {
144 return apply_filters( 'charitable_email_test_default_headline', __( 'Charitable Email System Test', 'charitable' ), $this );
145 }
146
147 /**
148 * Return the default body for the email.
149 *
150 * @since 1.8.9.2
151 *
152 * @return string
153 */
154 protected function get_default_body() {
155 $charitable_logo_html = $this->get_charitable_logo_html();
156
157 ob_start();
158 ?>
159 <div style="text-align: center; margin: 20px 0;">
160 <?php echo $charitable_logo_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
161 </div>
162
163 <p><?php esc_html_e( 'Hello!', 'charitable' ); ?></p>
164
165 <p><?php esc_html_e( 'This is a test email sent from the Charitable plugin to verify that the email system is working correctly.', 'charitable' ); ?></p>
166
167 <p><strong><?php esc_html_e( 'Test Details:', 'charitable' ); ?></strong></p>
168 <ul>
169 <li><?php esc_html_e( 'Website:', 'charitable' ); ?> [charitable_email show=site_name] ([charitable_email show=site_url])</li>
170 <li><?php esc_html_e( 'Sent via:', 'charitable' ); ?> <?php esc_html_e( 'Charitable Email System', 'charitable' ); ?></li>
171 <li><?php esc_html_e( 'Date/Time:', 'charitable' ); ?> <?php echo esc_html( current_time( 'mysql' ) ); ?></li>
172 <li><?php esc_html_e( 'Charitable Version:', 'charitable' ); ?> <?php echo esc_html( charitable()->get_version() ); ?></li>
173 </ul>
174
175 <p><?php esc_html_e( 'If you received this email, it means Charitable\'s email system is functioning properly on your website.', 'charitable' ); ?></p>
176
177 <p><em><?php esc_html_e( 'This test email was sent from the Charitable Tools page in your WordPress admin.', 'charitable' ); ?></em></p>
178 <?php
179 $body = ob_get_clean();
180
181 return apply_filters( 'charitable_email_test_default_body', $body, $this );
182 }
183
184 /**
185 * Get Charitable logo HTML for email.
186 *
187 * @since 1.8.9.2
188 *
189 * @return string
190 */
191 private function get_charitable_logo_html() {
192 $logo_url = charitable()->get_path( 'directory', false ) . 'assets/images/charitable-logo.png';
193
194 // Check if logo file exists, fallback to text
195 if ( file_exists( charitable()->get_path( 'directory' ) . 'assets/images/charitable-logo.png' ) ) {
196 return sprintf(
197 '<img src="%s" alt="Charitable" style="max-width: 200px; height: auto;" />',
198 esc_url( $logo_url )
199 );
200 } else {
201 return '<div style="font-size: 24px; font-weight: bold; color: #0073aa;">Charitable</div>';
202 }
203 }
204
205 /**
206 * Checks whether an email can be resent.
207 *
208 * @since 1.8.9.2
209 *
210 * @param int $object_id An object ID (not used for test emails).
211 * @param array $args Mixed set of arguments.
212 * @return boolean
213 */
214 public static function can_be_resent( $object_id, $args = array() ) {
215 return true; // Test emails can always be "resent"
216 }
217 }
218
219 endif;