Don’t feel bad, there’s been more than one morning I’ve poured my first cup of coffee before setting down the mug.
I’m not sure what your code looks like, seems like every example in this topic is different.
But as a general rule, unless you are writing hacky quick-and-dirty one-time-use throw away code for your own personal use (did I use enough adjectives to convey how much a Bad Practice it is?) you want to not have a function output any HTML.
You want to have the function return something.
If you have procedural code with conditionals, you can get away with outputting HTML from within the conditionals.
Still not best practice, but commonly enough done. eg.
Hello oddz, Money? no money involved, I could not make money coding … lol, my site with a wordpress theme, making a few beneficial changes. best wishes
Hello Mittineague, Good to hear from you, I purchased a domain with this theme on it, so not an actual direct purcahase, yet theme support has been kind by giving small amounts of code and pointing me in the right direction, yet not complete coding, so that is why I am here, Mittineague your help is greatly appreciated
That code works well to notify a User “Please upload a Profile Photo”
Yet I wanted to prevent Users without a profile photo from sending messages.
So I have added the same conditional code to the message function:
public static function addMessage($ID, $user, $message) {
$user_id = get_current_user_id();
$avatar=ThemexCore::getUserMeta($user_id, 'avatar');
if(empty($avatar)) {
$message=trim(preg_replace($filters, '', $message));
}
You will see it also has the $message last line, to use the themes error messages:
self::updateMembership($ID, 'messages', -1);
} else {
ThemexInterface::$messages[]=__("You've been added to the ignore list", 'theme');
}
} else {
ThemexInterface::$messages[]=__('Message field must not be empty', 'theme');
}
} else {
ThemexInterface::$messages[]=__('You have exceeded the number of messages', 'theme');
}
if(empty(ThemexInterface::$messages)) {
wp_redirect(themex_url());
exit();
}
}
Yet when I try to add 1 more error message, I get an “Internal Error”
self::updateMembership($ID, 'messages', -1);
} else {
ThemexInterface::$messages[]=__("You've been added to the ignore list", 'theme');
}
} else {
ThemexInterface::$messages[]=__('Message field must not be empty', 'theme');
}
} else {
ThemexInterface::$messages[]=__('You must upload a Profile Photo to send messages', 'theme');
}
} else {
ThemexInterface::$messages[]=__('You have exceeded the number of messages', 'theme');
}
if(empty(ThemexInterface::$messages)) {
wp_redirect(themex_url());
exit();
}
}