繁体   English   中英

Gravity Forms 添加附件到用户通知

[英]Gravity Forms add attachment to user notification

我正在使用 Gravity forms 中的以下代码将文件附加到用户的通知中:

add_filter( 'gform_notification_55', 'add_attachment_pdf', 10, 3 ); //target form id 2, change to your form id
function add_attachment_pdf( $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 or subject
    if( $notification['name'] == 'User Notification' ) {
        //get upload root for WordPress
        $upload = wp_upload_dir();
        $upload_path = $upload['basedir'];

        //add file, use full path , example -- $attachment = "C:\\xampp\\htdocs\\wpdev\\wp-content\\uploads\\test.txt"
        $attachment = $upload_path . '/2020-RSPA-POS-Channel-KPI-Study-Update-Post-COVID.pdf';

        GFCommon::log_debug( __METHOD__ . '(): file to be attached: ' . $attachment );


    }
    //return altered notification object
    return $notification;
}

除了向表单 55 添加附件,如示例所示,我还需要向不同的表单添加不同的附件。 我已经更改了表单 ID 以反映这一点,并第二次将代码复制/粘贴到函数文件中,但该站点中断了这样做。 上述工作按预期工作,就其本身而言。 如何多次使用过滤器?

最简单的方法(但不是最漂亮的)是复制所有内容并更改 function 名称。 这是一个示例,我在两个实例中更新 function 名称以匹配表单 ID:

add_filter( 'gform_notification_55', 'add_attachment_pdf_55', 10, 3 );
function add_attachment_pdf_55( $notification, $form, $entry ) {
    ...
}

add_filter( 'gform_notification_56', 'add_attachment_pdf_56', 10, 3 );
function add_attachment_pdf_56( $notification, $form, $entry ) {
    ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM