Skip to content

Commit c8af2b6

Browse files
committed
detect if phpmailer is being changed
1 parent b5bad79 commit c8af2b6

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

classes/suggested-tasks/providers/interactive/class-email-sending.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ class Email_Sending extends Interactive {
7070
*/
7171
protected $email_error = '';
7272

73+
/**
74+
* Whether phpmailer is filtered.
75+
*
76+
* @var bool
77+
*/
78+
protected $is_phpmailer_filtered = false;
79+
7380
/**
7481
* Initialize the task provider.
7582
*
@@ -86,6 +93,9 @@ public function init() {
8693
// Set the email error message.
8794
add_action( 'wp_mail_failed', [ $this, 'set_email_error' ] );
8895

96+
// By now all plugins should be loaded and hopefully add actions registered, so we can check if phpmailer is filtered.
97+
\add_action( 'init', [ $this, 'check_if_phpmailer_is_filtered' ], PHP_INT_MAX );
98+
8999
$this->email_subject = \esc_html__( 'Test email from Progress Planner', 'progress-planner' );
90100
// translators: %s is the admin URL.
91101
$this->email_content = sprintf( \esc_html__( 'This is a test email. Complete the task by clicking the link: %s', 'progress-planner' ), \admin_url( 'admin.php?page=progress-planner&prpl_complete_task=' . $this->get_task_id() ) );
@@ -137,6 +147,16 @@ public function enqueue_scripts() {
137147
);
138148
}
139149

150+
/**
151+
* Check if phpmailer is filtered.
152+
*
153+
* @return void
154+
*/
155+
public function check_if_phpmailer_is_filtered() {
156+
global $wp_filter;
157+
$this->is_phpmailer_filtered = isset( $wp_filter['phpmailer_init'] ) && ! empty( $wp_filter['phpmailer_init']->callbacks ) ? true : false;
158+
}
159+
140160
/**
141161
* Test email sending.
142162
*
@@ -309,7 +329,11 @@ public function the_popover_content() {
309329
<?php /* Email not received, showing troubleshooting */ ?>
310330
<div class="prpl-columns-wrapper-flex prpl-sending-email-step" id="prpl-sending-email-troubleshooting-step" style="display: none;">
311331
<div class="prpl-column prpl-column-content">
312-
332+
<?php if ( $this->is_phpmailer_filtered ) : ?>
333+
<p><?php \esc_html_e( 'Your website is using a plugin that filters emails.', 'progress-planner' ); ?></p>
334+
<?php else : ?>
335+
<p><?php \esc_html_e( 'Your website is not using a plugin that filters emails.', 'progress-planner' ); ?></p>
336+
<?php endif; ?>
313337
</div>
314338

315339
<div class="prpl-column">

0 commit comments

Comments
 (0)