I’m trying to strip tags that a Chrome addon has added to our WordPress posts.
The Ginger Software spelling and grammar checker (https://chrome.google.com/webstore/detail/spell-checker-and-grammar/kdfieneakcjfaiglcfcgkidlkmlijjnh?hl=en) alters the HTML behind the scenes and leaves the page littered with spurious span tags for class=”GINGER_SOFTWARE_mark”.
I did find an obscure WordPress plugin which strips these, but they’ve since updated the Chrome extension and it no longer works as the tag format changed, the author has gone AWOL so I’ve been taking a shot at updating the plugin myself, I’m close, but need a hand getting past the final stage…. Any takers?
This is a sample of the tag I’m stripping:
<span class="GINGER_SOFTWARE_mark" id="8199646e-ebe6-45e9-bbe2-b212389a8120">words go here</span>
and the plugin I’ve been trying to tweak is this one: http://wordpress.org/plugins/ginger-tag-remover/
Using Debuggex I was able to get this PCRE regex which matches the above:
<span class="GINGER_SOFTWARE_mark" id="[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}">(.*?)</span>
but implementing it into the PHP isn’t working out so well…
Here’s the code lifted from the plugin:
if ( !function_exists( 'add_action' ) ) {
echo 'Leave me alone. I don't want trouble.';
exit;
}
function gtr_strip_ginger_tags($content){
$gtr_patern_array=array();
array_push($gtr_patern_array,array('pattern'=>'#<span class="GINGER_SOFATWARE_noSuggestion GINGER_SOFATWARE_correct">(.*?)</span>#m','replace'=>'$1'));
array_push($gtr_patern_array,array('pattern'=>'#<span class="GINGER_SOFATWARE_noSuggestion GINGER_SOFATWARE_correct">(.*?)</span>#m','replace'=>'$1'));
array_push($gtr_patern_array,array('pattern'=>'#<span class="GINGER_SOFATWARE_correct">(.*?)</span>#m','replace'=>'$1'));
array_push($gtr_patern_array,array('pattern'=>'#<span class="GINGER_SOFATWARE_spelling">(.*?)</span>#m','replace'=>'$1'));
foreach($gtr_patern_array as $pat){
$content=preg_replace($pat['pattern'],$pat['replace'],$content);
}
//$content.='<!-- GINGER CLEANED -->';
return $content;
}
add_filter('content_save_pre','gtr_strip_ginger_tags');
I tried adding this:
array_push($gtr_patern_array,array('pattern'=>'#<span class="GINGER_SOFTWARE_mark" id="[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}"\ >(.*?)</span>#m','replace'=>'$1'));
Think I’m close, but not sure what I need to tweak, any suggestions?
Karu
You have in code “GINGER_SOFTAWARE” not “GINGER_SOFTWARE”. I think that is the issue – if this doesn’t work please comment this so I’ll dive further into this.
— Edit —
Then maybe try using RegExp that removes everything if the class is correct something like this: