Make WordPress Core

Opened 4 years ago

Last modified 3 years ago

#50964 new defect (bug)

WordPress view/preview links + post editor don't get along with SPA frontend

Reported by: fdouchant's profile fdouchant Owned by:
Milestone: Awaiting Review Priority: normal
Severity: major Version: 5.3
Component: REST API Keywords:
Focuses: Cc:



I've built a separated frontend (SPA) using WordPress as headless CMS. I managed to allow writers to view/preview posts on the frontend by setting the home_url accordingly.

I also used the preview_post_link filter to rewrite the preview URL and adding a generated nonce I then pass to the API to fetch the post content. Here is the function :

add_filter( 'preview_post_link', 'my_filter_function', 10, 2 );
function my_filter_function($preview_link, $post)
        $nonce = wp_create_nonce('wp_rest');

        return FRONTEND_DOMAIN . '/preview?type=' . $post->post_type . '&id=' . $post->ID . '&nonce=' . $nonce;

Everything worked just fine until I met the new post editor (must be version 5.3 or 5.4 - working with the REST API).

I now have 2 issues :

  1. Saving a post (or cusotm post). It seems the home_url needs to be the same as the site_url (wordpress) overwise it fails to update any post (it makes multiple REST API calls to the home_url). Settings the same URL works but now we can't view a post on the frontend using view links.
  1. Previewing a post (or custom post). In the new block editor, the preview_post_link filter doesn't seem to be called. URL aren't changed so I can't preview my post on the frontend.

I couldn't find anything about similar issues. Could you please help me ?



Change History (2)

This ticket was mentioned in Slack in #core by peterwilsoncc. View the logs.

3 years ago

#2 @chaion07
3 years ago

  • Component changed from Editor to REST API

Hello Fabrice,

I am updating the component as per discussion during a recent triage session. Thanks!

Note: See TracTickets for help on using tickets.