Plugin Author
Steven
(@shazahm1hotmailcom)
@flector
Sorry, I can not reproduce this. It must be the theme or another plugin preventing syntax highlighting in the comments.
I’m sorry for my English.
I try to describe.
By default “subscribers” cannot add code in comments.
I did little hack:
1. code in functions.php
function replace_code_pre ($matches){
$out = str_replace( array('<','>'), array('<','>'), $matches[3] );
return "<{$matches[1]}{$matches[2]}>".$out."</{$matches[1]}>";
}
function code_in_comments($comment_text){
$comment_text = preg_replace_callback ('!<(pre|code)([^>]*)>(.*?)</\\1>!ims', 'replace_code_pre', $comment_text);
return $comment_text;
}
add_filter ('pre_comment_content','code_in_comments');
remove_filter ('comment_text', 'wptexturize');
2. in wp-syntax.php after line 114 (in version 0.9.12)
$escaped = trim($match[3]);
add line:
$escaped = "true";
after this hack any subscribers can add code in comments. but in version 0.9.13 code is published, but without highlighting.
any suggestions? I really need posting code by subscribes.
thank you.
there are & lt; and & gt; in function replace_code_pre
$out = str_replace( array('<','>'), array('& lt;','& gt;'), $matches[3] );
without spaces.
Plugin Author
Steven
(@shazahm1hotmailcom)
Oh, ok, I see. Open the wp-syntax.php file and fine this code starting at line 37
/*if (!CUSTOM_TAGS) {
$allowedposttags['pre'] = array(
'lang' => array(),
'line' => array(),
'escaped' => array(),
'style' => array(),
'width' => array(),
'highlight' => array(),
'src' => array()
);
//Allow plugin use in comments
$allowedtags['pre'] = array(
'lang' => array(),
'line' => array(),
'escaped' => array(),
'highlight' => array()
);
}*/
And change it to:
if (!CUSTOM_TAGS) {
$allowedposttags['pre'] = array(
'lang' => array(),
'line' => array(),
'escaped' => array(),
'style' => array(),
'width' => array(),
'highlight' => array(),
'src' => array()
);
//Allow plugin use in comments
$allowedtags['pre'] = array(
'lang' => array(),
'line' => array(),
'escaped' => array(),
'highlight' => array()
);
}
The only change is uncommenting it. I didn’t test, but I think this should revert the change that made your hack work.
You might want to accomplish this a different way though. This blog post explains how to tap into a different filter to change the tags and attributes that are permitted rather than doing this string replace you’re doing.
http://www.kavdesign.net/blog/coding/how-to-allow-more-html-tags-in-the-wordpress-comments/