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'];
}
}
}