Gravity Forms 向用户通知添加附件
Gravity Forms add attachment to user notification
我正在使用 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 以反映这一点,并且 copied/pasted 代码第二次进入函数文件,但是网站在这样做时中断了。上面的工作按预期进行,就其本身而言。如何多次使用过滤器?
绝对最简单的方法(但不是最漂亮的)是复制所有内容并更改函数名称。这是一个示例,我在两个实例中更新函数名称以匹配表单 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 ) {
...
}
我正在使用 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 以反映这一点,并且 copied/pasted 代码第二次进入函数文件,但是网站在这样做时中断了。上面的工作按预期进行,就其本身而言。如何多次使用过滤器?
绝对最简单的方法(但不是最漂亮的)是复制所有内容并更改函数名称。这是一个示例,我在两个实例中更新函数名称以匹配表单 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 ) {
...
}