[wp-trac] [WordPress Trac] #50964: WordPress view/preview links + post editor don't get along with SPA frontend

WordPress Trac noreply at wordpress.org
Wed Aug 12 21:25:29 UTC 2020


#50964: WordPress view/preview links + post editor don't get along with SPA
frontend
--------------------------+-----------------------------
 Reporter:  fdouchant     |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Editor        |    Version:  5.3
 Severity:  major         |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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
 <?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.

 2. **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

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50964>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list