# For about a year I've had a separate page on the site containing just a simple form which lets me post directly on the web without having to use wp-admin or the WordPress app on my phone.
I'm always reminded of the argument that social networks usurped blogging because posting and consumption were all in the same place. I wanted something simple to let me to post quickly, hence the form.
Today, I came across the P2 WordPress theme which let's sites with multiple users post and reply in a Twitter-like fashion - see Matt Mullenweg's thoughts on how it changed Automattic - and it got me thinking how I could make it even easier to post.
A few tweaks later and I've now added a slimmed down version of the form to the top of the Daily page which shows if current_user_can('edit_posts')
:
I've got a couple of changes to make but I'm pretty happy with it so far. This post was made using it.
Comments
# Another test being published straight away rather than as a draft.
# The P2 theme uses AJAX to update the site without having to refresh the page so maybe I could go this route in future. It'll be a bit of a learning curve as it's not just having an AJAX form but also loading the posts. That's definitely something for another day.
@colinwalker Interesting! Is there a page or post that explains how you set this up?
@roelio Not yet. Will probably write something up tomorrow once I’ve finished tweaking it.
@colinwalker Ok, looking forward to that. It sounds like a great blogging workflow improvement.
@colinwalker did you see that WordPress.com now offer hosting of an updated p2 style site: P2 — The New Working Interesting stuff it it gets outside of .com some forking seems to be in progress.
@johnjohnston Yeah, saw that. Obviously a bit much for a blog but looks really interesting.
# Roel asked if there was a post detailing how I set up the posting form. There is now... Firstly, I've slimmed down the form a bit further by adding placeholder values rather than labels and adjusting the spacing. It now takes up less room at the top of the page. I've also added a toggle to show/hide the form with a quick bit of JavaScript and CSS.
So, how does it work? It's all relatively straightforward. As mentioned yesterday, the elements are contained within
if (current_user_can('edit_posts'))
checks. The original form page had everything permanently visible but required a "key" to be entered so that only I could post. With this now being at the top of the home page (unless your default is the Today view) I obviously don't want it visible all the time. Hiding it with the current user check also means I can do away with the key. The form is just regular HTML with its method set to "post" and no action so that it redirects back to the same page on submit. Inspired by micro.blog, the Title field is only shown if I change the post format to 'Post' rather than 'Status'. Once submitted and after a quick sanity check I pull the required form values from the standard PHP$_POST
variable and set up my core details:$title = stripslashes($_POST['title']); $body = stripslashes($_POST['body']); $status = $_POST['status']; $format = $_POST['format']; $author_id = '346'; $comment_status = 'open'; $ping_status = 'open'; $post_date = gmdate("Y-m-d H:i");
If I am sending a "Like" webmention I enter the URL and the required text is added to the post as per my "Likes and Replies plugin" so I won't go in to those details here. Suffice it to say that this uses a custom field on posting. With all the information in place I construct an array of 'post data'$post_data = array( 'post_type' => 'post', 'post_title' => $title, 'post_content' => $body, 'post_status' => $status, 'tax_input' => array('post_format' => $format), 'post_author' => $author_id, 'comment_status' => $comment_status, 'ping_status' => $ping_status, 'post_date_gmt' => $post_date, );
and then use this at the parameter to insert a new post$postID = wp_insert_post($post_data);
If the post is a draft I then redirect to the post preview, otherwise I just stay on the Daily page which will then have the shiny new post. And that's it - there's not much to it and it's simpler than with the standalone page. If I did decide to go the AJAX route things would get considerably more complex but I don't think I really need to. Besides, I've not done anything of that ilk for what seems like an eternity.@roelio The post is up.
Liked Scripting News: The ideal blogging tool... Dave Winer has been on the campaign trail for better blogging software since, well, since blogging began and repeatedly said that blogging needs to be easier. Here again he states that the ideal tool would merge "the publishing of WordPress with the interactivity of Facebook." I've taken a lot of cues from Winer over the years for how my own site operates and have long agreed that social media became such a success because of the simplicity and immediacy of posting and replying within the same interface. These thoughts and the P2 WordPress theme inspired my simple posting form (which I'm using to write this) but I still wish that things were easier. As I've previously written, the beauty of micro.blog is that it is essentially what Winer is after: blogging via a social-esque interface. The difference is that it is hosted rather than something you can host on your own and "install as easily as an app on your iPhone." The pieces are all there just not put together in a package that anyone could use.