WordPress.org

Ready to get started?Download WordPress

Forums

HumansNotBots - Easy, Accessible Email Cloaker
WP throws a warning (9 posts)

  1. hussong
    Member
    Posted 3 years ago #

    After activating HumansNotBots, WordPress 3.0.1 throws a warning on every page:

    Warning: join() [function.join]: Invalid arguments passed in [...]/wp-includes/post-template.php on line 361
    class="">

    Note: I've removed the actual path to wp [...] in the quote.
    HTH :-)

  2. zingming
    Member
    Plugin Author

    Posted 3 years ago #

    Thanks. It should be fixed now in version 1.1.

  3. hussong
    Member
    Posted 3 years ago #

    Great, it works like a charm now, many thanks for the quick fix!

    And thank you for creating this plugin. It provides the sanest way of managing email addresses for editors (no shortcodes, just enter name AT domain DOT com - everybody gets that) and is easy for readers as well :-)

  4. hussong
    Member
    Posted 3 years ago #

    Update: Unfortunately, it works well at first sight.

    With the default WordPress 3.0 Twenty Ten theme, the plugin empties the body class:

    before
    <body class="home blog logged-in">

    after
    <body class="" onload="HumansNotBots()" id="htmlbody">

    With the current Hybrid theme, it seems to interfere with Hybrid's own action hooks--it doesn't insert anything.

    There must be a better way to load and run the script, maybe wp_enqueue_script?

    http://codex.wordpress.org/Function_Reference/wp_enqueue_script

    HTH :-)

  5. zingming
    Member
    Plugin Author

    Posted 3 years ago #

    Thanks again. I fixed that bug and added support for the Hybrid theme in version 1.2.

    wp_enqueue_script is just a better way of including the script in the html head, but it doesn't run it. However, your tip was helpful, because I used it in 1.2 to improve the way I added the script to the html head.

  6. hussong
    Member
    Posted 3 years ago #

    Thank you for the super-fast update! In the meantime, I had gone ahead and added a few changes myself.

    In humansnotbots.js, I used getElementsByTagName to avoid having to insert an id attribute into the body element:

    function HumansNotBots()
    {
        var htmlbody = document.getElementsByTagName('body')[0];
        var rep = '<a href="mailto:$1@$2.$3">$1@$2.$3</a>';
        var newInnerHTML = htmlbody.innerHTML.replace(/([a-zA-Z0-9._%+-]+)\sAT\s([a-zA-Z0-9.-]+)\sDOT\s([a-zA-Z]{2,4})/g, rep);
        htmlbody.innerHTML = newInnerHTML;
    }

    In humansnotbots.php, I used wp_enqueue_script:

    /* Add javascript to html head */
    function add_header () {
        if ( !is_admin() )
      	{
            wp_enqueue_script( 'humansnotbots', WP_PLUGIN_URL .'/'. plugin_basename(dirname(__FILE__)) . '/humansnotbots.js', '', '1.2', false );
        }
    }
    add_action( 'wp_print_scripts', 'add_header' );

    using the tutorial here: http://weblogtoolscollection.com/archives/2010/05/06/adding-scripts-properly-to-wordpress-part-1-wp_enqueue_script/

    And to call the script, I added a function that inserts js upon the wp_footer event, which then calls the function HumansNotBots if the body has loaded:

    /* Add onload after body has loaded and call function */
    function add_onload() {
        ?>
        <script type="text/javascript">
        my_onload_callback = HumansNotBots(); // call function
    
        if( typeof jQuery == "function" ) {
            jQuery(my_onload_callback); // document.ready
        } else {
            document.getElementsByTagName('body')[0].onload = my_onload_callback; // body.onload
        }
        </script>
        <?php
    }
    add_action( 'wp_footer', 'add_onload' );

    using a solution I found here: http://wordpress.stackexchange.com/questions/879/adding-onload-to-body/882#882

    This should be a lot safer across different themes and plugins. Feel free to use this code for one of the next update :-)

  7. zingming
    Member
    Plugin Author

    Posted 3 years ago #

    Thanks. I should have thought to use getElementsByTagName instead!

    For the next update, I have your version of humansnotbots.js. For humansnotbots.php, I now have this (inspired from your suggestions):

    class HumansNotBots {
          function add_to_footer () {
          	       $js_url = WP_PLUGIN_URL .'/'. plugin_basename(dirname(__FILE__)) . '/humansnotbots.js';
          	       echo '<script type="text/javascript" src="' . $js_url .'"></script>' . "\n";
        	       echo '<script type="text/javascript">' . "\n\twindow.onload = HumansNotBots;\n</script>\n";
          }
    
    }
    
    $humansnotbots = new HumansNotBots();
    add_action('wp_footer', array($humansnotbots, 'add_to_footer'));
    ?>

    I will let you inspect the code/test this time before I push the update. :)

  8. hussong
    Member
    Posted 3 years ago #

    Thanks for the update. Yeah, I think it makes a lot of sense to not mess with the body-tag at all. And I guess I'd rather stay away from the window.onload event handler to prevent conflicts with other scripts. My knowledge of JavaScript is quite limited though...

  9. zingming
    Member
    Plugin Author

    Posted 3 years ago #

    1.3 is out.

    humansnotbots.php:

    class HumansNotBots {
          function add_to_footer () {
          	       $js_file_url = WP_PLUGIN_URL .'/'. plugin_basename(dirname(__FILE__)) . '/humansnotbots.js';
          	       echo '<script type="text/javascript" src="' . $js_file_url .'"></script>' . "\n";
          }
    }
    
    $humansnotbots = new HumansNotBots();
    add_action('wp_footer', array($humansnotbots, 'add_to_footer'));

    humansnotbots.js:

    function HumansNotBots() {
        var htmlbody = document.getElementsByTagName('body')[0];
        var rep = '<a href="mailto:$1@$2.$3">$1@$2.$3</a>';
        var newInnerHTML = htmlbody.innerHTML.replace(/([a-zA-Z0-9._%+-]+)\sAT\s([a-zA-Z0-9.-]+)\sDOT\s([a-zA-Z]{2,4})/g, rep);
        htmlbody.innerHTML = newInnerHTML;
    }
    
    HumansNotBots();

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic