• Hi there

    I am currently trying out WordPress 5.0 and I evaluate what has to be fixed on our side.
    Our current Setup: WordPress with REST API and a frontend hosted on another domain. To enable previews for our authors we needed to change the preview links a bit to point to our frontend and send some custom parameters (like the wp-nonce to access autosaves and so on).

    I once started an older thread about custom preview links:
    https://www.ads-software.com/support/topic/preview-changes-with-wordpress-rest-api-authentication-problem/

    Now with WordPress 5 they don’t work anymore.

    If I click on the preview button for the first time it navigates to something like this:
    https://cms.mybackenddomain.ch/wp/wp-admin/post.php?post=87&action=edit which seems to be the core link. The screen I see is just white with an animated WordPress logo – forever.

    If I click a second time on the preview link it navigates to:
    https://frontenddomain.com/87-autosave-v1/?preview_id=104&preview_nonce=c46519a6bb&preview=true

    Which is partly correct:
    https://frontenddomain.com ?
    87-autosave-v1 != post-slug ?
    /?preview_id=104&preview_nonce=c46519a6bb&preview=true ?

    I assume that I can dig a bit into my function which creates the link and resolve the autosave-v1 slug problem, but I don’t know why after a reload the first link is going to the wrong url.

    Does anyone know a change that happened in relation with WP 5 that would break this?

    For the sake of completeness I am posting a simplified version of my preview-link generation function:

    
    function custom_preview_page_link( $link ) {
    	$id = get_the_ID();
    	// For authentication a nonce must be created
    	// otherwise the REST API does not allow users to see previews
    	$nonce = wp_create_nonce( 'wp_rest' );
    	$post = get_post( $id );
    	$slug = $post->post_name;
    
    	$link = $home_path . $slug . '/?preview_id='. $id. '&preview_nonce=' . $nonce . '&preview=true';
    	return $link;
    }
    
    add_filter('preview_post_link', 'custom_preview_page_link');
    
  • The topic ‘Custom preview links not working since WP 5.0’ is closed to new replies.