Skip to content

Instantly share code, notes, and snippets.

@xnau
Created March 8, 2018 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnau/caa144e6da7222ada7e2f0f0aee73677 to your computer and use it in GitHub Desktop.
Save xnau/caa144e6da7222ada7e2f0f0aee73677 to your computer and use it in GitHub Desktop.
Shows how to replace the recipient value in the "to" field of a Participants Database email template.
<?php
add_filter( 'pdbcptet-recipient_tags', 'xnau_filter_recipients' );
/**
* replaces the recipient identifier with the recipient's email address
*
* @param array $tag_list the tag replacement data
* @return array
*/
function xnau_filter_recipients( $tag_list )
{
/*
* this is the name of the field used to select the recipient
* in this example, it will contain the recipient's user ID: it
* can be another value, but it must be a unique identifier
*/
$recipient_tag = 'recipient';
// this is the identifier value that the user has chosen
$identifier = $tag_list[$recipient_tag];
// now, use the idendifier value to get the record ID
$recipient_record_id = Participants _Db::get_record_id_by_term( 'user_id', $identifier );
// and then the recipient's record data
$recipient_record = Participants _Db:get_participant( $recipient_record_id );
/* now, place the recipient's email address into the data array,
* replacing the identifier value with the email address
*/
$tag_list[$recipient_tag] = $recipient_record['email'];
// return the altered data array
return $tag_list;
}
@xnau
Copy link
Author

xnau commented Mar 8, 2018

This will give you some idea how to do a recipient replacement. It assumes that the user has a dropdown or other selector that chooses the recipient. The value the selector saves is a unique identifier to the recipient. When that chosen value comes in to the filter, it is used to get the actual email address to use.

This assumes that a) the recipient field is named "recipient" and b) the unique identifier is a field named 'user_id'. You will likely need to changes these things for it to work in your setup.

The recipient value can be any value that can be used to find the recipient's email address, you'll just have to alter the code to use whatever method is needed to convert the incoming value to an email address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment