• Resolved TrishaM

    (@trisham)


    Greetings – once again I need help from an experienced PHP coder.

    I’d like to use either a short code (preferred) or a custom field, to enter a name, for example [phil] and have a function turn that into an email address that is obfuscated using a table of such names=>obfuscated email addresses that I can set up ahead of time in a separate text file or .php file…..

    This is for a multi-user site for a non-profit org, and they will be entering events with event coordinator contact info – I don’t really want them entering an email address directly (because I also manage their email and don’t want to deal with high amounts of spam that could result from it), but they are not tech savvy enough to consistently remember to use an obfuscated email address (if they can even remember how to do it right in the first place).

    So to make it easy for them I’d like them to just be able to enter a short code, or secondarily a custom field, and have a function that does a “lookup” and replaces the short code or custom field with the obfuscated email address. There is a limited list of event coordinators so I can easily maintain the list used to to the lookup from.

    I hope I’m explaining this well enough….will elaborate if questions. Any suggestions?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Thread Starter TrishaM

    (@trisham)

    Bump – anyone? It seems like a simple short code function to do a lookup and replace a short code with other text should be a simple thing for a decent PHP coder……any takers?

    add_shortcode( 'person', 'person_shortcode' );
    
    function person_shortcode( $attr ) {
    
    	if ( $attr['name'] == 'justin' )
    		$email = 'name@email.com';
    
    	elseif ( $attr['name'] == 'johnny' )
    		$email = 'johnny@email.com';
    
    	if ( $email )
    		return antispambot( $email );
    }

    Then, enter the shortcode like: [person name="justin"].

    Or, you could create individual people shortcodes:

    add_shortcode( 'justin', 'justin_shortcode' );
    
    function justin_shortcode() {
    	return antispambot( 'justin@email.com' );
    }

    And use like: [justin].

    Was curious after reading the above, so i echo’ed out the result of a string passed to antispambot()…

    The output is no different…
    test@test.com
    Output after antispambot()…
    test@test.com

    Did i miss something?

    @t31os_

    Look at the HTML source.

    That’s just an example of something’s that’s built into WP. You can, of course, exchange that with any other function.

    I did look at the source, both the same…

    Which is why i was a little puzzled… 🙁 …

    Are you getting different results?

    Thread Starter TrishaM

    (@trisham)

    @greenshady – thank you so much! I think I can use the first example and where you show the $email = ‘name@email.com’; I can replace that ‘name@email.com’ with the obfuscated address – I’ll test it to see if it works…

    I’m not familiar with antispambot – I know it’s in the WP core code as a function and what it does, just like t3los_ I haven’t been able to successfully use it, so I use an application that gives me the HTML code that looks like this:

    Nevermind it won’t display the HTML obfuscation correctly, it just displays the mailto link here….sigh….

    But it displays and works correctly like any other email link – I’m sure it wouldn’t stop the very smartest spambots but it sure stops most…..

    I’ll give this a go and let you know how it works….

    many thanks again!

    Thread Starter TrishaM

    (@trisham)

    UPDATE: Okay the first example given by greenshady works very well – I used it as is, including the use of antispambot instead of the other way I was thinking of, and it does display the email correctly while randomly obfuscating letters in the source code, which is great.

    The only downside is the the email is not a clickable (mailto) link. The application I’ve always used in the past to create obfuscated email addresses adds the a tag to make it clickable – all using HTML to keep it obfuscated – but when I tried to use that, it just displayed the HTML, not the email address….

    SO is there a way to add in the <a href=” etc to make it clickable?

    Many thanks again for all your help!

    Thread Starter TrishaM

    (@trisham)

    Bump – any ideas on how to make the newly obfuscated email address (using antispambot) clickable?

    Thread Starter TrishaM

    (@trisham)

    I still need some help – just need to be able to have the newly obfuscated email link clickable….

    Thread Starter TrishaM

    (@trisham)

    Bump……Anybody? There MUST be a way to use antispambot to obfuscate a mailto link and still have it be clickable…..

    Please?

    @trisham

    I think PrivateDaddy would work for you (obfuscated yet clickable mailto links). check it out at privatedaddy.com. There’s also a WordPress plug-in

    HTH,

    ND

    @trisham

    See “For WordPress” in the top menu bar

    skyew

    (@skyew)

    @trisham – I think this would work:

    <a href="mailto:<?php echo antispambot($email) ?>"><?php echo antispambot($email) ?></a>

    where $email is your email address

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Need help obfuscating email with PHP’ is closed to new replies.