Hello,
I was wondering I could get someone to look at a module function for me. Maybe I’ve just been trying to debug it for too long.
Here is the function:
/**
* Retrieves the notification e-mail configured for a member
**/
public function notification_email($member_id=0)
{
global $TMPL, $DB, $FNS, $LANG, $OUT;
$LANG->fetch_language_file('email_template');
$email = '';
// Set member id
if (!$member_id) {
$member_id = $TMPL->fetch_param('member_id') ? $TMPL->fetch_param('member_id') : $TMPL->fetch_param('author_id');
}
// Validate - BUG STARTS HERE
echo $member_id; // displays a 'true' value, e.g. 23
if (!$member_id) return $OUT->show_user_error('general', array($LANG->line('invalid_member_id')));
// Retrieve e-mail address
$query = $DB->query("SELECT m_field_id FROM exp_member_fields WHERE m_field_name = 'email_template_notify_email'");
$m_field_id = $query->row['m_field_id'];
$query = $DB->query("SELECT m_field_id_{$m_field_id} FROM exp_member_data WHERE member_id = ".$DB->escape_str($member_id));
if ($query->num_rows != 0) $email = $query->row['m_field_id_'.$m_field_id];
// Determine whether to var swap the value in data data
if ($TMPL AND $TMPL->tagdata and $email) {
$vars = array('notification_email' => $email);
return $FNS->prep_conditionals($FNS->var_swap($TMPL->tagdata, $vars), $vars);
}
return $email;
}
The echo statement outputs what I’d expect when a value is present, the id of the member (e.g. 23). For some reason, the following line ALWAYS gets executed:
return $OUT->show_user_error('general', array($LANG->line('invalid_member_id')));
If I remove that statement (and the surrounding if statement), member_id appears to be NULL or an empty string. I cannot for the life of me figure this out and I’m totally confused.
Any help would be much appreciated.
Thanks, Mike
It’s probably something silly, but I can’t see the bug either. Could you try var_dump’ing the variable to see what it’s being set as:
// Validate - BUG STARTS HERE
// echo $member_id; // displays a 'true' value, e.g. 23
// if (!$member_id) return $OUT->show_user_error('general', array($LANG->line('invalid_member_id')));
if( ! $member_id)
{
var_dump($member_id);
}
Also, how are you calling the function?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.