Created
October 18, 2022 22:18
-
-
Save tripflex/e6aec912b0e3145adec10d308c13918b to your computer and use it in GitHub Desktop.
Prevent specific email templates from sending when the user is an administrator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'job_manager_emails_email_should_send', 'smyles_email_should_send', 10, 4 ); | |
function smyles_email_should_send( $should_send, $template, $listing_id, $that ) { | |
// Don't send if the user IS an admin submitting the application | |
if ( $template->template_name && 'application_confirmation_non_admin' === $template->template_name && current_user_can( 'manage_options' ) ) { | |
return false; | |
} | |
// Don't send if the user IS NOT an admin submitting the application | |
if ( $template->template_name && 'application_confirmation_admin' === $template->template_name && ! current_user_can( 'manage_options' ) ) { | |
return false; | |
} | |
return $should_send; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You MUST set the "template name" under Advanced area when editing a template to:
application_confirmation_non_admin
- email to send when user is NOT an adminapplication_confirmation_admin
- email to send when user IS an admin