From 76223e6f007012a0762f0613bd1a9769030c6c61 Mon Sep 17 00:00:00 2001 From: Clay Griffiths Date: Thu, 4 Feb 2021 16:27:04 -0600 Subject: [PATCH] feat: add support for previewing drafts from WP (note: Gutenberg not yet supported) https://github.com/WordPress/gutenberg/issues/4555 https://github.com/WordPress/gutenberg/issues/13998 --- plugins/wpe-headless/includes/replacement/callbacks.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/wpe-headless/includes/replacement/callbacks.php b/plugins/wpe-headless/includes/replacement/callbacks.php index a40e3fa0e..41448949c 100644 --- a/plugins/wpe-headless/includes/replacement/callbacks.php +++ b/plugins/wpe-headless/includes/replacement/callbacks.php @@ -130,7 +130,13 @@ function wpe_headless_post_preview_link( $link, $post ) { /** * Add preview and preview ID back to path to support Next.js preview mode */ - $path = trailingslashit( $path ) . 'preview/' . $preview_id; + if ($post->post_status !== 'publish') { + $path = 'draft/'; + } else { + $path = $path ? trailingslashit( $path ) : ''; + } + + $path .= 'preview/' . $preview_id; $link = add_query_arg( array(