WordPress.org

Forums

[resolved] Can't get PHPEnkoder to work. (15 posts)

  1. fantasticteam
    Member
    Posted 5 years ago #

    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]a@b.com[/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!

    http://wordpress.org/extend/plugins/php-enkoder/

  2. michael_greenberg
    Member
    Posted 5 years ago #

    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!

  3. webmystery
    Member
    Posted 4 years ago #

    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.

  4. michael_greenberg
    Member
    Posted 4 years ago #

    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.

  5. webmystery
    Member
    Posted 4 years ago #

    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.

  6. michael_greenberg
    Member
    Posted 4 years ago #

    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.

  7. webmystery
    Member
    Posted 4 years ago #

    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.

  8. michael_greenberg
    Member
    Posted 4 years ago #

    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. :)

  9. webmystery
    Member
    Posted 4 years ago #

    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!

  10. webmystery
    Member
    Posted 4 years ago #

    Got it working! -- here's how:

    <?php
    global $post;
    $metafield= (get_post_meta($post->ID, 'keyname', true));
    echo enkode_plaintext_emails($metafield); ?>
    </li>
    </ul>

    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!

  11. michael_greenberg
    Member
    Posted 4 years ago #

    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.

  12. willGoldstone
    Member
    Posted 4 years ago #

    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 :)

  13. webmystery
    Member
    Posted 4 years ago #

    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'

    <?php
    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.

  14. webmystery
    Member
    Posted 4 years ago #

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

  15. michael_greenberg
    Member
    Posted 4 years ago #

    I was going to suggest using webmystery's solution, but you beat me to it. :)

Topic Closed

This topic has been closed to new replies.

About this Topic