• Resolved Ibby

    (@ibby)


    Hi,
    We use the Groups plugin to restrict access to staff calendar events on our website. It is currently a tedious process as we have to do this for every individual event.
    I just wanted to enquire in case you have a sample snippet we could add to our functions.php which will automate this process as staff sometimes forget to do this and these events were accessible through search engines.
    Thank you!

Viewing 1 replies (of 1 total)
  • Plugin Author Kento

    (@proaktion)

    Hi!

    You could hook into the wp_insert_post action like I show below.

    Note that I’ve not tested the code and it assumes that you’d be using a group named “Staff” to protect those events and that your events custom post type is “event”:

    
    add_action( 'wp_insert_post', 'my_event_auto_assign', 10, 3 );
    
    function my_event_auto_assign( $post_id, $post, $update ) {
        if ( !$update ) {
            if ( $post->post_type === 'event' ) {
                $group = Groups_Group::read_by_name( 'Staff' );
                if ( $group ) {
                    Groups_Post_Access::create(
                        array(
                            'post_id' => $post_id,
                            'group_id' => $group->group_id
                        )
                    );
                }
            }
        }
    }
    

    Cheers

Viewing 1 replies (of 1 total)
  • The topic ‘Auto-add post from custom taxonomy into group on publish’ is closed to new replies.