Update tool for Wordpress MU and allowable tags
We ran into problems setting up our services page becuase of some moderately advanced html code we were using. We were using definition lists with classes and ids on them - not all that advanced if you ask me. Anyways, after much digging and reading I came across a plugin that made it work part of the way. Apparently it does work in regular old WordPress but WordPress MU has some extra restrictions. Those restrictions do make sense when you consider it’s multi blog nature and the opportunity for abuse. Well, we’re running the whole deal here so no need for that but rather than just hack away at the core code, I added 2 hooks to the original plugin. Here’s what i did:
First off grab the latest tmve valid elements plugin http://www.engfers.com/plugins/tinymce-valid-elements/
Secondly install it by dropping it into the plugins directory (not mu-plugins) and activating it the blog that you need it in.
Then I added the code below to the bottom of the tinymce_valid_elements.php file. Here’s the 2 blocks of code:
function tmve_add_tags(&$content) {
$elements = tmve_get_element_map();
foreach ( $elements as $element => $attributes ) {
foreach ($attributes as $attrib ) {
if (isset($content[$element])){
$content[$element][$attrib] = array();
} else {
$content += array(
$element => array(
$attrib => array(),
)
);
}
}
}
return $content;
}
add_filter('edit_allowedposttags', 'tmve_add_tags');
The add_filter call makes wordpress run the function when you save the post which is needed in Wordpress MU. It’s a modification to the tmve_mce_valid_elements function.
Then I also added this:
function tmve_add_styles(&$content) {
$content[] = 'display';
return $content;
}
add_filter('safe_style_css', 'tmve_add_styles');
This hook made it possible to add the css display property into style attributes on my html. We needed this for the bottom part of our services page where we have some content blocks closed when the page loads.
One last thing is to configure it all. Click on Manage > TinyMCE Valid Elements and add the tags / elements you want to support.
Thanks again to David Engfer for the great plugin.
Lastly, I only used this on one blog so I believe you would need to activate and configure in each blog you want to use it in. Does anyone know the detail on that?

5 Responses to “ Update tool for Wordpress MU and allowable tags ”
March 17th, 2009 at 5:58 pm
If you want, I’ll work on that. I’ve heard of MU but have never played around with it. I’ll see if I can do something.
What exactly do you want it to do?
My next thing was to have the ability to read from a config XML file to insert some of your own default elements/attributes.
March 18th, 2009 at 7:11 am
Cool. We just needed the base functionality you wrote to work in MU and adding the edit_allowedposttags hook got us there.
Most complaints i’ve seen are about how MU blocks stuff like embedding videos and that’d be the kind of thing to put into a config xml file - great idea.
Only other MU specific thing i could think of would be if you could install the plugin in the admin blog and apply that setup globally to all blogs - i.e. not install in each blog separately. Might be possible with the special mu-plugins directory which behaves differently.
April 6th, 2009 at 2:40 am
Hello - I was using the tinymce-valid-elements plugin to get round problems with the editor stripping out Imagemap related tags. I am using Wordpress MU.
I applied your patches to the plugin to allow me to use these tags and it worked - great.
However, I had previously disabled Visual mode for the admin user that I was using to create the post. When I re-enabled Visual mode, and re-visited the page with the imagemap, when I switched from Visual mode to HTML, it stripped out the tags again - only in a worse fashion then before using the plugin.
For example, if I now insert a simple image (no map related tags) in visual mode and then switch to html all I get left with is
There seems to be some kind of conflict here. Unfortunately, I have had to disable the plugin in order to carry on working.
The auto stripping of tags by tinymce does seem to be an issue for lots of people. This is a nice way to work with it, as I understand that the stripping action can improve security.
Incidentally, I thought that tinymec DID support the necessary tags for Imagemaps, but not apparently the version in the current MU release.
Please keep up the good work - this is what we need.
December 14th, 2009 at 7:30 pm
The first line of your first code snippet has an “amp;” that should just be a plain ampersand &.
December 18th, 2009 at 8:13 am
Thanks Luke - it was some cruft added by wp - still can’t figure out how to keep the code indented either. sigh