• Hello,

    I have bought the Contributors Can add-on since our site is Page-oriented. All is working well, but it would be tremendously valuable for the reviewer/publisher of Revisionized pages to be able to diff them against the currently published version of that page.

    When in edit mode on a Revisionized page, logged in as an admin, the Publish sidebar widget does not have the Revisions line as I am used to seeing with normal published pages. Is there a way for admins/editors to use the WordPress version comparison/diffing tool to easily see proposed changes against the published version?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author jamiechong

    (@jamiechong)

    Hmm, interesting feature. I agree it’d be a cool to have this. Will add it to my list, but unfortunately can’t investigate it for another few weeks at least.

    Anonymous User 16042088

    (@anonymized-16042088)

    I have done it for one of my projects. I hope this code help you:

    <?php
    
    if ( is_admin() && apply_filters( 'revisionize_user_can_publish_revision', current_user_can( 'publish_posts' ) || current_user_can( 'publish_pages' ) ) ) {
    	add_action(
    		'admin_menu',
    		function () {
    			add_posts_page(
    				'Revision difference',
    				'Revision difference',
    				'manage_options',
    				'revision-difference',
    				'render_revision_difference_page'
    			);
    		}
    	);
    
    	add_action(
    		'post_submitbox_start',
    		function () {
    			$parent = get_post( get_post_meta( get_the_id(), '_post_revision_of', true ) );
    
    			if ( $parent && get_the_ID() !== $parent->ID ) : ?>
    				<p>
    					<?php
    					printf(
    						'<a href="%s&original_post_id=%s&revised_post_id=%s&_wpnonce=%s" target="_blank"><strong>Show differences</strong></a>',
    						esc_url( menu_page_url( 'revision-difference', false ) ),
    						esc_attr( $parent->ID ),
    						esc_attr( get_the_ID() ),
    						esc_attr( wp_create_nonce( 'revision-difference' ) )
    					);
    					?>
    				</p>
    			<?php
    			endif;
    		}
    	);
    }
    
    /**
     * Render admin page for revision differences
     */
    function render_revision_difference_page() {
    	if ( empty( $_GET['original_post_id'] ) && empty( $_GET['revised_post_id'] ) && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'revision-difference' ) ) {
    		wp_die( 'You can not access this page directly.' );
    	}
    
    	$original_post_id = sanitize_text_field( wp_unslash( $_GET['original_post_id'] ) );
    	$revised_post_id  = sanitize_text_field( wp_unslash( $_GET['revised_post_id'] ) );
    
    	if ( ! is_numeric( $original_post_id ) || ! is_numeric( $revised_post_id ) ) {
    		wp_die( 'URL is malformed.' );
    	}
    
    	require ABSPATH . 'wp-admin/includes/revision.php';
    
    	global $title;
    
    	?>
    	<h1><?php echo esc_html( $title ); ?></h1>
    	<?php
    
    	$revision_data = wp_prepare_revisions_for_js(
    		get_post( $original_post_id ),
    		$revised_post_id,
    		$original_post_id
    	);
    
    	foreach ( $revision_data['diffData'] as $posts ) {
    		foreach ( $posts['fields'] as $field ) {
    			?>
    			<h3><?php echo esc_html( $field['name'] ); ?></h3>
    			<?php
    			echo $field['diff'];
    		}
    	}
    }
    

    @novecode this is so far working great, yet it does not work with ACF, is there a simple way to make the ACF fields show up?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Compare Revision with Published Page’ is closed to new replies.