Is email post notify visitor on new media upload possible?

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).

Read More

Any insight at all would be helpful!

Related posts

Leave a Reply

1 comment

  1. 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>' . "rn";
    
            wp_mail( $email, 'subject', $message, $headers );
        }
    }