It’s a work in progress, but check out this version of the TRU Writer SPLOT that is no longer tied to the original’s Radcliffe theme (hit the write menu item to try it).

All SPLOTs are single purpose tools, most built as WordPress themes stuffed with custom functionality… technically they are child themes that utilize an existing theme for the core site functions and appearance. Long ago, someone asked if they could be done as a plug-in, and I said “no” because of how much work they had to do- create back end admin options, generate and process form data, and present content out of the normal blog post scope.

Like often…

I decided to take this on again via a request from colleagues Daniel Villar and Lauren Heywood from Coventry University DMLL, who have made some of the most wide and varied use of SPLOTs.

This new site is not quite plugin yet, but what I have done is remove all of the functionality from the child theme templates, it’s all in code. This means, I was able to take the child theme, and apply it in a different parent, and It Works (as much as I could test so far).

These are the files in the TRU Writer SPLOT theme, there is functionality baked into header, footer, archive, and various page templates, and thus tied to the parent theme.

Director of files in the theme, 13 files plus 4 directories
Files in the TRU Writer Theme

The test version has moved everything into functions, so it has no dependence on the parent theme beyond rendering content.

Directory with 3 files and 3 directories
Files in the test theme

It was more than cut and paste code. The pages templates used to render the access code form and the form for writing had all the form elements and logic intertwined into the template (peek at it).

Now, the writing form is embedded into any normal page by adding this to the content:

[writerform]

This I knew was possible form all of the various WordPress form plugins out there. But still to work out the logic of the hidden author user account, required doing much more with WordPress hooks to do various redirects and checks before the content appears (template_redirect is my hook friend). I ran into endless duplicate header errors.

I end up checking a few things, there are query parameters sent to deal with the random link and the one to get the special edit link to send via email, but also it needs to identify if a page to be rendered is one of the two special ones with forms in them.

Previously I had done this by checking the page template (or worse, assuming that the pages were always /write and /desk). Now I have a function that looks for pages with the shortcodes used to render the forms ($pattern is either [writerdesk] or [writerform]). There are cases (the second optional parameter) where I need to return an array element for displaying these as a form, see below)

function truwriter_find_pages ( $pattern = '[]', $for_menu = false ) {
	/* find all pages with pattern passed (meant for finding desk and writing form 
	   pages based on shortcode passed                             */

	// get all pages
	$seekpages = get_pages(); 
	
	// if we are building a menu, insert the menu selector
	$foundpages = ($for_menu) ?  array(0 => 'Select Page') : array();
  
  	foreach ( $seekpages as $p ) {
  		if ( strpos( $p->post_content, $pattern ) !== false) {
  			$foundpages[$p->ID] = $p->post_title;
  		}
  	}
  	
  	return ($foundpages);
}

I can also check the returned results, an empty array means no pages are using the shortcode. The plugin will create a simple page with the shortcodes if none exist.

But it also means that the pages are not limited to specific URLs – I even made this change in the regular version of TRU Writer. So you can create any page, and then it is selected as a theme option to identify it.

Both this new version and the standard TRU Writer now include a theme option to identify pages used for the two form pages.

But also to change was the way something published was rendered, as extra information is added in the SPLOT. In the original version, it’s just coded into the single.php template. To pull it out, we have to hook into the call for generating the_content to add info to the output.

// filter content on writing page so we do not submit the page content if form is submitted
add_filter( 'the_content', 'truwriter_mod_content' );
 
function truwriter_mod_content( $content ) {
	if ( is_single() && in_the_loop() && is_main_query() ) {
	
		global $post;
		// additional content for single views

		// add before content notice for previews		
		$precontent = ( is_preview() ) ? '
This is a preview of your entry. Wwhen finished reviwing, close this window/tab to return to the writing form. Then make any changes and click "Revise Draft" again or if it is ready, click Final Publish.
' : ''; $postcontent = ''; $wAuthor = get_post_meta( $post->ID, 'wAuthor', 1 ); if ( truwriter_option('show_footer' ) ) { $wFooter = get_post_meta( $post->ID, 'wFooter', 1 ); if ($wFooter) $postcontent .= '

' . make_clickable( $wFooter ) . '

'; } $postcontent .= '

' . truwriter_meta_title() . '

  • Author: ' . $wAuthor . '
  • Published: ' . get_the_time( get_option('date_format'), $post->ID ) . '
  • Word Count: ' . str_word_count( get_the_content()) . '
  • '; // output estimated reading time if we are using plugin $postcontent .= truwriter_get_reading_time('
  • Reading time:', '
  • '); // show the request edit link button if they have provided an email and post is published if ( get_post_meta( $post->ID, 'wEmail', 1 ) and get_post_status() == 'publish' ) { $postcontent .= '
  • Edit Link: (emailed to author) Request Now
  • '; } if ( truwriter_option( 'use_cc' ) != 'none' ) { $postcontent .= '
  • Rights: '; // get the license code, either define for site or post meta for user assigned $cc_code = ( truwriter_option( 'use_cc' ) == 'site') ? truwriter_option( 'cc_site' ) : get_post_meta($post->ID, 'wLicense', true); $postcontent .= truwriter_license_html( $cc_code, $wAuthor, get_the_time( "Y", $post->ID ) ) . '
  • '; } if ( truwriter_option('show_tweet_button') ) { $postcontent .= '
  • Share:
  • '; } $postcontent .= '
'; return $precontent . $content . $postcontent; } }

There is a bit of content that is prepended when we are doing a preview (a notice shown above), and then extra metadata generated by the SPLOT that comes after.

Screen shot of a published item showing the elements that are added to the output

The formatting is kept simple, but everything has CSS IDs and classes to customize it via the customizer.

So how does this become a plugin?

Apply more elbow grease.

The code pretty much can work as is. Some changes need to happen to change the theme options to plugin ones, and if I really get my act together, these should go into a Customizer interface rather than the theme admin screen I’ve used for ever. The output for the shortcodes is a lot of stringing together bits of text, it might be better broken into smaller modular functions. And it will need some more customizer options to manage some appearance issues of the forms (background color, etc).

So it’s got more work ahead. But this pretty much shows that SPLOT can work independent of the parent theme. Give it a try and let me know how it goes.

The original TRU Writer theme is still viable, and updates will happen to both going forward. Already, the work to get this demo going has flowed back into the main theme, simplifying reliance on page templates, and adding some better theme options. I doubt I will do this to all SPLOTs, this was Just To See If I Could

I doubt few readers, if any are still here, can really unravel what the bleep I am talking about. Much of this is my own mental noting. What people often did before twitter threads.

And while I think SPLOTs might have had a long run, almost 5 years, just when I start to think no one cares, come across people using them.

So SPLOT Plissken has escaped the Theme!


Featured Image: Modified one frame of YouTube video of Blick Flick’s video assignment title sequence.

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 *