Automattic / babble

Multilingual WordPress done right.
https://wordpress.org/plugins/babble/
246 stars 50 forks source link

Translations failing "You are not allowed to edit posts as this user" #322

Open mkjonesuk opened 9 years ago

mkjonesuk commented 9 years ago

Background: We have a translation team of 'Editor' role who are trying to translate a few 100 posts written by other people. When they try to save the Translation (either In Progress or Complete) it throws the "You are not allowed to edit posts as this user" error.

Note that this error also happens for users of the 'Administrator' role.

This error only seems to happen when users try and translate other peoples Posts. I can Publish a Post myself and translate it no problem. But I can't translate anyone else's content.

For weeks we've assumed some weird permissions issue is to blame which was related to an unsanctioned WordPress upgrade on the live site but today we discovered that the same issue is on our local development site and staging site. It wan't picked up before because we had not tried Translating other users Posts, only our own that we had added for testing purposes.

Debug error from the Translations panel:

_Catchable fatal error: Argument 1 passed to Babble_Jobs::get_post_meta_to_translate() must be an instance of WPPost, null given, called in /siteremoved/wp-content/plugins/babble/class-jobs.php on line 1070 and defined in /siteremoved/wp-content/plugins/babble/class-jobs.php on line 1207

Running WP 4.3 and Babble 1.5.1

mattwatsoncodes commented 9 years ago

Hey @mkjonesuk I think these are two separate issues.

The permissions issue can be fixed by adding a snippet similar to the following in your functions.php:

function add_theme_caps() { // gets the author role $role = get_role( 'editor' ); $role->add_cap( 'read' ); $role->add_cap( 'edit_bbl_jobs' ); $role->add_cap( 'edit_others_bbl_jobs' ); $role->add_cap( 'edit_published_bbl_jobs' ); $role->add_cap( 'edit_private_bbl_jobs' ); $role->add_cap( 'publish_bbl_jobs' ); $role->add_cap( 'delete_bbl_jobs' ); $role->add_cap( 'delete_others_bbl_jobs' ); $role->add_cap( 'delete_published_bbl_jobs' ); $role->add_cap( 'delete_private_bbl_jobs' );

// This only works, because it accesses the class instance.
// would allow the author to edit others' posts for current theme only
$role->add_cap( 'edit_others_posts' );

} add_action( 'admin_init', 'add_theme_caps');

The error that is getting dumped to screen is because one of the posts associated with the translation job has been deleted. It can be mitigated by wrapping the if statement on line 1207 with a if( $post != null) statement.

If I've got it terribly wrong then someone from the Babble team can probably correct me :)

Matt