• Resolved certainlyakey

    (@certainlyakey)


    Hello! Thank you for the plugin, I use it extensively.

    On one of my sites there’s a custom field designed for all sorts of contact information, optionally including emails. These emails as the client is not very tech savvy will be most certainly put a plain text, without <a href="mailto:"> tag. Therefore the question, is it possible to automatically find such emails in given text (for example, with eae_encode_emails function), wrap them in a tags and then apply obfuscation. This is how it could work, on a simple text string:

    $contactstext = get_post_meta($post->ID, 'contactstext', true);
    //$contactstext = 'string... [email protected] ...string'
    if ($contactstext) {echo '<div class="contactstext">'.eae_encode_emails($contactstext).'</div>';}
    //$contactstext = 'string... <a href="mailto:OBFUSCATEDEMAIL">OBFUSCATEDEMAIL</a> ...string'

    Thanks!

    https://www.ads-software.com/plugins/email-address-encoder/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Till Krüss

    (@tillkruess)

    Yes, you can auto-link and encode all found email addresses like that:

    add_filter( 'eae_method', function() {
    	return 'encode_n_link_emails';
    });
    
    function encode_n_link_emails( $email ) {
    
    	return sprintf(
    		'<a href="%s">%s</a>',
    		eae_encode_str( 'mailto:' . $email ),
    		eae_encode_str( $email )
    	);
    
    }
    Thread Starter certainlyakey

    (@certainlyakey)

    Thank you very much! This code works, however, only for plain emails, without a tags already applied. If an email is wrapped in a, we get this in browser:
    mailto:[email protected]">[email protected]

    Plugin Author Till Krüss

    (@tillkruess)

    I’d recommend to either run strip_tags() on your custom field data before hand, that would remove all HTML tags from it, or if you want to preserve possible HTML tags, then get a plugin (or PHP function) that auto-links email addresses and after that’s done run only eae_encode_emails() on your custom field data.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Is it possible to find plain text emails and wrap them into a tag’ is closed to new replies.