我正在使用Postie插件在我的Wp博客上自动发布电子邮件。 我正在尝试使用“from”和“reply to”字段填充两个自定义字段(mail_meta_from和mail_meta_replyto“)
add_filter('postie_post_before', 'add_custom_field');
//Get the "from" and "replyto" email details
add_filter('postie_filter_email2', 'get_emaildetails', 10, 3);
function get_emaildetails( $from, $toEmail, $replytoEmail) {
DebugEcho("step-01b");
DebugDump("from " . $from);
DebugDump("toEmail " . $toEmail);
DebugDump("replytoEmail " . $replytoEmail);
$fromField = $from;
$replytoEmail = $replytoEmail;
return $from;
return $replytoEmail;
function add_custom_field($post) {
add_post_meta($post['ID'], 'mail_meta_from', '$from');
add_post_meta($post['ID'], 'mail_meta_replyto', $replytoEmail);
return $post;
}
}
过去两天这让我疯了,我尝试了上述的多种变化但没有成功。 目前,我收到了错误
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'add_custom_field' not found or invalid function name in /home/sites/mysite.com/public_html/wp-includes/plugin.php on line 213
我试着从错误中吸取教训,但是我没有得到任何关于...... WP论坛的默认答案是查看http://postieplugin.com/extending/。
我有......反复。
非常感谢任何帮助!
答案 0 :(得分:1)
您正在add_custom_field()
函数范围内定义get_emaildetails()
函数,因为它位于花括号内。您还应该考虑为函数使用更独特的名称,或者将其封装为对象名称空间。您收到的错误表示,当apply_filter()
调用postie_post_before
时,找不到名为add_custom_field()
的函数。使用下面的代码来正确定位函数,但请注意您还有其他一些语法错误。
add_filter('postie_post_before', 'add_custom_field');
function add_custom_field($post) {
// the variable $from is not defined, and it will not evaluate if enclosed
// in single quotes. if you want the value of $from define it then use "{$from}"
add_post_meta($post['ID'], 'mail_meta_from', '$from');
// $replytoEmail is not defined
add_post_meta($post['ID'], 'mail_meta_replyto', $replytoEmail);
return $post;
}
//Get the "from" and "replyto" email details
add_filter('postie_filter_email2', 'get_emaildetails', 10, 3);
function get_emaildetails( $from, $toEmail, $replytoEmail) {
DebugEcho("step-01b");
DebugDump("from " . $from);
DebugDump("toEmail " . $toEmail);
DebugDump("replytoEmail " . $replytoEmail);
// what is this for?
$fromField = $from;
// setting to itself, then not used?
$replytoEmail = $replytoEmail;
return $from;
// this will never return?
return $replytoEmail;
}