Thread Starter
M66B
(@m66b)
I found out the comment textarea isn’t replaced as it should, but I didn’t found out why yet. On another similar site (same theme at least) it is just working.
Thread Starter
M66B
(@m66b)
Okay, I fixed the problem this way:
First I added a new action hook:
add_filter('comment_form_field_comment', array($this, 'alt_replace_comment_field'));
Below this one:
add_action('template_redirect', array($this, 'replace_comment_field'));
Then I added this function below ‘replace_comment_field’:
function alt_replace_comment_field($field) {
return preg_replace("#<textarea(.*?)name=([\"\'])comment([\"\'])(.+?)</textarea>#s", "<textarea$1name=$2" .$this->md5_sign. "$3$4</textarea><textarea name=\"comment\" rows=\"1\" cols=\"1\" style=\"display:none\"></textarea>", $field, 1);
}
I believe this solution is better and more compatible than the original one. Furthermore I believe there is an error in de preg_replace in the original function.
Thread Starter
M66B
(@m66b)
Important note: this will only work for WordPress version 3.0 or newer.
Anonymous User 166966
(@anonymized-166966)
I believe this solution is better and more compatible than the original one.
See Plugin Details: Requires WordPress Version: 2.7 or higher
Furthermore I believe there is an error in de preg_replace in the original function.
Where?
Anonymous User 166966
(@anonymized-166966)
comment_form_field_comment is a theme specific filter. Not every theme (with wp 3.0) has/use it.
Thread Starter
M66B
(@m66b)
I was aware that the comment_form_field_comment filter is only available in WP 3.0+, but not that it is theme specific.
About the preg_replace error, the single quotes of this fragment should be replaced by double quotes:
$2' .$this->md5_sign. '$3
Anonymous User 166966
(@anonymized-166966)
but not that is is theme specific.
Please read: http://devpress.com/blog/using-the-wordpress-comment-form/
Only if the theme supports the wordpress comment form.
About the preg_replace error, the single quotes of this fragment should be replaced by double quotes:
Please see the code:
'return preg_replace("#<textarea(.*?)name=([\"\'])comment([\"\'])(.+?)</textarea>#s", "<textarea$1name=$2' .$this->md5_sign.
Thread Starter
M66B
(@m66b)
I still think the closing quote is wrong:
"<textarea$1name=$2' .$this->md5_sign.
Opening quote: ” (just before <textarea)
Closing quote: ‘ (just after $2)
I discovered this because I copied the pre_replace function call to my alternate replace function and it didn’t work correctly (the single quotes ended up in the HTML).
Thread Starter
M66B
(@m66b)
BTW, do you have any idea why the original code didn’t replace the textarea as it should?
Anonymous User 166966
(@anonymized-166966)
Original:
create_function(
'$input',
'return preg_replace("#<textarea(.*?)name=([\"\'])comment([\"\'])(.+?)</textarea>#s", "<textarea$1name=$2' .$this->md5_sign. '$3$4</textarea><textarea name=\"comment\" rows=\"1\" cols=\"1\" style=\"display:none\"></textarea>", $input, 1);'
)
Please read the manual, ok? bye.
http://www.php.net/manual/en/function.create-function.php
Thread Starter
M66B
(@m66b)
Let’s break down the preg_replace of the original code:
preg_replace(
"#<textarea(.*?)name=([\"\'])comment([\"\'])(.+?)</textarea>#s",
STARTING QUOTE-> "<textarea$1name=$2' <-ENDING QUOTE
.$this->md5_sign.
STARTING QUOTO-> '$3$4</textarea><textarea name=\"comment\" rows=\"1\" cols=\"1\" style=\"display:none\">
</textarea>", <-ENDING QUOTE
$input,
1);'
I don’t see why the documentation of create_function matters, but maybe you can explain it?
Apart from this discussion, my original problem is still not solved. Somehow, and I really looked hard to find out why, the comment textarea is not replaced. Do you have any idea about what could be wrong?