Last active
December 16, 2015 00:19
-
-
Save MattRead/5346862 to your computer and use it in GitHub Desktop.
replace @name with link to comment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function filter_comment_content_out($content, $comment) { | |
if (!preg_match_all('#(@[0-9a-zA-Z_]+)\b#i', $content, $matches, PREG_SET_ORDER)) { | |
return $content; | |
} | |
$id = null; | |
foreach ( $matches as $m ) { | |
foreach($comment->post->comments as $com) { | |
if ($com->id < $comment->id && $com->name == substr($m[1], 1)) { | |
$id = $com->id; | |
} | |
} | |
$content = $id ? str_replace($m[1], '<a href="#comment-'.$id.'">'.$m[1].'</a>', $content) : $content; | |
$id = null; | |
} | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment