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
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'.
Is there any update? As my live site is suffering from this issue. Thanks.
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.
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.
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?
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
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
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
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.