如何将 pdf 文件附加到 Gravity Forms 通知?

How do I attach a pdf file to a Gravity Forms Notification?

Gravity forms 提供了一种从文件上传器附加文件的方法(参见下面的代码),但是我如何更改此代码以简单地从隐藏字段值附加我自己的 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;
  }

根据该代码,这样的事情应该可行。将 $url 值替换为 PDF 中的 URL。

add_filter( 'gform_notification', 'change_user_notification_attachments', 10, 3 );
function change_user_notification_attachments( $notification, $form, $entry ) {

    if ( $notification['name'] == 'User Notification' ) {
        $url = 'http://yoursite.com/path/to/file.pdf';
        $notification['attachments'][] = $url;
    }

    return $notification;
}