我“继承”了一个活动预订WP插件,出于某种原因(显然,在将网站移动到同一服务器的另一个位置后),现在的情况是这样的:
正如预期的那样,新的预订将与相关信息一起添加到数据库中,并可以在自定义帖子类型(预订)管理页面中看到,但。。。
预订确认电子邮件仅在注册用户(管理员)进行预订测试时送达,而未注册用户(普通访客)则不会收到实际预订的确认电子邮件。
给网站所有者的通知邮件(用于用户的“真实”预订)有几个空字符串,而不是它们应该包含的自定义字段值。
起初,我认为问题出在wp\\u mail()的使用上,所以我尝试修补它(比如,使用PHP mail()而不是mailgun SMTP)。但看看这个方法:
public static function send_request($booking_id)
{
$booking_info = self::get_booking_info($booking_id);
PC::Debug($booking_info, "booking_info in send_request");
/* PC::Debug() shows an almost empty array, except for \'event\' and \'name\' */
$subject = self::get_title_info($booking_id) . \' - \' . self::$request[\'subject\'][$booking_info[\'language\']];
$message = self::$request[\'client\'][$booking_info[\'language\']] . self::$footer;
// Not working = Empty \'To\' field
wp_mail($booking_info[\'mail\'], $subject, $message, self::$headers);
$subject = self::get_title_info($booking_id) . \' - \' . self::$request[\'subject\'][\'it\'];
$message = self::$request[\'admin\'] . self::get_info_for_admin($booking_id);
// Working
wp_mail(self::admin_mails(), $subject, $message, self::$headers);
}
让我意识到唯一的区别似乎在于wp\\u mail()的第一个参数,并且我已经验证(感谢wp mail Log plugin)及其原始或JSON格式,这些邮件的“Receiver:”字段实际上是空的。“普通用户”版本中的此字段源自:
private static function get_booking_info($booking_id)
{
$post = get_post( $booking_id );
PC::Debug($post);
// Debug is fine
return array(
\'name\' => $post->post_title,
\'event\' => MP_Booking_Register::get_event_name($post->booking_show),
\'mail\' => $post->booking_email,
\'language\' => $post->booking_language,
\'seats\' => $post->booking_seats,
\'date\' => $post->booking_date,
);
}
现在,这些自定义字段由该函数生成:
private static function insert_post($booking_info) {
$booking = array(
\'post_title\' => $booking_info[\'name\'],
\'post_type\' => \'booking\',
\'post_status\' => \'publish\',
\'post_date\' => date(\'Y-m-d H:i:s\', strtotime(\'now\')),
\'post_author\' => 1,
);
PC::debug($booking_info,"booking_info in insert_post()");
// Debug OK
$booking_id = wp_insert_post($booking);
PC::debug($booking_id,"booking_id (NEW) in insert_post()");
// Debug OK
add_post_meta($booking_id, \'booking_first_name\', $booking_info[\'first_name\'], true);
add_post_meta($booking_id, \'booking_last_name\', $booking_info[\'last_name\'], true);
add_post_meta($booking_id, \'booking_email\', $booking_info[\'mail\'], true);
add_post_meta($booking_id, \'booking_language\',$booking_info[\'language\'], true);
add_post_meta($booking_id, \'booking_seats\', $booking_info[\'seats\'], true);
add_post_meta($booking_id, \'booking_show\', $booking_info[\'event\'], true);
add_post_meta($booking_id, \'booking_date\', $booking_info[\'date\'], true);
add_post_meta($booking_id, \'booking_state\', \'Richiesto\', true);
$postCustom = get_post_custom($booking_id);
PC::debug($postCustom, "Custom Fields");
$allMeta = get_post_meta($booking_id);
PC::debug($allMeta,"All Post Meta");
return $booking_id;
}
使用PC::Debug()我可以正确地看到$booking\\u id和$booking\\u信息,但$postCustom和$postMeta是空数组。所以add\\u post\\u meta()是否失败?如果是,为什么?
相关类别:
https://gist.github.com/CarloMartini/cc4083b4cf3634c74a910a3ae80f44b6
https://gist.github.com/CarloMartini/61ff9d0fc961b5e94bc7a938c6b5fc4d