diff --git a/docs/documentation/06-WordPress Integration/previews.md b/docs/documentation/06-WordPress Integration/previews.md index 479bec59e..6baa97165 100644 --- a/docs/documentation/06-WordPress Integration/previews.md +++ b/docs/documentation/06-WordPress Integration/previews.md @@ -154,7 +154,7 @@ The `preview.usePostLinkForRedirect` was added in `@headstartwp/next@1.3.3` and This becomes even more useful when you have a more complicated permalink structure, let's say your `news` post type adds the category name to the url such as `/news/political/news-name`. If both your Next.js project and WordPress are following the same permalink structure, no additional logic is required to get previews to work. Previously permalinks like this would require providing custom logic in `getRedirectPath`. -Note that by default, `draft` posts will not have a pretty permalink, instead, they have something like `domain.com/?p=id` so HeadstartWP adds a new rest field for all public post types called: `_tenup_preview_link` which will return a pretty permalink even for draft posts. This field will be used by the previewHandler for draft posts. +Note that by default, `draft` posts will not have a pretty permalink, instead, they have something like `domain.com/?p=id` so HeadstartWP adds a new rest field for all public post types called: `_headless_wp_preview_link` which will return a pretty permalink even for draft posts. This field will be used by the previewHandler for draft posts. If you are overriding permalink in WordPress via filter you must ensure that draft posts have a fallback post name. e.g: diff --git a/packages/next/src/handlers/previewHandler.ts b/packages/next/src/handlers/previewHandler.ts index bbfd441f6..746683de7 100644 --- a/packages/next/src/handlers/previewHandler.ts +++ b/packages/next/src/handlers/previewHandler.ts @@ -202,13 +202,13 @@ export async function previewHandler( if (preview?.usePostLinkForRedirect) { if ( result.status === 'draft' && - typeof result._tenup_preview_link === 'undefined' + typeof result._headless_wp_preview_link === 'undefined' ) { throw new Error( - 'You are using usePostLinkForRedirect setting but your rest response does not have _tenup_preview_link, ensure you are running the latest version of the plugin', + 'You are using usePostLinkForRedirect setting but your rest response does not have _headless_wp_preview_link, ensure you are running the latest version of the plugin', ); } - const link = result._tenup_preview_link ?? result.link; + const link = result._headless_wp_preview_link ?? result.link; return removeSourceUrl({ link: link as string, backendUrl: sourceUrl ?? '' }); } diff --git a/wp/headless-wp/includes/classes/Preview/PreviewLink.php b/wp/headless-wp/includes/classes/Preview/PreviewLink.php index da1a29bd7..3e4a337c2 100644 --- a/wp/headless-wp/includes/classes/Preview/PreviewLink.php +++ b/wp/headless-wp/includes/classes/Preview/PreviewLink.php @@ -18,7 +18,7 @@ class PreviewLink { public function register() { add_filter( 'template_include', [ $this, 'handle_preview' ], 20 ); - // only add _tenup_preview_link for preview authenticated requests + // only add _headless_wp_preview_link for preview authenticated requests if ( PreviewToken::get_payload_from_token() ) { add_action( 'rest_api_init', [ $this, 'add_preview_link_field' ] ); } @@ -35,7 +35,7 @@ public function add_preview_link_field() { foreach ( $post_types as $post_type ) { register_rest_field( $post_type, - '_tenup_preview_link', + '_headless_wp_preview_link', [ 'get_callback' => function ( $post_object ) { return $this->get_draft_permalink( get_post( $post_object['id'] ) );