Skip to content

Instantly share code, notes, and snippets.

@sivel
Created January 31, 2009 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivel/55392 to your computer and use it in GitHub Desktop.
Save sivel/55392 to your computer and use it in GitHub Desktop.
<?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