我正在使用Gravity表单,我已经让它发出自动通知。这个通知发生在我的Android应用程序连接到它并添加一个条目后。 我的问题是它不执行变量替换。
因此,例如,表单编辑器中的主题被定义为 来自{全名:2}
的新移动房屋应用提交但电子邮件最终结果为 来自
的新移动房屋应用程序提交电子邮件中的所有表单变量都不会被替换。但是,如果我检查网站上的条目,它就在那里。
我已将代码添加到Gravity Forms WebApi中的 post_entries 函数,如下所示:
public function post_entries($data, $form_id = null) {
$this->authorize('gravityforms_edit_entries');
$result = GFAPI::add_entries($data, $form_id);
if (is_wp_error($result)) {
$response = $this->get_error_response($result);
$status = $this->get_error_status($result);
} else {
$status = 201;
$response = $result;
// This is the form object from Gravity Forms.
$form = \GFAPI::get_form($form_id);
$event = 'form_submission';
$notifications = GFCommon::get_notifications_to_send($event, $form, $lead[0]);
$notifications_to_send = array();
//running through filters that disable form submission notifications
foreach ($notifications as $notification) {
if (apply_filters("gform_disable_notification_{$form['id']}", apply_filters('gform_disable_notification', false, $notification, $form, $lead), $notification, $form, $lead)) {
//skip notifications if it has been disabled by a hook
continue;
}
$notifications_to_send[] = $notification['id'];
}
GFCommon::send_notifications($notifications_to_send, $form, $lead, true, $event);
}
$this->end($status, $response);
}
编辑:这是Naomi帮助
的工作代码public function post_entries( $data, $form_id = null ) {
$this->authorize( 'gravityforms_edit_entries' );
$result = GFAPI::add_entries( $data, $form_id );
if ( is_wp_error( $result ) ) {
$response = $this->get_error_response( $result );
$status = $this->get_error_status( $result );
} else {
$status = 201;
$response = $result;
$lead = \GFAPI::get_entry($result);
// This is the form object from Gravity Forms.
$form = \GFAPI::get_form($form_id);
$event ='form_submission';
$notifications = GFCommon::get_notifications_to_send( $event, $form, $lead );
$notifications_to_send = array();
//running through filters that disable form submission notifications
foreach ( $notifications as $notification ) {
if ( apply_filters( "gform_disable_notification_{$form['id']}", apply_filters( 'gform_disable_notification', false, $notification, $form, $lead ), $notification, $form, $lead ) ) {
//skip notifications if it has been disabled by a hook
continue;
}
$notifications_to_send[] = $notification['id'];
}
GFCommon::send_notifications( $notifications_to_send, $form, $lead, true, $event );
}
$this->end( $status, $response );
}
答案 0 :(得分:1)
在您的代码中,您发送到通知功能的$ lead变量尚未设置在任何地方(您只是凭空掏空:-))。此变量需要包含Gravity Forms条目对象,然后通知函数可以使用它来替换变量。
来自GFAPI :: add_entries的$ result将为您提供一系列条目ID,您可以使用GFAPI :: get_entry函数从条目ID中获取条目对象。