Revision preview not showing changes

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 );

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer