Plugin Author
Kento
(@proaktion)
Hi,
The contributor cannot restrict access to a post to groups that he does not belong to.
> How do I ensure that the post author can see their own post?
You need to have the user assigned to the corresponding group, otherwise he won’t be able to view the post.
Ceers
The contributor cannot restrict access to a post to groups that he does not belong to.
Ah then this might not be a great feature request.
My use-case is a front-end application where the user can create and restrict posts. For documentation purposes, this is how you could allow post authors to always see their posts regardless of assigned Groups.
/**
* Ensure the post author always has access to their published posts.
*
* This is not needed in a default implementation of Groups.
*
* @param String $sql
* @param WP_Query $query
*
* @return String $sql
*/
function wpf15771076_groups_give_author_access( $sql, $query ) {
global $wpdb;
if( ! is_user_logged_in() ) {
return $sql;
}
return sprintf( 'AND %s OR ( 1=1 %s )',
$wpdb->prepare( "{$wpdb->posts}.post_author = %d", get_current_user_id() ),
$sql
);
}
add_filter( 'groups_post_access_posts_where', 'wpf15771076_groups_give_author_access', 10, 2 );
Plugin Author
Kento
(@proaktion)
Yeah, it’s not something that I would see as a common use case, but the solution for your particular case seems appropriate.
Thanks for sharing your approach!