Viewing 30 posts - 1 through 30 (of 39 total)
  • Author
    Posts
  • #1422579

    Hi
    In WordPress there is a function to prevent SPAM on Email addresses:

    But when we use for example a button in Enfold with a link to an email adress, this is not possible.

    Does Enfold protect emails in buttons or how we can protect them?

    Thanks very much.

    Best regards
    Mike

    #1422611

    Hey Michael,

    Thank you for the inquiry.

    You could modify the enfold/config-templatebuilder/avia-template-builder/php/class-generic-helper.php and around line 442, look for this code.

    //	check for e-mail
    				if( strpos( $link[1], '@' ) !== false && strpos( $link[1], '://' ) === false )
    				{
    					return 'mailto:' . $link[1];
    				}
    

    Wrap the email address with the antispambot function.

    //	check for e-mail
    				if( strpos( $link[1], '@' ) !== false && strpos( $link[1], '://' ) === false )
    				{
    					return 'mailto:' . antispambot($link[1]);
    				}
    

    Best regards,
    Ismael

    #1422705

    Hi Ismael
    Can I also copy the class-generic-helper.php in the Child Theme for not overwriting the original file?
    And then every Email Link in Enfold (Buttons and so on) wil wrapped with the antispambot function?
    Will this be a functionality in future for that we can activate/deactivate it without overwriting PHP files?
    Best regards
    Mike

    #1422733

    Hi,

    Thank you for the update.

    Yes, all email links will be wrapped with the antispambot function. Unfortunately, you cannot override the file in the child theme. We will forward this thread to the team for further consideration.

    Best regards,
    Ismael

    #1422753

    Hi Ismael
    Would be nice, if the team can implement some functionality in Enfold because it is not very cool, when we have to overwrite files of the theme, because after every update this would be overwritten…
    Best regards
    Mike

    #1422764

    but there are 3times settings for '@'
    do you think it is best to replace all of them ;)

    but this is only for manually inserted Links in ALB Elements?
    Have you tested that ?

    #1422879

    Hi,

    Thank you for the update.

    @Guenni007: What do you mean by “3times settings for ‘@’”? You are correct. The modification above is only applicable for manually inserted links. We could also add this function to check if the link is an email address.

    // https://developer.wordpress.org/reference/functions/is_email/

    We have forwarded the thread to our channel for further consideration. In case you prefer not to implement or test the suggestion above, please explore the possibility of using a plugin.

    Best regards,
    Ismael

    #1422994

    on that php you mentioned – the if-clause:
    if( strpos( $link[1], '@' ) !== false
    eachtime for $link[0] == 'manually'
    we had 3 times that check.

    and maybe it is better to replace it to:
    return 'mailto:' . antispambot($link[1],1);
    because i do not see any difference in the DOM when applying it without. Or does even the sourcecode show then transformed html entities
    with the 1 i see:

    the shortcode i have for emails inside text blocks :

    function obfuscate_emails($atts, $content = null) {
        if (!is_email($content)) {
            return;
        }
        return '<a href="mailto:' . antispambot($content,1) . '">' . antispambot($content) . '</a>';
    }
    add_shortcode('email', 'obfuscate_emails');

    i had to use then as [email] (Email address hidden if logged out) [/email]

    #1423083

    Hi,

    we had 3 times that check.

    You need to replace the condition inside the get_url function, around line 442 as previously mentioned. However, I didn’t notice that I was using an older version of the theme for testing. In the latest version, the condition is located around line 468.

    because i do not see any difference in the DOM when applying it without.

    I read that Chrome automatically decodes HTML entities, so you may not see the difference, but I’m not sure if this information is accurate. Yes, adding the second parameter helps.

    Thanks for helping.

    Best regards,
    Ismael

    #1423152

    Hi again
    So, for text blocks I can use the shortcode mentionned by @Guenni007
    For buttons I have to change the code in enfold/config-templatebuilder/avia-template-builder/php/class-generic-helper.php and I have to do it after every Enfold update again, correct?
    Or can you recommend a plugin that prevent all emails in text blocks, buttons and so on?
    Best regards
    Mike

    #1423358

    Hi,

    For buttons I have to change the code in enfold/config-templatebuilder/avia-template-builder/php/class-generic-helper.php and I have to do it after every Enfold update again, correct?

    We’re considering adding this modification in the next patch. Please keep the changes for now.

    Best regards,
    Ismael

    #1423456

    Hi Ismael
    Thanks very much.
    If it would be in the next patch, would you implement it only for buttons or also for normal text elements?
    Best regards
    Mike

    #1423491

    Hi,

    It will be implemented for every element with the Link Settings.

    Best regards,
    Ismael

    #1423518

    Hi Ismael
    Ok, very good. So we will wait for the next patch ;-)
    Best regards
    Mike

    #1423573

    Hi
    As I saw, you implemented this now in the newest Enfold version 5.6.7.
    What ist the difference between avf_obfuscate_email_link and avf_obfuscate_email_link_hex_encoding ?
    Best regards
    Mike

    #1423632

    Hi,

    You can enable the antispambot option using avf_obfuscate_email_link filter. This feature is disabled by default. To adjust the value of the hex_encoding parameter, you can use avf_obfuscate_email_link_hex_encoding, as detailed in the antispambot documentation.

    // https://developer.wordpress.org/reference/functions/antispambot/

    Best regards,
    Ismael

    #1423658

    Hi Ismael
    Okey. Can you give me an example, how we have to activate and configure it? ;-)
    Best regards
    Mike

    #1423666

    Hi,

    To activate, just add this code in the functions.php file.

     add_filter(‘avf_obfuscate_email_link’, ‘__return_true’);
    

    And to adjust the hex_encoding parameter, use this.

    add_filter('avf_obfuscate_email_link_hex_encoding', function($hex) {
        return 0;
    }, 10, 1);
    

    Best regards,
    Ismael

    #1423672
    #1423675

    Hi all
    Thanks very much.
    For what is this hex encoding? This I still do not understand ;-)
    Best regards
    Mike

    #1423760

    Hi,

    For what is this hex encoding?

    It’s the value used in the rand function inside the antispambot function.

    // Line 2911: https://core.trac.wordpress.org/browser/tags/6.3/src/wp-includes/formatting.php#L2911
    // Line 2914: https://core.trac.wordpress.org/browser/tags/6.3/src/wp-includes/formatting.php#L2914

    This is the manual for the rand function.

    // // https://www.php.net/manual/en/function.rand.php

    The returned value (0 to 2) of the rand function determines the execution of these conditions.

    if ( 0 == $j ) {
    	                        $email_no_spam_address .= '&#' . ord( $email_address[ $i ] ) . ';';
    	                } elseif ( 1 == $j ) {
    	                        $email_no_spam_address .= $email_address[ $i ];
    	                } elseif ( 2 == $j ) {
    	                        $email_no_spam_address .= '%' . zeroise( dechex( ord( $email_address[ $i ] ) ), 2 );
    	                }
    

    If you want to check the functions that are executed inside these conditions, please see the links below.

    // https://www.php.net/manual/en/function.ord.php
    // https://www.php.net/manual/en/function.dechex.php
    // https://developer.wordpress.org/reference/functions/zeroise/

    Best regards,
    Ismael

    #1423808

    HI Ismael
    Thanks for the informations.
    But which value do you recommend to use?
    Best regards
    Mike

    #1423871

    Hi,

    We recommend setting it to 1, as this will actually obscure the email address. Setting it to 0 will only convert each character to its HTML entity code, which most browsers automatically decode back to the actual symbols or letters.

    hex_encoding: 1

    <a href="mailto:%74%65%73%74%40te%73t%2e%63%6fm">Click me</span></a>
    

    hex_encoding: 0

    <a href="mailto: (Email address hidden if logged out) "></a>
    

    Best regards,
    Ismael

    #1423880

    Hi Ismael
    Okey, thank you very much. We will try this out.
    Best regards
    Mike

    #1424006

    Hi,
    Glad Ismael could help, please let us know if you need further help or if we should close this thread.

    Best regards,
    Mike

    #1424303

    Hi Mike
    I just added this code on a website to test it.

    How can I activate for an ALB element?

    When we have buttons with links like "mailto: (Email address hidden if logged out) " or "mailto: (Email address hidden if logged out) ?subject=test" there happens nothing.

    When we use the shortcode [av_email_spam url=" (Email address hidden if logged out) " hex_encoding="1"]readable info[/av_email_spam] there happens not much.

    For example the mail (Email address hidden if logged out) will be samariter%40samariter-kallnach.ch.

    Best regards
    Mike

    #1424333

    Hi,
    Did you create this shortcode yourself, I don’t see a reference to this in the solution from Günter above
    When I read the Github avf_obfuscate_email_link filter it is intended for buttons with email links, and when I test it seems to work correctly:
    Enfold_Support_3817.jpeg
    Enfold_Support_3819.jpeg
    This is the filter that I added to my child theme:

    function custom_avf_obfuscate_email_link_hex_encoding( $hex_encoding, $e_mail )
    {
    	$hex_encoding = 1;
    
    	return $hex_encoding;
    }
    add_filter( 'avf_obfuscate_email_link_hex_encoding', 'custom_avf_obfuscate_email_link_hex_encoding', 10, 2 );
    
    function custom_avf_obfuscate_email_link( $obfuscate, $e_mail )
    {
    	$obfuscate = true;
    
    	return $obfuscate;
    }
    add_filter( 'avf_obfuscate_email_link', 'custom_avf_obfuscate_email_link', 10, 2 );

    Try using the filter instead of your shortcode.

    Best regards,
    Mike

    #1424343

    Hi Mike
    Ah now I see the problem.
    When I set the link like (Email address hidden if logged out) it works fine.
    But when I set the link like mailto: (Email address hidden if logged out) it does not work.
    The problem is, that there are some cases it only works with the addition mailto:
    For example when we want to set the subject and the body, like mailto: (Email address hidden if logged out) ?subject=your_subject&body=your_body
    Or when we want to set an email address under the social services of a team member.
    It would be nice, if this filter also works in this cases.
    Best regards
    Mike

    #1424346

    Hi,
    Thanks for the feedback, in buttons the email address is automatically recognized so the “mailto:” is not needed, but the question mark for adding a subject line & email body text breaks this function. I have submited this issue to the Dev Team for their review. I also noted that you want this to work for email addresses in other fields.
    We will repliy back when a solution is found, thank you for your patience.

    Best regards,
    Mike

    #1424347

    Hi Mike
    Yes, this would be very nice, if it also would work with subject and body and also in other fields like social links in teams.
    Briefly summarized it should also work when we add mailto: before the email address.
    Best regards
    Mike

Viewing 30 posts - 1 through 30 (of 39 total)
  • The topic ‘Prevent SPAM on Email Buttons’ is closed to new replies.