In WordPress I have a calendar (With the "Events Calendar Plugin"). I want this calendar to be for logged in users only. So I used this code:
add_filter( 'tribe_events_pre_get_posts', 'redirect_from_events' );
function redirect_from_events( $query ) {
// print_r("hey");
if ( is_user_logged_in() )
return;
if ( ! $query->is_main_query() || ! $query->get( 'eventDisplay' ) ){
//print_r("hey");
return;
}
// Look for a page with a slug of "logged-in-users-only".
$target_page = get_posts( [
'post_type' => 'page',
'name' => 'logged-in-users-only'
] );
// Use the target page URL if found, else use the home page URL.
if ( empty( $target_page ) ) {
$url = get_home_url();
print_r($url);
} else {
$target_page = current( $target_page );
$url = get_permalink( $target_page->ID );
print_r($url);
}
// Redirect!
wp_safe_redirect( $url );
exit;
}
add_filter( 'posts_where', 'restrict_events', 100 );
function restrict_events( $where_sql ) {
global $wpdb;
if ( is_user_logged_in() || ! class_exists( 'Tribe__Events__Main' ) ) {
return $where_sql;
}
return $wpdb->prepare( " $where_sql AND $wpdb->posts.post_type <> %s ", Tribe__Events__Main::POSTTYPE );
}
Now I want to cancel this code. I trued commenting it but it's still working. I am not sure but I think I should use Remove_filter to accomplish this. So I created another snippet:
remove_filter( 'tribe_events_pre_get_posts', 'redirect_from_events' );
remove_filter( 'posts_where', 'restrict_events', 100 );
But the code is still working somehow. Please assist cancelling this code.