Created
January 31, 2009 01:21
-
-
Save sivel/55392 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/* | |
Plugin Name: External Shadowbox Automation | |
Plugin URI: http://sivel.net/wordpress/ | |
Description: Automatically adds Shadowbox the activator to external links in your post content | |
Author: Matt Martz | |
Author URI: http://sivel.net | |
Version: 11 | |
*/ | |
function external_shadowbox_automation($content) { | |
global $post; | |
$pattern = "/<a(.*?)href=('|\")([^'\"]*)('|\")(.*?)>/i"; | |
preg_match_all($pattern,$content,$matches,PREG_SET_ORDER); | |
foreach ($matches as $match) { | |
if (!stristr($match[3], $_SERVER['HTTP_HOST']) && | |
!preg_match('/\ rel=(\'|")(.*?)(shadow|light|no)box(.*?)(\'|")/i', $match[0]) && | |
!preg_match('/\ target=(\'|")_blank(\'|")/i', $match[0])) { | |
$replacement = '<a$1href=$2$3$4 rel=$2shadowbox[post-' . $post->ID . ']$4$5>'; | |
$link = preg_replace($pattern, $replacement, $match[0]); | |
$content = str_replace($match[0], $link, $content); | |
} | |
} | |
return $content; | |
} | |
add_filter('the_content', 'external_shadowbox_automation', 100); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment