1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Trac Links |
---|
4 | Plugin URI: http://wordpress.org/ |
---|
5 | Description: Link ticket and changeset numbers to core.trac.wordpress.org |
---|
6 | Version: 1.0.1 |
---|
7 | Author: Automattic |
---|
8 | Author URI: http://wordpress.org/ |
---|
9 | */ |
---|
10 | |
---|
11 | add_filter( 'the_content', 'markup_wporg_links', 10, 1 ); |
---|
12 | add_filter( 'comment_text', 'markup_wporg_links', 10, 1 ); |
---|
13 | |
---|
14 | function markup_wporg_links( $content ) { |
---|
15 | $find = array( |
---|
16 | '/[\b]?#(\d{3,6})[\b]?/i', // core trac ticket #1234 in http://core.trac.wordpress.org/ticket/1234 |
---|
17 | '/[\b]?r(\d{3,6})[\b]?/i', // core changeset r1234 in http://core.trac.wordpress.org/changeset/1234 |
---|
18 | '/[\b]?diff:@(\d{3,6}):(\d{3,6})[\b]?/i', // core diff diff:@200:300 https://core.trac.wordpress.org/changeset?new=300&old=200 |
---|
19 | ); |
---|
20 | |
---|
21 | $replace = array( |
---|
22 | '<a href="http://core.trac.wordpress.org/ticket/$1">$0</a>', // core trac ticket |
---|
23 | '<a href="http://core.trac.wordpress.org/changeset/$1">$0</a>', // core trac changeset |
---|
24 | '<a href="http://core.trac.wordpress.org/changeset?new=$2&old=$1">$0</a>', // core diff |
---|
25 | ); |
---|
26 | |
---|
27 | preg_match_all( '#[^>]+(?=<[^/]*[^a])|[^>]+$#', $content, $matches, PREG_SET_ORDER ); |
---|
28 | |
---|
29 | foreach ( $matches as $match ) { |
---|
30 | $content = str_replace( $match[0], preg_replace( $find, $replace, $match[0] ), $content ); |
---|
31 | } |
---|
32 | |
---|
33 | return $content; |
---|
34 | } |
---|