WordPress.org

Make WordPress Core

Opened 4 months ago

#50964 new defect (bug)

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

Reported by: fdouchant Owned by:
Milestone: Awaiting Review Priority: normal
Severity: major Version: 5.3
Component: Editor Keywords:
Focuses: Cc:

Description

Hi,

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 :

<?php
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 ?

Cheers,

Fabrice

Change History (0)

Note: See TracTickets for help on using tickets.