views:

56

answers:

1

Hi, i have a wordpress blog and several authors. i want to auto remove some website urls from my blog content. For example i don't want ANY myspace urls in post content, not only myspace.com than myspace.com/whatever or myspace.com/faq.html...

Is that possible to do that with some php codes or adding some codes to .htaccess file ?

Thank you...

+4  A: 

.htaccess can't help you here.

You should be able to throw together a pretty basic plugin, something like this:

add_filter('the_content', 'myspace_url_filter', 999);

function myspace_url_filter($content) {
  return preg_replace('/(<a[^>]href=["'])[^"']+myspace.com[^"']+["']/', '\1#"', $content);
}

Note that this is by no means a perfect regex; it can trivially be evaded by replacing the myspace domain name with a myspace IP (good luck tracking down every public IP they use...), common XSS techniques, the use of any URL redirection service like tinyURL (to catch this, you'd have to follow every single link, and any redirects), or simply linking to a page which contains the link in question (e.g. a tinyURL preview page).

Long story short, any technical countermeasure you can devise can be easily defeated, and addressing even the simplest workarounds can require extremely complicated work on your part.

It might be simpler just to talk to your authors, make your desires clear, and discipline any author who refuses to obey your "no myspace links" rule.

Frank Farmer