1

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.

  • Will translator deal with pages as well? – Frank P. Walentynowicz Jun 9 '17 at 1:56
  • I am interested with anything that can help me, I mean only posts or posts and pages, but the most important right now is posts. – AFA Med Jun 9 '17 at 14:11
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.