Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a plugin or snippet that would:

  1. Add an email input form to each post
  2. Send a predefined message when new media (or attachments) has been uploaded for that post only

The requested functionality here is different from other plugins I am aware of because it targets only the end user and only on new media upload (as compared to comments).

Any insight at all would be helpful!

share|improve this question
    
I am not sure about only media uploads - but there are many notification plugins that will notify users when post is updated. and if you click the "update post" button when new attachment is added - so It will notify them. as for upload via the media upload - I am sure that these plugins can be very easily be adapted to that (just add another trigger action on media save) –  krembo99 Mar 29 '12 at 10:55

1 Answer 1

up vote 1 down vote accepted

As for the email input form, you can use any plugin for Custom Fields ( I use Advanced Custom Fields or Custom Content Type Manager ) or add you own meta box ( tutorial ).

And for sending an email to the address inserted as a custom field, use the following code.
The custom field is named email_warn.

The filter wp_mail_content_type enables html content for emails.
And add_attachment will fire at each upload, pull the parent ID and send an email if the custom field is defined and is a valid email

add_filter( 'wp_mail_content_type', 'wpse_20324_mail_html' );
add_filter( 'add_attachment', 'wpse_20324_post_upload' );

function wpse_20324_mail_html()
{
    return "text/html";
}

function wpse_20324_post_upload( $attachment_ID )
{
    $uploaded = get_post( $attachment_ID );
    $email = get_post_meta( $uploaded->post_parent, 'email_warn', true );

    if( isset( $email ) && is_email( $email ) ) 
    {
        /**
         * The message will contain all post info about the uploaded file 
        */
        $vardump = print_r( $uploaded, true );
        $message = '<pre>' . $vardump . '</pre>';

        $headers = 'From: Test WPSE <test@test.com>' . "\r\n";

        wp_mail( $email, 'subject', $message, $headers );
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.