• Resolved irarab

    (@irarab)


    I am trying to use antispambot to encode my email address in widget text using a short code as per Function_Reference/antispambot

    My website is legalmarketingplus.com

    It is still under development. I tried to put my email in the header as “info AT legalmarketingplus.com”. This is in my functions.php

    /**
     * Hide email from Spam Bots using a shortcode.
     *
     * @param array  $atts    Shortcode attributes. Not used.
     * @param string $content The shortcode content. Should be an email address.
     *
     * @return string The obfuscated email address.
     */
    function wpcodex_hide_email_shortcode( $atts , $content = null ) {
    	if ( ! is_email( $content ) ) {
    		return;
    	}
    
            // Test to see what antispambot returns. This works.
            // I am getting encoded email.
           	$fh = fopen('/home3/digitalwiz/tmp/testlog.txt',"a+");
    	fwrite($fh,antispambot( $content ));
    	fclose($fh);
    
    	return '<a href="mailto:' . antispambot( $content ) . '">' . antispambot( $content ) . '</a>';
    }
    
    add_shortcode( 'email', 'wpcodex_hide_email_shortcode' );
    
    // You can also use this in a plain text widget if you add this filter to your function file as well.
    
    add_filter( 'widget_text', 'shortcode_unautop');
    add_filter( 'widget_text', 'do_shortcode');
    
    /*
    To use this in your WordPress Content area all you have to do it wrap it in a short code.
    
    [email][email protected][/email]
    
    */

    I put a test in to write antispambot( $content ) to a text file. It is writing the encoded email address to the text file but the source code has the regular email address. I am using the shortcode [email]. This is in widget text.

    I checked using “Debug Bar Actions and Filters Addon” and the only callbacks on widget_text are:

    • balanceTags
    • shortcode_unautop
    • do_shortcode

    Thank you in advance for all of your help.

Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Email Antispambot’ is closed to new replies.