Allow a non-author to see revisions of a post

I have a specific workflow of authoring in my website.

An author publishes a new post, then an automatic version with another language is generated and assigned to another user (translator).

I want this translator to be able to see revisions, I mean when he requests the page /wp-admin/revision.php?revision=450 he must see the history of changes as if he is the owner of the file, but The translator cannot edit the original post (written in the default language).

I dived a little bit in admin/revision.php file, but I think there must be better alternatives.

1 Answer
1

Basic solution

Let’s create new role translator, with capabilities matching capabilities of author role. Insert the code below to functions.php of your current theme:

function wpse_add_translator_role() {
    if ( empty( get_role( 'translator' ) ) ) { 
        $role = get_role( 'author' );
        add_role( 'translator', 'Translator', $role->capabilities );
    }
}
add_action( 'init', 'wpse_add_translator_role', 10 );

Once the role translator is created, you can remove the code above from functions.php, or just comment out add_action line:

// add_action( 'init', 'wpse_add_translator_role', 10 );

Template modification

Find template used to display single post. Immediately after the_content(); tag insert the code below:

$user = wp_get_current_user();
if( 0 != $user->ID ) {
    if( in_array( 'translator', $user->roles ) ) {
        global $post;
        $revisions = wp_get_post_revisions( $post->ID );
        if( !empty( $revisions ) ) {
            echo '<div id="revisions" style="clear:both"><h3>Revisions</h3>';
            foreach ( $revisions as $revision ) { 
                echo 'ID = '; echo $revision->ID; ?>
                <textarea rows="10"><?php echo addslashes( $revision->post_content ) ?></textarea><?php
            }
            echo '</div>';
        }
    }   
}

Prepare translator(s)

Edit every user who is a translator and change his role to translator.

Test

Login as translator and select a single post. You should see its content and all available revisions.

Final notes

The code inserted into your template can be further modified, to display revisions for posts of other authors only. This part is easy, therefore, I’m leaving it up to you.

It is important to remember that all changes, mentioned above, should be applied to the child theme, not the original one.

Leave a Comment