Jun 15
Although I personally detest Wordpress, it does have its uses and the user-interface is well-constructed, making it much easier for non-technical users to use it. Regardless, when it doesn't do quite what you want it to do, extending it can sometimes be really easy (due to the massive number of plugins), or extremely difficult. Most of the time, in my case (recently), it's the latter and not the former.

I was recently given the task to import an unmodified XML dataset into a web-based tool as tabular data, HTML'ified, and allow for visual editing of the information, and they wanted to use Wordpress. I thought, "Okay, that should be easy enough." Well, okay, do I create a plugin to handle the import? I don't really want to learn Wordpress hooks and programming functionality considering I hate the thing...no, I'll just import it directly into the database. I used a diff tool to discover that creating a new draft entry only modifies three database tables anyway, that's easy enough. Got that working, 1-2-3, lickity-split!

But now, we need to let staff have access to modify the tabular data.
I can log in and see the tables, but...what the heck?! I can remove the anchor data in a table row, but I can't remove the table row itself? Okay, surely it will render as empty. Nope, it removed the data, but not the anchor that contained the data, therefore there's this huge blank space where nothing exists...not good. I need to remove the table column and everything in it.

Wordpress uses TinyMCE internally as its Visual Editor (a Rich Text Editor, as more people will be accustomed to it being called). I've worked with TinyMCE before, so figuring out how to get the advanced view to work will be a piece of cake...

...or so I thought, yet again...

Apparently, Wordpress has literally integrated TinyMCE into its system, which can be a good thing, I suppose, if they actually finished making it dynamically controlled (as I have heard the Drupal team has done). If you want to change the Visual Editor, you need to manually modify Wordpress code, create a plugin that uses the hooks (if you knew what they were) to modify Wordpress' default behavior, or create a plugin that is a complete replacement of the internal Visual Editor. YAY!

In my search to find possible solutions that wouldn't force me to create redundant code, I found the most suitable solution to be Labnotes' "Advanced WYSIWYG" plugin. Although I had to modify the actual plugin code to make it behave how I wanted/needed it to, the only thing I had to modify was a simple array variable list. In essence, it actually seemed easier to modify than that default TinyMCE way of modifying itself.

The Labnotes code was small and friendly, but I did have to modify three functions to get it to work the way I needed it to. For some reason, my modifications changes the appearance of the TinyMCE window (adds padding or margin to the JS iframe), but it's such a small oddity that I didn't feel like researching it further. My modifications can be found below:



With the above changes, I set the extended tools on hidden layers (as Wordpress does, but accidentally hides the extend button), and attempted to mimic (only slightly off-from default) the default layout of Wordpress' default layout for their Visual Editor button arrangements. I also added in table controls (YES! I can now modify rows, columns, cells, etc...all from within the RTE) and full screen entry editing to boot, because with tabular data, the visual editor window will be pretty darn cramped.

TinyMCE supports many other possible plugins, and they too can be implemented using this plugin, although similarly you'd have to modify the functions you see above to fit your needs, but all it's doing is telling TinyMCE which buttons to load, which in turns have certain plugin requirements. Wordpress doesn't include all the plugins by default, and if you wanted to extend it to use a certain feature that is not contained in Wordpress' package (such as table controls, or fullscreen view), you'd have to determine which version of TinyMCE is packaged with your version of Wordpress (just open up any of the TinyMCE files under the "js" directory in your wp-content/plugins" folder, it should have a version number somewhere), go to SourceForge where TinyMCE holds its repositories for public download, and grab the same version's package, export the plugins folder, and upload your necessary plugins to the appropriate plugin folder for Wordpress' TinyMCE. ...It sounds like a lot, but it really isn't.

So, now that I can finish this project up for the time being (after Wordpress training for the staff that have already been trained, of course -- they're nervous of technology), I can kick Wordpress in the nuts and move on to something better. Hopefully my own experiences can help someone else out a little. BTW, I </3 Wordpress (It's NOT a CMS, people!).

Oh yes, did I mention how Wordpress "helps" you clean your code by removing any properties it hasn't programmatically understood, such as a table's summary, the caption tag, and other types of things? ...and here I thought I'd try to be nice and semantic. Darn Wordpress!

Posted by Brendon Kozlowski

0 Trackbacks

  1. No Trackbacks

6 Comments

Display comments as(Linear | Threaded)
  1. Mike says:

    Detest wordpress?!? *head explodes*

    Ironic that this page seems to be displaying a little funny and your post is cut off? Or did I just arrive at a bad time? ;-)

    But yeah, there are definitely advantages and disadvantages to including tinymce by default in wordpress. I think for most users, it actually is a good decision. I would contrast this with drupal which does not include an rte by default. And in fact, it can be quite painful to set one up in drupal. On the other hand, once you get tinymce working in drupal 4.7, there is a very nice admin interface where you can choose exactly which buttons the editor should include.

  2. Brendon Kozlowski says:

    Whoops! The funny thing is me being in a hurry and forgetting to escape my HTML entity.

    Don't get me wrong, I definitely don't like Wordpress (it's not easily embedded - at all) unless it's to be the only thing residing at a site. I don't like it as a CMS as it needs to be so far extended beyond its original intent it's almost ridiculous. But, more to the point, I don't even really like what I'm using now either. Each pre-packaged blogging tool has both its advantages and disadvantages, and I may end up building my own for my own uses, but...who knows. Either way, I thought maybe this could help someone later on. :-)

  3. hm2k says:

    You have this PHP, but you don't say what to do with it or where it should be placed.

    Please expand.

  4. Brendon Kozlowski says:

    @hm2k:
    You need to follow the link to LabNotes, and download and install their plugin, found on the link (at their page) as "advanced-wysiwyg.php". Once you download this file, you'll edit that file according to my code. As I said, you'll need to make sure that any plugins you use need to be included - you may need to visit SourceForge and download them to be included if Wordpress doesn't include them by default.

    I did explain what to do with the code, I think you just skimmed it over too quickly. I won't do this for you, but if you need any more help, let me know.

  5. Ronny says:

    Thanks, you just saved my blog! I use the Freshy2 theme and it screws things up on the RTE end, so I've used your code to restore it to default. Just one thing, it ruins the Wordpress 2.6 RTE style (with those neat media buttons above), but nevermind.

  6. Brendon Kozlowski says:

    Ronny, if you look through the Wordpress code hard enough, I'd imagine you could find what Wordpress uses to override TinyMCE to place those "neat media buttons" in the editor. I haven't upgraded our staff installation of Wordpress at work (they're not very good at change, so the security concern was not as important as the usability) so I'm not sure what changes have been made since our install of 2.1.x.

    I am, however, glad that this has helped you out!

Add Comment


Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

BBCode format allowed