Description
We’d like to support the WordPress preview functionality for both the decoupled and the embedded mode, so it the CMS experience remains the same.
Possible solution
We could use the Embedded mode to support the preview in the decoupled. We’d need a WordPress plugin for that. This was our first idea:
The JWT generated contains information in its payload about:
- The expiring time
- The post ID
The expiring time for the normal preview is 60 seconds, enough time to send the request to Frontity and Frontity send the request back to the REST API. After those 60 seconds it is not valid anymore.
A new token is generated for each request (each time the user clicks on the Preview button). That is because each time the expiring time changes, that means that the payload is different and the token is different.
The expering time for the publicly sharable link is infinite. That means that the token is always the same. To avoid having to save token in the database, just a post meta "public-share"
setting is saved. The non-expiring token is only valid if that post meta is true. Disabling the sharable link simply turns the "public-share"
meta to false.
The secret key used is a constant that the user needs to define in wp-config.php
named PREVIEW_AUTH_KEY
but it defaults to SECURE_AUTH_KEY
if missing.
CURRENT STATUS SUMMARY
Please, bear in mind that this section wasn’t part of the opening post. It has been added afterwards and its purpose is to keep a quick summary with the most relevant information about this FD at the top of the thread.
There is already a working proof of concept of the preview in the Embedded mode proof of concept. This will be a functionality of the Frontity PHP plugin.
You can see a demo on this post: