add_filter( 'gform_notification_2', 'add_attachment_pdf', 10, 3 );
function add_attachment_pdf( $notification, $form, $entry ) {
    if( $notification['name'] == 'Melding nieuw lid' ) {
        //get upload root for WordPress
        $upload = get_home_path();
        $upload_path = $upload['basedir'];
        $jaarverlsag = $upload . '/files/APC-Jaarverslag-2018.pdf';
        $beleidsplan = $upload . '/files/APC-Beleidsplan-2019-2021.pdf';

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

        if ( file_exists( $jaarverlsag ) || file_exists( $beleidsplan ) ) {
            $notification['attachments']   = rgar( $notification, 'attachments', array() );
            $notification['attachments'][] = $jaarverlsag;
            $notification['attachments'][] = $beleidsplan;
            GFCommon::log_debug( __METHOD__ . '(): file added to attachments list: ' . print_r( $notification['attachments'], 1 ) );
        } else {
            GFCommon::log_debug( __METHOD__ . '(): not attaching; file does not exist.' );
        }
    }
    //return altered notification object
    return $notification;
}
Geef een reactie 0