这是功能的来源。这只是一个内容过滤器和一些基本的正则表达式,是我在Automatic的一位同事写的。
add_filter( \'the_content\', \'markup_wporg_links\' );
add_filter( \'comment_text\', \'markup_wporg_links\' );
function markup_wporg_links( $content ) {
$find = array(
\'/(\\ |^)#(\\d{3,6})(\\b|$)/i\', // core trac ticket #1234-core in http://core.trac.wordpress.org/ticket/
\'/(\\ |^)r(\\d{3,6})(\\b|$)/i\', // core changeset r1234-core in http://core.trac.wordpress.org/changeset/1234
\'/(\\ |^)diff:@(\\d{3,6}):(\\d{3,6})(\\b|$)/i\', // core diff diff-core:@20:30 https://core.trac.wordpress.org/changeset?new=30&old=20
);
$replace = array(
\'<a href="http://core.trac.wordpress.org/ticket/$2">$0</a>\', // core trac ticket
\'<a href="http://core.trac.wordpress.org/changeset/$2">$0</a>\', // core trac changeset
\'<a href="http://core.trac.wordpress.org/changeset?new=$3&old=$2">$0</a>\', // core diff
);
preg_match_all( \'#[^>]+(?=<[^/]*[^a])|[^>]+$#\', $content, $matches, PREG_SET_ORDER );
foreach ( $matches as $val )
$content = str_replace( $val[0], preg_replace( $find, $replace, $val[0] ), $content );
return $content;
}
修改它以满足您的需要。