我有一个插件(类似于注册表单),它为开发人员提供了一些操作/挂钩来添加他们自己的东西。插件内部的函数调用如下:
// Allow devs to hook in
do_action( \'after_record_action\', $result, $data, $format );
我想是吧
$data
是存储表单数据的数组。在访问者使用注册表单后,我想发送一封包含以下内容的邮件
$data
使用
wp_mail()
如何使用after_record_action
? 我需要在我的functions.php
?
// get data from $data[] array
$data[\'email\'] = $email;
$data[\'key\'] = $key;
// use $data to create a personalized mail
$to = $email;
$subject = "Wordpress Test";
$content = "Hi, this us your key:" . $key . "Enjoy using it!";
// send mail using wp_mail
$status = wp_mail($to, $subject, $content);
我非常感谢您对我的帮助,因为我对php的使用经验不太丰富。
最合适的回答,由SO网友:Marian Rick 整理而成
使用add_action
我可以为插件添加一个函数。
// add action to after_record_action
add_action(\'after_record_action\', \'marian_rick_custom_action\', 10, 3);
// add function
function marian_rick_custom_action ($result, $data, $format){
// get data from $data[] array
$email = $data[\'email\'];
$key = $data[\'key\'];
// use $data to create a personalized mail
$to = $email;
$subject = "Wordpress Test";
$content = "Hi, this us your key:" . $key . "Enjoy using it!";
// send mail using wp_mail
$status = wp_mail($to, $subject, $content);
}
As stated here by Tarun Mahashwari