• Resolved filatovdanyl

    (@filatovdanyl)


    When creating a revision (which is a draft) and doing some changes in it and then clicking on preview – the preview doesn’t show any changes (even though draft was saved). I figured it’s because it was using original post’s permalink and basically showing it instead of revision. I’ve come up with a fix which I’ll post below

Viewing 1 replies (of 1 total)
  • Thread Starter filatovdanyl

    (@filatovdanyl)

    My fix is to change the permalink in revision by adding some unique slug to it and then removing that when publishing it back into original post:

    
    // revisionize: revision draft preview not showing changes - fix
    
    add_action( 'revisionize_after_create_revision', function( $original_id, $revision_id ) {
    	// adding a unique slug to revision permalink that will be removed when publishing it back to original
    	$add_slug = '-revisionize_some_slug';
    	// updating post_name didn't work with revisionize to change permalink of revision. post_name was actually empty on revision post
    	$permalink = get_post_meta( $revision_id, 'custom_permalink', true );
    	if ( substr( $permalink, -1 ) === '/' ) {
    		$permalink = substr( $permalink, 0, -1 ) . $add_slug . '/';
    	} else {
    		$permalink .= $add_slug;
    	}
    	update_post_meta( $revision_id, 'custom_permalink', $permalink );
    }, 10, 2 );
    
    add_action( 'revisionize_before_publish', function( $original_id, $revision_id ) {
    	// removing our unique slug from permalink before publishing revision into original
    	update_post_meta( $revision_id, 'custom_permalink', str_replace( '-revisionize_some_slug', '', get_post_meta( $revision_id, 'custom_permalink', true ) ) );
    }, 10, 2 );
Viewing 1 replies (of 1 total)
  • The topic ‘Revision preview not showing changes’ is closed to new replies.