Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save bappi-d-great/ccadd4aceb242d77a7b7 to your computer and use it in GitHub Desktop.

Select an option

Save bappi-d-great/ccadd4aceb242d77a7b7 to your computer and use it in GitHub Desktop.
Hide WPMU events that are associated to a BP group
<?php
function custom_posts_events( $query ){
if( ! is_admin() && ! is_super_admin() ){
if( is_archive() ){
$grps = BP_Groups_Member::get_group_ids( get_current_user_id() );
$marr['relation'] = 'OR';
$marr[] = array(
'key' => 'eab_event-bp-group_event',
'value' => '0',
'compare' => '='
);
foreach( $grps['groups'] as $grp ){
$marr[] = array(
'key' => 'eab_event-bp-group_event',
'value' => $grp,
'compare' => '='
);
}
if( $query->query['post_type'] == 'incsub_event' ){
$query->set( 'meta_query', $marr );
}
}
}
}
add_action( 'pre_get_posts', 'custom_posts_events' );
add_filter( 'template_redirect', 'hide_group_events' );
function hide_group_events(){
if( ! is_admin() && ! is_super_admin() ){
global $post;
if( is_singular() ){
if( get_post_type( $post ) == 'incsub_event' ){
$meta = get_post_meta( $post->ID, 'eab_event-bp-group_event', true );
if( $meta > 0 ){
if( ! groups_is_user_member( get_current_user_id(), $meta ) ){
wp_redirect( 'http://localhost/ttt' );
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment