I have a client who relies heavily on a WordPress plugin, Public Post Preview. It's a very useful plugin for publishers who need to proof their content with collaborators or advertising agencies before actually publishing. Without extending WordPress' functionality you could publish the post under password protection or privately requiring a user to log in to your WordPress site. These wouldn't be as convinient as just sending a link as it adds steps for the end user and would create obstructions.
Public Post Preview offers the user a link in a meta box while editing the post. This link is valid for 24 hours and allows a user who is not logged in to preview the content of the post if they have a valid link.
I recently had a situation where Public Post Preview was providing a link which did not work. Rather than seeing the post you want to preview, the URL was responding with a 404 error. Many forum posts were written about this issue that were 12 months or older and the general consensus was that this issue had been solved. I have not delved further into investigating this, but I suspect that the problem persists for me because I use Nginx and PHP FPM rather than the more common Apache configuration. Nevertheless, I needed a quick solution to keep my client able to use Public Post Preview.
My solution was to add this jQuery to the admin area. This code chops up the Public Post Preview link, discovers the post ID and reformats a simple Public Post Preview link that is independent of the permalink structure of the site.
This code targets the Public Post Preview plugin and only in situations where the provided link may not work. In the event that the plugin is fixed, this code will no longer run and will not slow down the admin area.
The easiest way to add this to the admin area is with the following snippet.
A complete example of the code that can be added to functions.php can be found on this Gist.
If I were the author of Public Post Preview it would make the most sense to me to provide a link that is independent of the site's permalink structure in all cases.