WordPress.org

Support

Support » Plugins and Hacks » Real-Time Find and Replace » [Resolved] Issue with html chars

[Resolved] Issue with html chars

  • I really appreciate the simplicity and effectiveness of your plugin.

    I have a small problem replacing html chars, because every time I save they get converted in whateer they look on the page. For example,

    &#8211 ;

    gets replaced with a dash (I’ve added a space there as WP forum also turns it into a dash, even if i write it “&amp ;#8211;” – no spaces :).

    So, every time I want to add a new replace, I need to replace the html chars in my previous replaces or they won’t work.
    Is there anything to be done about this? Maybe add a hook to the replaces array and let me add an extra array of replaces in functions.php through a filter?

    Thank you for looking into this.

    http://wordpress.org/plugins/real-time-find-and-replace/

Viewing 4 replies - 1 through 4 (of 4 total)
  • I have made myself a temporary solution. In your plugin file, I have added this code to far_ob_call function, after the is_array check:

    if (function_exists('far_get_extra')) {
    	$far_extra_replaces = far_get_extra();
    	if (is_array($far_extra_replaces))
    		foreach ($far_extra_replaces as $extra_find => $extra_replace) {
    			$farsettings['farfind'][] = $extra_find;
    			$farsettings['farreplace'][] = $extra_replace;
    		}
    }

    And in functions.php I declared my far_get_extra function which returns the array of replacements without the worry that html chars will get converted into their meanings by WP. Not sure if the $find => $replace type of array for extra replaces will work in all cases (maybe some chars aren’t allowed in keys), but it does in mine.

    I found the solution for this.
    In the end, it turns out WP has a function that prevents textarea from replacing html entities into their result: http://codex.wordpress.org/Function_Reference/esc_textarea

    Therefore, both $find and $replace vars need to be wrapped in esc_textarea() on line 115 of $real-time-find-and-replace.php, resulting in:

    echo "<p id='row$i'><label for='farfind$i'>Find:&nbsp;</label><textarea rows='3' cols='30' name='farfind[$i]' id='farfind$i'>".esc_textarea( $find )."</textarea>&nbsp;&nbsp;<label for='farregex$i'>RegEx?:&nbsp;</label><input type='checkbox' name='farregex[$i]' id='farregex$i' $regex />&nbsp;&nbsp;<label for='farreplace$i'>Replace:&nbsp;</label><textarea rows='3' cols='30' name='farreplace[$i]' id='farreplace$i'>".esc_textarea( $replace )."</textarea>&nbsp;&nbsp&nbsp;<a href='#' onClick='removeFormField(\"#row$i\"); return false;'>Remove</a></p>\n";

    Please include this in the next release, if it’s not too much trouble.

    Thank you!

    Plugin Author Marios Alexandrou

    @marios-alexandrou

    Thanks for the code to fix this issue. The latest version includes it.

    Excellent. Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Issue with html chars’ is closed to new replies.
Skip to toolbar