我试图使用gform_after_submission获取字段值(文件的url),然后将值传递给通知,以便将其作为附件发送。到目前为止,这就是我所拥有的:
add_action("gform_after_submission", "after_submission", 10, 2);
function after_submission($entry, $form){
$pdf = $entry["3"];
return $pdf;
}
add_filter( 'gform_notification_3', 'add_notification_attachments', 10, 3 );
function add_notification_attachments( $notification, $form, $entry ) {
if ( $notification['name'] == 'Admin Notification' ) {
$path = 'path/to/file.pdf';
$notification['attachments'] = array( $path );
}
return $notification;
}发布于 2022-10-06 13:57:01
未经测试,但不需要第一个操作,只需要通知筛选器。
add_filter( 'gform_notification_3', 'add_notification_attachments', 10, 3 );
function add_notification_attachments( $notification, $form, $entry ) {
if ( $notification['name'] == 'Admin Notification' ) {
$path = $entry['3'];
$notification['attachments'] = array( $path );
}
return $notification;
}发布于 2022-10-07 07:49:17
谢谢Dave,没有看到您更新的代码,但是有一次您告诉我如何将URL转换为路径时,下面是我所做的工作&它现在工作得很好:
function get_file_path_from_url( $file_url ){
return realpath($_SERVER['DOCUMENT_ROOT'] . parse_url( $file_url, PHP_URL_PATH ));
}
add_filter( 'gform_notification_3', 'add_notification_attachments', 10, 3 );
function add_notification_attachments( $notification, $form, $entry ) {
if ( $notification['name'] == 'Admin Notification' ) {
$path = $entry['3'];
$path = get_file_path_from_url($path);
$notification['attachments'] = array( $path );
}
return $notification;
}https://stackoverflow.com/questions/73974350
复制相似问题