在使用contact form 7和Grunion contact form插件之前,我就这样做了。在使用contact form 7时,我创建了一个新标签,将电子邮件发送给帖子作者:
//contact form 7 author email
wpcf7_add_shortcode(\'author_email\', \'wpcf7_expert_email_shortcode_handler\', true);
function wpcf7_expert_email_shortcode_handler($tag) {
if (!is_array($tag)) return \'\';
$name = $tag[\'name\'];
if (empty($name)) return \'\';
global $post;
//get author email:
$author_mail = get_the_author_meta(\'user_email\',$post->post_author);
$html = \'<input type="hidden" name="\' . $name . \'" value="\' . $author_mail . \'" />\';
return $html;
}
/*
* Usage: in contact form 7 form area add
* [author_email unique_name]
* and in to email address add
* [unique_name]
*/
对于Grunion,我直接从模板调用它,使用:
global $post;
$author_mail = get_the_author_meta(\'user_email\',$post->post_author);
echo do_shortcode(\'[contact-form subject="message from.\'$post->post_title.\'" to="\'.$author_mail.\'"]\');