How do I add an attachment to the approval email
Suppose you approve a user and want to attach a document to the email. This is easy to do just by adding a filter to core wp_mail function.
1 2 3 4 5 6 7 8 9 10 | function nua_include_attachment( $attributes ) { if ( strpos ( $attributes [ 'subject' ], 'Registration Approved' ) !== 0 ) { // add an attachment $attachments = array ( WP_CONTENT_DIR . '/uploads/support.zip' ); $attributes [ 'attachments' ] = $attachments ; } return $attributes ; } add_filter( 'wp_mail' , 'nua_include_attachment' ); |
A few things to note.
1 | if ( strpos ( $attributes [ 'subject' ], 'Registration Approved' ) !== 0 ) { |
None of the code will execute if the subject has been modified from the default. This would need to be modified to match part of the subject.
1 | $attachments = array ( WP_CONTENT_DIR . '/uploads/support.zip' ); |