Support for showing PHP code  

  RSS

lph
 lph
(@lph)
New Member
Joined: 3 years ago
Posts: 1
22/05/2016 12:23 am  

Many of my members post PHP code snippets wrapped with [PHP].  This tag shows up in the comments with the code. Is there a way to get this to look better?

Screen Shot 2016 05 21 at 1.21.57 PM


Quote
Tom
 Tom
(@tomson)
Support Team Admin
Joined: 5 years ago
Posts: 2961
22/05/2016 10:26 am  

Hi lph

put this code in your current active theme's function.php file:

function wpdiscuz_display_php($comment){
    $comment = preg_replace_callback('|\[php\](.*?)\[\/php\]|is', 'wpdiscuz_php_code', $comment);
    return $comment;
}
function  wpdiscuz_php_code($match){
    return '<br/><pre><p style="text-align:right;border-bottom:1px solid #ddd; padding:5px 2px; margin:0px; color:#ccc;">| PHP CODE |</p>'.str_replace(array('>', '<'),array('&gt;','&lt;'),$match[1]).'</pre><br/>';
}
add_filter( 'comment_text', 'wpdiscuz_display_php' );

ReplyQuote
Share:
Green
Default
Pear
Black Emo
{green}:grinning:
{green}:wink:
{green}:face:
{green}:inlove:
{green}:sweaty:
{green}:surprised:
{green}:lovekiss:
{green}:laugh:
{green}:formalsmile:
{green}:displeased:
{green}:cool:
{green}:resent:
{green}:nerd:
{green}:screaming:
{green}:amazed:
{green}:sad:
{green}:deceitful:
{green}:starryeyes:
{green}:evil:
{green}:shocked:
{green}:tears:
{green}:sulky:
{green}:smile:
{green}:vomited:
{green}:hi:
{green}:afraid:
{green}:crazy:
{green}:rabid:
{green}:fighting:
{green}:nonoise:
{green}:blushed:
{green}:idontknow:
{green}:scared:
{green}:razz:
{green}:kiss:
{green}:eat:
{green}:shutmouth:
{green}:gape:
{green}:suspicious:
{green}:laughingoutloud:
{green}:bruise:
{green}:crying:
{green}:pray:
{green}:serious:
{green}:excitement:
:)
:d
:wink:
:mrgreen:
:neutral:
:twisted:
:arrow:
:shock:
:???:
:cool:
:evil:
:oops:
:razz:
:roll:
:cry:
:eek:
:lol:
:mad:
:sad:
:!:
:?:
:idea:
:hmm:
:beg:
:whew:
:chuckle:
:silly:
:envy:
:shutmouth:
{pear}:happy:
{pear}:smile:
{pear}:laugh:
{pear}:laughingoutloud:
{pear}:crying:
{pear}:exhausted:
{pear}:nerd:
{pear}:surprised:
{pear}:veryhungry:
{pear}:wink:
{blackemo}:laughtertotears:
{blackemo}:gift:
{blackemo}:love:
{blackemo}:inlove:
{blackemo}:shamefaced:
{blackemo}:heart:
{blackemo}:crazy:
{blackemo}:anguished:
{blackemo}:bruise:
{blackemo}:easymoney:
{blackemo}:exhausted:
{blackemo}:vampire:
{blackemo}:shutmouth:
{blackemo}:wink:
{blackemo}:carnival:
{blackemo}:flowers:
{blackemo}:hotdrink:
{blackemo}:party: