From the start of SPLOTs we recognized an inherent problem with not asking for people who use them to create accounts / share info– there would be no way for them to modify what they wrote or shared once it was put in.

The same thing happened with the UDG Agora version of the DS106 Assignment Bank Theme— the end result is you either have to make changes on request, or people just add it twice (or thrice or quadrice).

I’d had in mind a way, but did not really do until the most recent update — if the author provides an email address, a special custom link is emailed to them (or can be requested later) that allows them to edit their work later:

It could have been done w/o email, by providing them the link as a one time view after they submitted, but I worried about the odds people would save that. The URLs are ones that have 2 parameters appended to the writing tool URL

http://mycoolsite.ca/write/?wid=123&tk=4a7c07ff8cdc570832a1d64f2d67cfacf1f176b7

Where wid is the WordPress databased ID for the post, and tk is a special key generated for each item.

Just yesterday afternoon I was thinking it would be useful for a site editor or admin to retrieve such a URL for a writer (that is the generic name I used for a “user”– I hate “user”) if they had not provided an email, or for a site that pre-dated this feature.

My first effort was adding a box to the bottom if a published piece only a logged in admin would see, but that seemed awkward, and not good when people are doing demos. Why not then, add it to the admin interface when an item is edited? This is easy, I have done it before– because WordPress lets me modify everything in and on WordPress, I can add a “Custom Metabox” to the post editor; here it is in action:

edit-link-wp

I gather this is all for naught in the Calypso era, but for now, this was the way I did it, pretty much lifting code from the WordPress Codex for add_meta_box.

It’s all stuff added to my theme’s functions.php which just be saying so weans away most readers. Oh well.

// add meta box to show edit link on posts
function truwriter_editlink_meta_box() {

	add_meta_box(
		're_editlink',
		'Author Re-Edit Link',
		'truwriter_editlink_meta_box_callback',
		'post',
		'side'
	);
}
add_action( 'add_meta_boxes', 'truwriter_editlink_meta_box' );

The call to add_action tells WordPress, “Hey, when the dashboard loads, along with all the stuff you do, also do what Alan wants to via stuff in a function namedtruwriter_editlink_meta_box

That function sets things up:

  • re_editlink is an HTML ID added to the thing, I won’t be using it, but if your box needed some interaction with jQuery, than it is so. Heck, it does not hurt.
  • Author Re-Edit Link The title that sits at the top of the box in the Dashboard.
  • truwriter_editlink_meta_box_callback This is critical, it is the name of another function (below) that fills the box.
  • post says I want to show up on Posts screens (it has no meaning on Pages). WordPress lets me be specific, or I can even add my own box to the main dashboard. See, they let me do whatever I want to the dashboard interface.
  • side Tells WordPress I want my box to show up on the side column, I could have it appear below the post (and custom metadata). I like it on the side. And hopefully you know as an individual user, you can slide these boxes up and down the screen; I like my featured image box higher. Did you know that? Go try.

Now the callback function that fills the box is what you need to figure out; what do you want in the box? It could be as simple as:

function truwriter_editlink_meta_box_callback( $post ) {
  echo 'Isn't Alan Awesome? Read the best blog anywhere';
}

which is pretty useless, lame, but hey, you might want that in your dashboard. You could insert random GIFs, inspirational quotes, some weather widget.

In my case, I needed to retrieve some information specific to the post content, namely the special key needed to edit; and in fact it generates the key if it did not exist (using another custom function). I put the special URL in a form field with a simple JavaScript to select the text (a URL) so an admin can click, copy the URL, and then share it.

// content for edit link meta box
function truwriter_editlink_meta_box_callback( $post ) {

	// Add a nonce field so we can check for it later.
	wp_nonce_field( 'truwriter_editlink_meta_box_data', 'truwriter_editlink_meta_box_nonce' );


	// get edit key
	$ekey = get_post_meta( $post->ID, 'wEditKey', 1 );
	
	// make an edit link if it does not exist
	if ( !$ekey ) {
		truwriter_make_edit_link( $post->ID );
		$ekey = get_post_meta( $post->ID, 'wEditKey', 1 );
	}

	echo ' ';
	echo '';
	
	}

I had done this before for the DS106 Daily Create to make a small tool needed to generate extra information.

It’s probably lost in the PHP wash, but the fact that WordPress gives its hooks and actions into everything it does, lets me use WordPress in a way to modify it’s own functionality.

If that’s not super meta, whatsameta with you?

You can get all of this at https://github.com/cogdog/truwriter


Top / Featured Image Credit: flickr photo by Nitevision http://flickr.com/photos/octavaria/5674960372 shared under a Creative Commons (BY) license

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 *