10
Jul 10

redirect_canonical

redirect_canonical

Turns out I had to do some further tweaking for my subdomain plugin. Unfortunately, my subdomain code didn't originally handle the redirect_canonical filter provided by WordPress. This was originally no big problem, until I tried to create a subdomain for all posts tagged with a particular tag. (In this case dev.fbartho.com which presents all posts tagged with "Development").

Implementing the redirect_canonical filter hook in my plugin was a little tricky because by the time it is called I had already destroyed the original request URI and thus my ability to detect what the unmodified page url was at that time. Thankfully, all it took once I understood the problem was to store that in a global before I modified it, and then read that global back at the appropriate time in redirect_canonical

CKEditor

Today I also added the CKEditor plugin for WordPress. My first impressions of it are that it works very well. In most situations it seems pretty polished. It has a good number of toolbar buttons, without them being overly crowded, and you get to customize their appearance. Minor niggle: there isn't a <code> button, but I think I'll be able to add that with a quick little change.

Screenshot of CKEditor in WordPress in a Fluid Site Specific BrowserTwo features I recommend you use: there's a "Fullscreen" button and a "Show Blocks" button. The show blocks button gives you little grey rectangles around the major semantic elements and that lets you get a good feel for where your insertion point is located and what the editor is actually doing under the hood.  As for the fullscreen option, obviously that's self explanatory, but if you put that together with a Fluid-generated site specific browser for your blog, and the experience you get is that of a dedicated word-processor for your blog entries.

My one caveat is that, to my supreme disappointment, CKEditor completely fails to load on iPad. I have no idea why yet, but the editor simply flickers out of existence and you're left with the simplest and dumbest of editor experience. (It doesn't even let WordPress' original editor reappear)

I'll see how things go, but moving forwards, for desktop publishing, I may primarily use CKEditor within my Fluid Journal app. However, I really wish I had a more mobile editor that works well. Any recommendations?


20
Jun 10

Triumph at last! WordPress & subdomains do go together

I finally decided to do something about the abysmal visual quality of my site in recent times, but I definitely didn't want to compromise on complexity. Sometime in college, I started taking to heart the idea that it is rarely worth doing something, unless you plan to do it well. There is a modifier on that however: you need to define what *well* means for yourself. I had always held the opinion that my website was primarily for experimenting with new technologies or learning new things; having a visually interesting website was of distinct lesser importance. After I was in the job market this last I was informed — to my surprise — that my resume had been found via my own website more than through any other means. I cringed when I heard. Apparently, the visual effect of my site has become more important to me.

Back in the day I setup a WordPress and a Movable Type blog just to see how they worked, and over the past year I noticed enough respectable WordPress blogs that I decided to go with that option. Bringing back the point about needing my endeavors to be technically interesting, I decided to put a twist on my setup: I would attempt to integrate my full control of subdomains into the same WP installation. Little did I know quite how challenging that would prove to be.

The first obstacle I ran into was that WordPress 3.0 had just landed, and that meant that many plugins, and a few of the themes I tried weren't fully compatible. Not a big deal, I dove right in and started learning about the WP API and the types of things that broke from 2.8; A couple patches here and there and next thing you know the core pieces were working.

The basics resolved, I attempted to find a plugin that would do what I wished for subdomain management. No dice, though one plugin did stand out as being from the same family, and I was able to learn a bit from how it was structured.

Obvious next step? Start to a custom plugin to do what I wanted.

Key things I ended up learning much about:

  • Use 302 redirects instead of 301 while debugging.
    I lost some time attempting various (still flawed) solutions just to find that my webbrowsers had cached the 301 as the Permanent redirect that it is.
  • add_action()/add_filter()

    Crucially important, these are how your plugin gets the ability to override and inject data throughout the WP data flow. Basically there are a ton of keywords that WordPress broadcasts to at certain steps in it's life. This is effectively an observer pattern. In many cases WordPress will pass in its initialized array of data, and then ask all observers if they think it's correct. These observers include components across the system many of which might be plugins. These plugins have the option to remove or inject data based on their own logic, before the results are passed along to the next observer in the chain. Finally the potentially modified data is handed back to WordPress which then uses it.

  • Permalinks and URL rewriting

    I spent much too long learning how WordPress works in this case. Basically, there is exactly one initial entrance point to WP for everything of relevance to normal operation. The URL rewriting rules in the .htaccess just reformat the URL such that it passes data into index.php Further URL matching also happens at runtime in WP_Rewrite. I tried and I tried to figure out supplemental mod_rewrite rules to help create the subdomain effect I wished and had absolutely no luck. I tried to hook in to the additional rewrite rules and those were even more of a headache than mod_rewrite!

  • K.I.S.S.

    As usual, this principle seems to be a good guide. With every attempt frustrating and each subsequent attempt becoming more and more convoluted I eventually spent some serious time examining the flow of data in WordPress. I finally determined that the crucial datasource used to disambiguate which page to load is $_SERVER['REQUEST_URI']. And with that realization came final success. Discarding the evolutionarily created mess and substituting one quick little method added in the plugin's startup, and Tahdah! Pretty permalink urls with subdomains in use, for every subdomain I care to map in my standard WP admin console.

After spending over a day frustrated on this problem, I'm elated to have solved it and I needed to write my first post. From my iPad no less!

PS. WordPress for iPad (the app) is extremely flaky, I typed my whole post in it and then it completely fails to actually submit the post (no error message) Additionally, until reboot, copy paste was broken in it so it looked like this post would be lost. Eventually, extracted, this post was published via the web admin console's raw HTML editor. Any recommendations for a better client? For the desktop it looks like I'll be using ScribeFire embedded in Safari unless someone has something better?