• Resolved dbacksbst

    (@dbacksbst)


    I am having the exact same issue as the poster on this thread, however the issue was marked as closed. I would prefer something better than the “workaround” described at the end. Is there a hook that I might be able to use?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Jean A

    (@jeanabarquez)

    Hi @dbacksbst,

    Thanks for opening this thread!

    We do have this Knowledgebase article on how to hide the calendar from logged-out users.

    Could you please try that one first and see if it works?

    Regards,
    Jean

    Thread Starter dbacksbst

    (@dbacksbst)

    Hello Jean,

    I tried your suggestion, and it looks like the filter tribe_events_pre_get_posts is never called when the events calendar page is loaded (https://mydomain.com/events/month), so the redirect function is not triggered.

    I also tried the suggested “Additional precaution” which uses the posts_where filter, which did hide all the events from the calendar, but the calendar page itself still loaded.

    Is there a different filter you could suggest?

    Thanks,
    Marie

    • This reply was modified 2 years, 2 months ago by dbacksbst.
    • This reply was modified 2 years, 2 months ago by dbacksbst.
    • This reply was modified 2 years, 2 months ago by dbacksbst.
    Plugin Support Darian

    (@d0153)

    @dbacksbst If you’re using V6 of The Events Calendar, then?tribe_events_pre_get_posts will never run since that’s the v1 hook.

    In the meantime, you could?use?pre_get_posts?with a high priority (like 100 – to be sure we’ve already modified it) – it also passes the query.

    Let me know how it goes.

    Thread Starter dbacksbst

    (@dbacksbst)

    Hi Darian,

    I just tried using pre_get_posts with priority 100, but the result is still the same. As an aside, all of my other pages were (and still are) redirecting properly before any changes.

    • This reply was modified 2 years, 2 months ago by dbacksbst.
    • This reply was modified 2 years, 2 months ago by dbacksbst.
    Plugin Support Darian

    (@d0153)

    Hi @dbacksbst

    Thanks for your message.

    Could you provide the snippet code you’re using and the version of the following? This will help me understand how your system is set up.

    • PHP
    • WordPress
    • The Events Calendar
    • Theme
    Thread Starter dbacksbst

    (@dbacksbst)

    • PHP: 7.4
    • WordPress: 6.1.1
    • The Events Calendar:
      • TEC: 6.0.6.2
      • TEC Pro: 6.0.5.1
      • TEC Filter Bar: 5.4.1
    • Theme: Custom

    Code:

    add_filter('pre_get_posts', 'my_restrict_events', 100);
    function my_restrict_events($query) {
      if (!$query->is_main_query() || !$query->get('eventDisplay')) {
        return;
      }
    
      // The result is the same even if this block is commented out.
      $current_user = wp_get_current_user();
      if (is_user_allowed($current_user)) {
        return;
      }  
    
      // Redirect!
      wp_safe_redirect('not-authorized');
      exit;
    }
    Plugin Support Darian

    (@d0153)

    Hi @dbacksbst

    It seems the redirect is not working.

    Is ‘not-authorized’ a slug of a page? If so, could you replace the following

    // Redirect!
    wp_safe_redirect('not-authorized');

    to

    // Redirect!
    $url = get_permalink( get_page_by_path( 'not-authorized' ) );
    header('Location: '.$url);

    Let me know how it goes.

    Thread Starter dbacksbst

    (@dbacksbst)

    Hi Darian,

    Your suggestion fixed the issue, thanks! However, 'not-authorized' is a page slug, and I use it in redirects elsewhere without issue, so I am still confused about why it doesn’t work here. Do you have an explanation?

    Plugin Support Darian

    (@d0153)

    Hi @dbacksbst

    Thanks for your response.

    I am not sure as well. The only thing I found with the snippet is that the redirect was not working. That is why I use an alternative way to redirect the user.

    Please let me know if you have further questions or concerns.

    Plugin Support Darian

    (@d0153)

    Hi @dbacksbst

    This thread has been inactive for a while, so we’ll go ahead and mark it Resolved. Please open a new thread if any other questions arise, and we’d be happy to help.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Redirect from Events Calendar page not working (part 2)’ is closed to new replies.