Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This is probably pretty simple, but...

I want to use the WP function antispambot not on get_the_author_email but on a value in a field I added to User Profile called publicemail. Everything I've tried throws a php error.

This is the antispambot usage shown in the WP docs:

echo antispambot(get_the_author_email());

And this is the complete function I'd like to get to work with antispambot and have it encode publicemail:

<?php
if ( !empty( $curauth->publicemail )){
echo 'Email &nbsp; <a href="mailto:' .$curauth->publicemail.' ?subject=Webmail">
<img src="' . get_bloginfo('template_url') . '/images/email_16.png"></a>'; }
?>
share|improve this question
    
And where's the antispambot usage? Btw: Afaik, you should only use it on $curauth->publicemail, which should be the actual email. –  kaiser Feb 28 '12 at 8:53
    
Exactly; I only want to use antispambot on $curauth->publicemail, i.e. antispambot($curauth->publicemail) which doesn't work. –  songdogtech Feb 28 '12 at 14:14
    
What does "doesn't work" exactly mean? –  kaiser Feb 28 '12 at 14:20
    
No display of an email address - either plain text or encoded - in between the mailto: link and the ?subject=Webmail text. –  songdogtech Feb 28 '12 at 17:56
    
wow I can't believe they included that function in the core :) –  onetrickpony Feb 28 '12 at 19:51

1 Answer 1

up vote 1 down vote accepted

As the Codex states for the antispambot() function:

Return Values (string) Converted email address.

You have to do one of the following:

echo antispambot( $curauth->publicemail );
// OR...
print antispambot( $curauth->publicemail );

So your full example would look like the following:

if ( ! empty( $curauth->publicemail ) )
{
    echo 'Email <a href="mailto:'.antispambot( $curauth->publicemail ).'?subject=Webmail">
    <img src="'.get_bloginfo('template_url').'/images/email_16.png"></a>'; 
}

About the difference between echo, print and (just) return

  1. echo and print are just synonyms/alias for each other and actually display something on the screen. The only difference in usage is, that you can't use echo in combination with return.
  2. return just gives something back as a functions output. In combination with print, a function can actually display something in a template, etc.
share|improve this answer
    
Ah, that was the problem. Works fine now. Thanks! –  songdogtech Feb 28 '12 at 23:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.