Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Convert iTunes links to TradeDoubler affiliate links
- */
- add_filter( 'the_content', 'themename_music_link_filter', 1 );
- add_filter( 'comment_text', 'themename_music_link_filter' );
- function themename_music_link_filter( $content ) {
- $content = preg_replace_callback( '/<a\b(?>\s+(?:href="([^"]*)")|[^\s>]+|\s+)*>/', 'themename_affiliatize_links', $content );
- return $content;
- }
- function themename_affiliatize_links( $matches ) {
- $link_tag = $matches[0];
- if ( isset( $matches[1] ) ) {
- if ( 0 === strpos( $matches[1], 'http://itunes.apple.com/' ) || 0 === strpos( $matches[1], 'http://phobos.apple.com/' ) ) {
- $wrapper = 'http://clkuk.tradedoubler.com/click?p=23708&a=1995293&url=';
- $new_url = add_query_arg( 'partnerId', 2003, $matches[1 ]);
- $new_url = $wrapper . rawurlencode( rawurlencode( $new_url ) );
- $link_tag = str_replace( $matches[1], $new_url, $matches[0] );
- }
- }
- return $link_tag;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement