【问题标题】:Gravity Forms add attachment to user notificationGravity Forms 向用户通知添加附件
【发布时间】:2020-09-06 01:25:04
【问题描述】:

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

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 以反映这一点,并第二次将代码复制/粘贴到函数文件中,但该站点中断了这样做。上述工作按预期工作,就其本身而言。如何多次使用过滤器?

【问题讨论】:

    标签: php wordpress function filter gravityforms


    【解决方案1】:

    绝对最简单的方法(但不是最漂亮的)是复制所有内容并更改函数名称。这是一个示例,我在两个实例中更新函数名称以匹配表单 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 ) {
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 2021-05-19
      • 1970-01-01
      • 2017-09-14
      • 1970-01-01
      • 2015-07-02
      • 1970-01-01
      • 1970-01-01
      • 2016-06-09
      • 2021-12-02
      相关资源
      最近更新 更多