Not sure that’s something we could realistically predict, given the custom form from your end.
However, I know we use the wp_mail() function and inside that is the wp_mail filter that you could hook onto to add your extra fields to before emailing.
Thread Starter
AJ
(@permaculturetreegeek)
Hmm, the extra fields are all created by Buddypress from the extend profiles component. I wonder about creating an array that just grabs everything and hook that into the email?
Something like this?
$current_user = wp_get_current_user();
$current_user_id = $current_user->ID;
bp_profile_field_data( array('user_id'=>$current_user_id, $user_fields=> array() ));
foreach($user_fields as $name=>$value) {
echo "<strong>".$name."</strong>"." => ";
foreach($value as $nameAr=>$valueAr) {
echo "<br /> ";
echo $nameAr." => ";
echo var_dump($valueAr);
}
}
Worth a try, I can’t say for sure how that will come out within the email, without actually adding it myself to a test instance. If it works though, go for it 🙂
Thread Starter
AJ
(@permaculturetreegeek)
I’m not sure how to add it to the email. Do you have any tips on that?
Thanks!
Are you familiar with WP hooks at all? Specifically filters?
You can intercept the “message” with the wp_mail filter and append your own stuff.
http://adambrown.info/p/wp_hooks/hook/wp_mail?version=3.6&file=wp-includes/pluggable.php
Thread Starter
AJ
(@permaculturetreegeek)
I understand hooks and filters when I read them, but writing is still a bit beyond me.
here’s an example of what I meant, with a bit of comments.
add_filter( 'wp_mail', 'myfilter' );
function myfilter( $values ) {
/*
$values will be an array.
$values['to']
$values['subject']
$values['message']
$values['headers']
$values['attachments']
*/
//Do whatever you have to do here to gather what extra content you want to add. You can append to the message like below, or you can even replace completely.
$values['message'] = $values['message'] . ' This is appended data to the message.';
return $values;
}
Thread Starter
AJ
(@permaculturetreegeek)
Cool thanks!
Question: How do I know which mail is the one sent by the plugin?
That looks like it will add extra stuff to all emails sent.
Is it possible to filter it to add stuff to specific emails only?
Thanks.
No great way, but you could use php’s strpos() to check if either of the following are in the subject: ‘Banned member registration attempt’
‘New Member Request’
As an aside, I may add a filter around some of this stuff in the future so people could intercept. This would be a good place.
Thread Starter
AJ
(@permaculturetreegeek)
OK thanks, Ill see if I can get it to work.