New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post translator not displaying for users without the edit_post capability #286

Closed
luisarn opened this Issue Sep 28, 2017 · 2 comments

Comments

2 participants
@luisarn

luisarn commented Sep 28, 2017

Version Information

  • PHP: 7.1.9
  • WordPress: 4.8.2

Steps to Reproduce

  1. Create a custom post type (content_page) with custom capabilities name using map_meta_cap:
    content_page_edit, content_page_delete, content_page_publish, ... and so on.
  2. Create a custom role (Content Editor) and assign those capabilities to that role and assign an user to that role
  3. Enable the Custom Post Type Translator on Multilingual Press settings for the post type "content_page"
  4. Use the Content Editor user to edit the content_page custom post type

What I Expected

To be able to use the Post Translator.

What Happened Instead

Post Translator not showing up.

Proposed solution

After digging into the code on Mlp_Translation_Metabox.php I found out that the required capabilities are hard coded on line 186 (edit_posts) and 189 (edit_post):

` private function is_translatable_by_user( WP_Post $post, $blog_id ) {

	$blog_id = absint( $blog_id );

	$remote_post = $this->data->get_remote_post( $post, $blog_id );
	if ( isset( $remote_post->dummy ) && $remote_post->dummy === true ) {
		return current_user_can_for_blog( $blog_id, 'edit_posts' );
	}

	return current_user_can_for_blog( $blog_id, 'edit_post', $remote_post->ID );
}`

So I updated the function / method to get the current post type mapped edit_posts and edit_post capability to make it work:

` private function is_translatable_by_user( WP_Post $post, $blog_id ) {

	$blog_id = absint( $blog_id );

	$remote_post = $this->data->get_remote_post( $post, $blog_id );
	// Need to get current CPT edit post cap.
	$post_type = get_post_type_object( $post->post_type );
	if ( isset( $remote_post->dummy ) && $remote_post->dummy === true ) {
		return current_user_can_for_blog( $blog_id, $post_type->cap->edit_posts );
	}
	return current_user_can_for_blog( $blog_id, $post_type->cap->edit_post, $remote_post->ID );
}`

Best regards,
Luis

@tfrommen tfrommen added this to the v2.10.0 milestone Sep 28, 2017

@tfrommen

This comment has been minimized.

Show comment
Hide comment
@tfrommen

tfrommen Sep 28, 2017

Contributor

Hi there,

good catch! 👍

We already fixed this for the next major version, but simply forgot to backport this, which we wanted to and now will do.

Contributor

tfrommen commented Sep 28, 2017

Hi there,

good catch! 👍

We already fixed this for the next major version, but simply forgot to backport this, which we wanted to and now will do.

@tfrommen

This comment has been minimized.

Show comment
Hide comment
@tfrommen

tfrommen Sep 28, 2017

Contributor

Fixed in f8ebb23.

Contributor

tfrommen commented Sep 28, 2017

Fixed in f8ebb23.

@tfrommen tfrommen closed this Sep 28, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment