【发布时间】:2016-08-31 23:14:24
【问题描述】:
重力表单提供了一种从文件上传器附加文件的方法(请参见下面的代码),但是我如何更改此代码以简单地从隐藏字段值附加我自己的 PDF 文件,或者只是将 pdf 文件粘贴到此代码中?我尝试了几件事,但没有奏效。任何帮助将不胜感激!
add_filter( 'gform_notification', 'change_user_notification_attachments', 10, 3 );
function change_user_notification_attachments( $notification, $form, $entry ) {
//There is no concept of user notifications anymore, so we will need to target notifications based on other criteria, such as name
if ( $notification['name'] == 'User Notification' ) {
$fileupload_fields = GFCommon::get_fields_by_type( $form, array( 'fileupload' ) );
if(!is_array($fileupload_fields))
return $notification;
$attachments = array();
$upload_root = RGFormsModel::get_upload_root();
foreach( $fileupload_fields as $field ) {
$url = $entry[ $field['id'] ];
$attachment = preg_replace( '|^(.*?)/gravity_forms/|', $upload_root, $url );
if ( $attachment ) {
$attachments[] = $attachment;
}
}
$notification['attachments'] = $attachments;
}
return $notification;
}
【问题讨论】: