Skip Navigation

[Resolved] Access custom restriction not working while editing on parent post

This support ticket is created 8 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 -
- - - - - - -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

Tagged: 

This topic contains 9 replies, has 3 voices.

Last updated by Adriano 8 years, 2 months ago.

Assisted by: Adriano.

Author
Posts
#368830

Hi,

I have two custom post types. Book (parent) and Book-Chapter (child). A book can have multiple book-chapters.

The default role of 'Author' in wordpress have 'Publish Their Own Content' right in 'Book' Custom Post type.
But in 'Book-Chapter' custom post type, Author cannot publish their own content. If I add 'Book-Chapter custom post type' from Add New and see editing screen it shows 'Submit for review' button and every thing works fine as per rights assigned.

But if Author will go in Book CPT (parent) and add child from child table (new custom post book-chapter) and save it using save button in table, the book-chapter directly get published, not following the same rule configured in access.

Can you please look into it why book-chapter is not following the Access rules?

Thanks,

Khurram

#368841

Just updated Toolset to newest version. Haven't updated any settings and now when creating child post from parent post screen, it says 'You do not have rights to create new items'.

#368889

Is there any update? As my live site is suffering from this issue. Thanks.

#369033

Dear Khurram,

Thanks for the details, I can duplicate same problem, and put it into our to-do list, our developers will take care of it.

#369373

Hello,

I’m Adriano, Toolset support lead and I have been escalated to this thread. I’ll give my best to help you to achieve your needs through Toolset components.

I need to request temporary access (wp-admin and FTP) to your site in order to be offering better help. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

#369649

Well, I did some tests in local and here are my findings:

1. Created an author that can publish in Book but can't in Book Chapter.
2. When I'm logged as him, I can publish a new book but I can't publish a Book Chapter, I receive the message you described above. Isn't it the expected behavior?

#369853
trouble pic 2.png
trouble pic 1.png

You are right about 'Publishing' rights of book-chapter as I disabled author publish rights from book-chapter.

But the problem is not with 'publishing', its with adding new record. To regenerate the problem please follow following statements.

If I go from dashboard admin menu ;
Book Chapters->Add New->[I can add and 'Submit for review' rather than 'Publish' which is default behavior and is correct].

But if I go from Books to any existing book and try to 'Add New Book Chapter' in children grid it says 'You do not have right to create new record'. Ideally this 'Add New Book Chapter' from parent (book) screen shall replicate the functionality as adding new 'Book Chapter' from its own screen. The difference between 'Publish' and 'Submit for review' shall not bother adding child data either from child's own menu or from parent's menu.

I have attached two images "trouble pic 1" is showing clicking on 'Add New Book Chapter' from parent screen and "trouble pic 2" is showing the error message on top of children grid.

Hope this will be sufficient to understand the bug.

Regards,
Khurram

#369904

That makes total sense now, let me forward this issue to our development team.

Meanwhile I've crafted a workaround for you. You will need to check publish for author in Book Chapter. Then you will need to add the code below in functions.php:

add_action( 'save_post', 'change_post_to_draft' );

function change_post_to_draft( $post_id ){
	$has_permissions = true;
	if ( 
		class_exists( 'Access_Helper' ) 
		&& class_exists( 'TAccess_Loader' )
	) {
		$role = Access_Helper::wpcf_get_current_logged_user_role();
		if ( $role == 'author' ) {
			$has_permissions = false;
		} else if ( ! current_user_can( 'publish_posts' ) ) {
			$has_permissions = false;
		}
	} else {
		if ( ! current_user_can( 'publish_posts' ) ) {
			$has_permissions = false;
		}
	}
	if( !$has_permissions ){
		remove_action( 'save_post', 'change_post_to_draft' );
		$my_post = array(
			'ID' => $post_id,
			'post_status' => 'draft'
		);
		wp_update_post( $my_post );
		add_action( 'save_post', 'change_post_to_draft' );
	}
}

This will always check if the current user is an author, then it will change the status of the post from published to draft.

Please let me know if you are satisfied with my reply and any other questions you may have.

Regards,

Adriano Ferreira

#370461

Hi Adriano,

I have implemented the function and it is working fine. What would be the status for 'Submit for review'?
And how can we track the implementation of this bug, as is there any feature implementation tracking online?

Thanks,
Khurram

#370607

The status will be draft, native one from WP. We are working to improve this in the future, so you won't need this workaround sometime soon.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.