Support » Plugins » Can’t get PHPEnkoder to work.

  • Resolved fantasticteam


    So I’ve installed PHPEnkoder, activated it, and checked the settings (and left them to their defaults). I dropped a few email addresses into a post, one as plain HTML text and one in a mailto:, but neither is encrypted in the page source.

    I then tried adding [enkode] [/enkode] around an address in the post and still nothing. It just appears on the page like “[enkode][/enkode]”.

    What am I doing wrong? I’ve spent hours looking for an anti-email harvesting plugin and I’m certain this is what I’m looking for, but now I’ve stalled at the finish line. Thanks for anyone’s help!

Viewing 14 replies - 1 through 14 (of 14 total)
  • Sorry for the extremely late follow-up…is this still an issue? If not, can I ask what the problem was?

    To others: always feel free to e-mail me about any problems!

    Usually the PHP Enkoder works great for me – though you may have to enable the settings first.
    I wish it worked in sidebar widgets and custom fields though, like for a list of contacts or a custom email field. Any suggestions on how to do this are welcome.

    It’s a little technical, but the plugin is set up to export a few of its functions: you can call enkode manually in plugins or widgets. It’s described on the webpage…let me know (perhaps by e-mail?) if it doesn’t work for you.

    Thanks for the reply.

    If I show a custom field on a page like this is is not encoded
    <?php echo (get_post_meta($post->ID, 'email', true)); ?>

    If I do the following it works (the field only contains one email):

    <?php $email= (get_post_meta($post->ID, 'email', true)); ?>
     <?php echo enkode_mailto("$email", "$email"); ?>

    The above code works when when inserted directly in sidebar.php, BUT if I try putting the above code in a sidebar widget using the Executable PHP widget plugin the encryption doesn’t work. It looks like it encodes only the “mailto:” text but it doesn’t get the $email variable – possibly a path issue with the widget. The direct approach becomes sadly complicated when using an over-engineered theme like Thematic, which is why I resorted to the Executable plugin.

    If I use the shortcode in a custom field I see the literal shortcode printed on the screen – nothing is encrypted – regardless of where that custom field is displayed.

    I’ve also tried using the Links widget for contacts to put a list of people’s names and email addresses in the sidebar. These emails are not encrypted either.

    So .. there is some difficulty with email addresses in widgets and some difficulty with the shortcodes in custom fields.

    Thanks in advance! Any suggestions or ideas are most welcome.

    So one easy kludge is to just edit the widgets to call PHP Enkoder directly. But that’s unsatisfying.

    I haven’t tested this, but try adding sidebars_widgets hook to the array of content hooks on line 206 of enkoder.php. This should (since 2.7) run the enkoder over your sidebar widgets.

    Let me know how it turns out: if it works, I can add it as a configuration option.

    Thanks for the suggestion, Michael

    Did I do this right?
    $content_hook = array('the_content', 'get_comment_text', 'sidebars_widgets');

    Unfortunately, that completely blocks the sidebar widgets from displaying at all. I tried it with a couple of simpler theses (twentyten, American Bones) to make sure it wasn’t a theme problem.

    Oh well — For now I guess I’ll just hack the sidebar. If I hack the widgets I’m afraid the changes will get lost at the next upgrade.

    I suspect that the ideal solution to this is not a simple fix.

    Yeah, that looks right…I’m not sure why it would hide the sidebars entirely. It could be a filter ordering issue, or a problem in your widgets…I’m not sure.

    I won’t have time to spend on debugging this until some time next week. If you haven’t heard back from me by next weekend, ping this thread or send me an e-mail. 🙂

    Hi Michael – Can’t find your email address anywhere.

    I’m still looking for a way to encrypt email addresses in custom fields and/or sidebar widgets. Many thanks!

    Got it working! — here’s how:

    global $post;
    $metafield= (get_post_meta($post->ID, 'keyname', true));
    echo enkode_plaintext_emails($metafield); ?>

    The above code will enkode an email address that appears in a custom field along with other text. The global $post; line allows the Executable PHP widget to recognize the $post->ID.

    Using enkode_mailto works only for fields with a single email – it doesn’t enkode fields with additional text. The plaintext option does not encode everything correctly if there is already a “mailto:” link in the field, but since we won’t be needing those thanks to PHP Enkoder, that won’t be a problem.

    Thanks for pointing me in the right direction!

    Glad you figured it out! Just to be clear (for, you know, posterity): you put that snippet in a widget that simply executes arbitrary PHP?

    If you do a pass with enkode_mailtos before enkode_plaintext_emails, you should catch mailto links before the plaintext enkoding pass.



    Michael, If I want to just use this to encode an email thats stored in a custom field, can I use what is written above –

    <?php $email= (get_post_meta($post->ID, 'email', true)); ?>
     <?php echo enkode_mailto("$email", "$email"); ?>

    Doesn’t seem to work for me. I just get the actual address.. am I wrong to expect something different. I tried simple mail encoder but this doesnt work with custom field values. Thanks in advance 🙂



    Yes Michael – Hi Will —

    Look at the snippet I posted above – use enkode_plaintext_emails instead of (or after, as Michael suggests) enkode_mailto

    assuming that your custom field is named ’email’

    global $post;
    $email=(get_post_meta($post->ID, 'email', true));
    echo enkode_plaintext_emails($email); ?>

    I use the Executable PHP widget to load this code in the sidebar.



    PS: I think you really need that global $post; line in order to grab the post id in the sidebar



    I was going to suggest using webmystery’s solution, but you beat me to it. 🙂

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Can’t get PHPEnkoder to work.’ is closed to new replies.