Okay
  Public Ticket #1579012
PHP function in text field
Closed

Comments

  • Marius started the conversation

    Hi,

    I want to use this method to secure plain mail adresses:
    https://gist.github.com/irazasyed/6621341

    I added the following code to my functions.php:

    function hide_email($email)
    { $character_set = '+-.0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz';
      $key = str_shuffle($character_set); $cipher_text = ''; $id = 'e'.rand(1,999999999);
      for ($i=0;$i<strlen($email);$i+=1) $cipher_text.= $key[strpos($character_set,$email[$i])];
      $script = 'var a="'.$key.'";var b=a.split("").sort().join("");var c="'.$cipher_text.'";var d="";';
      $script.= 'for(var e=0;e<c.length;e++)d+=b.charAt(a.indexOf(c.charAt(e)));';
      $script.= 'document.getElementById("'.$id.'").innerHTML="<a href=\\"mailto:"+d+"\\">"+d+"</a>"';
      $script = "eval(\"".str_replace(array("\\",'"'),array("\\\\",'\"'), $script)."\")";   $script = '<script type="text/javascript">/*<![CDATA[*/'.$script.'/*]]>*/</script>';
      return '<span id="'.$id.'">[javascript protected email address]</span>'.$script;
    }


    Usually (e.g. on a normal bootstrap website) I insert my mail adress like this:

    <?php echo hide_email('[email protected]'); ?>

    How can I use this method in Salient and Visual Composer?
    The php code above doesn't work in an unfiltered html field.

    Thanks in advance.

  •  3,179
    Andrew replied

    Hi mdgomes,

    In general its not possible to add PHP code to the pages content areas on wordpress.

    What we can think of now is maybe add that hide_email function to an existing file or something that will place it where you want.

    Alternatively you can use a plugin to add the capability to place PHP code on the page content area and see if it offers a shortcode option so that you can maybe add the shortcode to a text block editor when the editor is in text mode.

    Hope you can work it from there. 

  • Marius replied

    Thanks, I avoided to use own PHP code and use the following Plugin:

    https://de.wordpress.org/plugins/email-address-encoder/

    Works as intended =)

  •  3,179
    Andrew replied

    Hey there,

    Thanks for reaching in,

    That's awesome. Please be sure to reach in incase you encounter another issue,

    Regards