-
AuthorPosts
-
October 15, 2023 at 7:48 pm #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
MikeOctober 16, 2023 at 4:35 am #1422611Hey 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,
IsmaelOctober 16, 2023 at 9:47 pm #1422705Hi 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
MikeOctober 17, 2023 at 4:24 am #1422733Hi,
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,
IsmaelOctober 17, 2023 at 8:02 am #1422753Hi 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
MikeOctober 17, 2023 at 10:05 am #1422764but 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 ?October 18, 2023 at 10:39 am #1422879Hi,
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,
IsmaelOctober 19, 2023 at 11:33 am #1422994on 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]
October 20, 2023 at 9:06 am #1423083Hi,
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,
IsmaelOctober 20, 2023 at 4:59 pm #1423152Hi 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
MikeOctober 23, 2023 at 3:24 am #1423358Hi,
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,
IsmaelOctober 23, 2023 at 6:29 pm #1423456Hi 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
MikeOctober 24, 2023 at 3:11 am #1423491Hi,
It will be implemented for every element with the Link Settings.
Best regards,
IsmaelOctober 24, 2023 at 8:44 am #1423518Hi Ismael
Ok, very good. So we will wait for the next patch ;-)
Best regards
MikeOctober 24, 2023 at 1:24 pm #1423573Hi
As I saw, you implemented this now in the newest Enfold version 5.6.7.
What ist the difference betweenavf_obfuscate_email_link
andavf_obfuscate_email_link_hex_encoding
?
Best regards
MikeOctober 25, 2023 at 4:48 am #1423632Hi,
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,
IsmaelOctober 25, 2023 at 9:25 am #1423658Hi Ismael
Okey. Can you give me an example, how we have to activate and configure it? ;-)
Best regards
MikeOctober 25, 2023 at 10:38 am #1423666Hi,
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,
IsmaelOctober 25, 2023 at 11:03 am #1423672Hi,
You also find an example here:
Best regards,
GünterOctober 25, 2023 at 11:12 am #1423675Hi all
Thanks very much.
For what is this hex encoding? This I still do not understand ;-)
Best regards
MikeOctober 26, 2023 at 11:06 am #1423760Hi,
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#L2914This 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,
IsmaelOctober 26, 2023 at 5:05 pm #1423808HI Ismael
Thanks for the informations.
But which value do you recommend to use?
Best regards
MikeOctober 27, 2023 at 3:31 am #1423871Hi,
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,
IsmaelOctober 27, 2023 at 8:35 am #1423880Hi Ismael
Okey, thank you very much. We will try this out.
Best regards
MikeOctober 29, 2023 at 12:50 pm #1424006Hi,
Glad Ismael could help, please let us know if you need further help or if we should close this thread.Best regards,
MikeNovember 1, 2023 at 11:10 am #1424303Hi 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
MikeNovember 1, 2023 at 4:17 pm #1424333Hi,
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:
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,
MikeNovember 1, 2023 at 5:59 pm #1424343Hi 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 likemailto: (Email address hidden if logged out)
it does not work.
The problem is, that there are some cases it only works with the additionmailto:
For example when we want to set the subject and the body, likemailto: (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
MikeNovember 1, 2023 at 10:08 pm #1424346Hi,
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,
MikeNovember 1, 2023 at 10:11 pm #1424347Hi 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 -
AuthorPosts
- The topic ‘Prevent SPAM on Email Buttons’ is closed to new replies.