This is kind of a big deal for SPLOTs… but then again I thought the plugin version was, and that made nary a ripple. Maybe I need to write an open textbook (SNAP!).

A brand new version of the TRU Writer SPLOT WordPress Theme is now available sitting tapping its thumbs waiting for you.

It’s gotten lighter. This, in a change I hope to propagate to TRU Collector and SPLOTbox, carries out some earlier thoughts. There is no longer a need to create a secret “author” account, a bunch of related code was jettisoned. and a required Welcome Desk page is nixed too.

This will simplify issues on multisite that Colin Madland was seeking help with:

First SPLOTs and Secret Logins

Okay, what is it with “secret” accounts? The whole idea of SPLOTs in WordPress is not needing accounts or logins. But there has been a duct tape approach back to the first one made in 2014

So in a few rounds of tinkering, I managed to get the media uploading working, and even generating a somewhat working version. But the first problem is that when not logged in as a site user, as a visitor, I could see the uploader, but nothing could be uploaded (permissions).


As it turns out, you have to be logged in as a user with at least Authoring privileges to upload media. My first effort was then to create a generic authoring account, and maybe we would have to share the login. The user needs no access to the dashboard, they just need to be logged in as this user.

A whole swatch of SPLOTting has been done by a trick, a sleight of coding. When a visitor goes to a form to create something, if they are no logged in to the site, the theme silently logs them in as an authoring level user, all done behind the scenes, hiding the dashboard and the admin bar. This was solely done initially to use the media uploader, the ability of WordPress to generate multiple sizes, and later, to use the media uploaded in the editor.

I could see in many attempts by others that this whole account thing was (a) baffling; and (b) often not done well. I started exploring a different interface of uploading media. I even had a working version where the account was created if not present, without the site owner needing to bother.

It’s still a lazy solution.

So now it is gone. There are no secret accounts needed in the version you can try here http://splot.ca/writer — which honestly looks no different to the user.

The Drop Zone

Well, it does have this kind of drag and drop upload interface (or click to select a file, e.g. on a mobile).

I started experimenting with dropzone.js but it did not play well on iOS. But I did find out that a file input form field could act as drag and drop interface, but that was only over the default small button. With some clever CSS, some borrowed some hacked away, I was able to change the style of that button to be the whole area with the stipple background. The preview thumbnail is actually not uploaded, but generated with some jQuery. Once the form is first submitted to review, then a regular WordPress file upload happens.

This is the HTML for the form file input field, set up to accept image files:

And the fancy styling use some positioning stuff I lifted some drop dropzone.js. The background places a small icon in the area; and the background is a new trick I got from Patternify

In the script that responds to the form, we end up having the attachment ID in $wHeaderImage_id which we can do other things with.

The mistake I made multiple times is the upload will not work until I added enctype="multipart/form-data" to the form tag. There’s a bit more magic in the Javascript, but now we have image uploads without needing the WordPress media library.

Fewer Pages, Templates, Redirects

The other improvement, as mentioned, is dropping the need for a second “Welcome Desk” page. This was a remnant of my ear;y sloppy development to handle cases where a site has an option to use a special access code to get to the form.

For some reason I came up with this crazy flow when someone visits the form

  • Is the user logged in? (either as an admin or the secret user) If NO
    • Go to the Writing desk page
    • Is an access code required? IF NO:
      • do the secret login
      • go back to the writing form and do stuff
    • If YES:
      • Present the form to enter access code.
      • Is correct code entered?
        • NO: error, try again.
        • YES: do secret login
        • go back to the writing form and do stuff
  • Now we can present the writing form

There are all kinds of bouncing around and checks that needed to happen. It did work (for years) but I am shaking my head at this crazy logic. I think I saw that it might help to have a separate page for the access code to have special instructions??

Anyhow, I uncoupled all of the access code checks and forms, and it all is handled now by one page template. Gone are crazy redirects, extra checks, and the set up stuff to create and manage this second page template.

As of now, then there is only one special page and template needed in the theme.

Thus, a less complex theme. And without tricks and hijinks of special hidden users (never mind things I ignored for a while as logging out of the special account was never precise, so sometimes commenters ended up represented by the secret user. Or people logged into multisite for other purposes are logged out.

What’s Lost?

Two things are now lost with this new approach, but in time, I may find the end around– seeing autoembedded URLs in the editor and inline image uploads.

Before this I had figured out how to enable the front end editor to instantly embed media URLs in the editor (like pasting in a YouTube URL and seeing it materialize as the full embedded player, in the editor). This can only happen if you are logged in to the site, even as the secret user.

I went through a bunch of efforts to find out why. As near as I could trace, it has to do with a limit of ajax requests when not logged in. And I cannot find the write WordPress hooks toss ajax_no_privs. I have tried pleading for help in StackExchange and in WordPress.org and gotten nothing.

That’s sad. I know from Direct Messaging that Tom is trying to figure this one out too. I think I can get there one day, and it’s not a crippling loss.

What happens now is that an embeddable URL sits there as a plain URL, but you can see it when you preview your work, and when it is finally published… this in itself was a trick to find a way to let non-logged in users see a draft.

After submitting the first round in the writing form, and clearing any errors, one sees:

Notice message atop form, "We have saved this first version of your writing. You can preview it now (opens in a new window), or make edits and save again."
After first submission, one you get a preview link… this will open in a new window/tab.

When there was a secret user, it’s easy to have a link for a preview using the post id, something like http://somecoolsplot.ca/?p=344&preview=true but if not logged in that link produces a 404 error.

I found a partial answer in Stack Exchange (which nearly always has an answer, just not for me), that works like:

The thing I noted was that it removes the ?preview=true from the URL and this means in my single.php template a little check I have to show an info box won’t work by checking is_preview(). I got around this by tacking on my own url parameter ispre=true when a link is displayed to “see preview”, making my own function:

and in my single.php template, I have a thing to show a message only if the current item is a preview.

This produces now a preview that can be seen when not logged in, and also, since it opens in a new tab/window, I like to put a notice in with a link to close the tab/window:

Notice box atop the preview, 'This is a preview of your entry that shows how it will look when published. Close this window/tab when done to return to the writing form. Make any changes and click "Revise Draft" again or if it is ready, click "Publish Now".'

So even if the URL for something that WordPress can embed is in plain text in the editor, and stays that way when the form is submitted:

The SPLOT editor includes a YouTube URL on a blank line.
Embeddable link in the editor

But when previewed (and eventually published), you get the embedded video:

The preview shows an embedded video.

It all works, maybe not ideally. I did have a version where after saving, the embed is added via a function, but the problem is, it converts the link to an iframe embed. This is fine on a single WordPress site but will break in multisite.

There is some sneaky way the WordPress renders the embeds in the editor via jQuery. but I’ve not cracked it yet to do so when the writer is not logged in.

Not yet.

The Second Loss

The other thing missing without being logged in is the editor’s feature to upload and insert an image in the middle of a written piece. The TinyMCE editor does have an image insert tool, but you need a web URL to add (it just slaps an img tag in the source).

But there is an auto embed thing for image URLs- if you have a link directly to an image, say to some random dog:

WordPress will automagically embed that like a YouTube. But woah, surprise! I just did this in a non logged in view, pasting in the URL above, and the editor made the link appear right in the editor!

That’s neat, but most people will likely not find the full URL to an image.

My idea is maybe to find a way to use my file upload trick as something that could work in the editor. This is on the map for future.

Simpler Is As…

I’m not sure if anyone really cares about all this, but I think it’s big. And next it will be rolled into the plugin version of the TRU Writer. I am floored that no one has even tried the SPLOTwriter plugin. I thought it was almost a crowning SPLOT achievement. Pinnacle.

Look soon for some news when the simple Splot record spins out to TRU Collector and SPLOTbox.

If you don’t dig your own music, then the audience is zero. I’m not dropping there.

I’d really really really appreciate if some folks can try the new theme or at least give the test versions a spin.


Featured Image: A makeover of the label on public domain image Simple melody found on picyrl. I like this site a lot, and while they do credit the Library of Congress as the source, why the ***** can they not link to the original? The source link is http://loc.gov and while this is true, it’s of no value. I can find the source in about 3 clicks https://www.loc.gov/resource/jukebox-17522

If this kind of stuff has value, please support me by tossing a one time PayPal kibble or monthly on Patreon
Become a patron at Patreon!
Profile Picture for CogDog The Blog
An early 90s builder of web stuff and blogging Alan Levine barks at CogDogBlog.com on web storytelling (#ds106 #4life), photography, bending WordPress, and serendipity in the infinite internet river. He thinks it's weird to write about himself in the third person. And he is 100% into the Fediverse (or tells himself so) Tooting as @cogdog@cosocial.ca

Leave a Reply

Your email address will not be published. Required fields are marked *