至于电子邮件输入表单,您可以使用任何用于自定义字段的插件(我使用Advanced Custom Fields 或Custom Content Type Manager ) 或添加您自己的元框(tutorial ).
要将电子邮件发送到作为自定义字段插入的地址,请使用以下代码
自定义字段命名为email_warn.
过滤器wp_mail_content_type
为电子邮件启用html内容
和add_attachment
如果自定义字段已定义且为有效电子邮件,则将在每次上载时触发,提取父ID并发送电子邮件
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 <[email protected]>\' . "\\r\\n";
wp_mail( $email, \'subject\', $message, $headers );
}
}