How To Allow Anyone To Preview A Post Without Logging In

Previewing is an important part of the publishing process and generally requires the previewer to be logged into WordPress.

But what if you want someone to do a one-off review? Perhaps you’ve written about them, or they are an expert on the subject matter. Creating a WordPress account, getting them to log in and then deleting the account when the process is finished is a little excessive.

Wouldn’t it be easier just to send them a private link, with a configurable expiry date, that took them straight to the content and only that content? Of course it would and here’s how.

Composite image showing preview button
Allow anyone to preview a post without logging in

Every now and then, you stumble across a plugin that solves a problem that’s so obvious that you wonder why you hadn’t gone looking for a solution in the first place.

The Public Post Preview plugin is one such plugin.

This plugin (and we’ll add another just to extend its functionality with the expiry date) allows you to send a URL to anyone that will allow them to preview a post – and only that post – without having to log into the host WordPress site.

It does this by appending a NONCE onto the normal preview URL which bypasses the login requirement for the post in question. If the URL is altered in any way, such as changing the post ID, then request will fail.

What’s A NONCE?

A NONCE is a “Number used ONCE” and is designed to make URLs unique and tied to a specific request. You can find out much more about NONCEs and how they operate in WordPress in the NONCE entry in the Codex.

Using the Public Post Preview Plugin

screenshot of the Publish metabox with the new Enable public preview function
Share this link for login-less previews

Install the plugin via the admin interface: there’s no configuration required.

You should now find a new Enable public preview checkbox in the Publish metabox for unpublished posts.

Selecting public Preview toggles the display of an unique URL that you can provide to your external previewers.

Deselecting, disables public preview meaning that the link won’t work. Publishing the post also disables the link.

Changing the Default Expiry Date For Preview Links

By default, the preview link is valid for 48 hours but this can be overridden. Very handily, this code has already been wrapped up in the snappily titled Public Post Preview Configurator plugin which also adds a Settings panel in which the expiry time (in hours) can be entered.

With these two plugins installed, you’ll be able to allow anyone to preview a post on your site without logging in, which will save you and the previewer a lot of fiddling around with logins.

Plugin Details

Public Post Preview

Requires: 3.5 or higher
Compatible up to: 3.8.1
Last Updated: 2013-12-28
Downloads: 17,767
Rating:4.8 / 5.0 (29 ratings)

0 of 2 support threads in the last two months have been resolved.

Public Post Preview Configurator

Requires: 3.5 or higher
Compatible up to: 3.7.1
Last Updated: 2013-12-18
Downloads: 114
Rating:5.0 / 5.0 (1 rating)

1 of 1 support threads in the last two months have been resolved.

Both plugins tested on WordPress 3.8.1 running in multisite mode.

UPDATE: Allowing For Custom Status

One potential flaw with this plugin is that it only provides a preview link for posts with a status of draft, pending or future. If you are using a plugin such as via Edit Flow, then the link is not going to be available when a post has a custom status.

We can get around this by hacking the plugin code slightly to change the status check.

Open public-post-preview.php and scroll down to the post_submit_misc_actions function (approx line 135). Replace

{code}

if ( ! in_array( $post->post_status, array( ‘draft’, ‘pending’, ‘future’ ) ) )

{/code}

with

{code}

if ( in_array( $post->post_status, array( ‘draft’, ‘publish’) ) )

{/code}

The change means that if the post status is draft or publish then a preview link won’t be made available, the net affect being that it will be for any other status, including custom status. Add any other status to this list as appropriate.