• I am trying to restrict access to Modern Events Calendar (MEC) generated slugs, but can’t seem to find an easy way to do it. MEC automatically generates ‘/events’, ‘/events/event-name’, and ‘/event-category/category-name’ slugs where it serves event calendar content. There is nowhere in MEC to move these to manually created pages or where the UM settings show up.

    Is there a way to have UM enforce login restrictions for a slug and all sub-slugs, like ‘/events/*’ or ‘/event*’? Happy to hard code this in a php extension in my theme, but no clue what WordPress event to hook or what UM functions to call. Any help would be greatly appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Shaun

    (@shaunco)

    I managed to piece the following hook together. Please note that I had to modify UM/core/class-access.php to have both $allow_access and $redirect_handler be public, as the setting allow_access to false does absolutely nothing if redirect_handler is false.

    
    // Modern Event Calendar is members only
    add_filter("um_access_check_global_settings","um_access_check_for_MEC", 9999 );
    function um_access_check_for_MEC(){
        $current_url = UM()->permalinks()->get_current_url(get_option('permalink_structure'));
       
        // Are we are somewhere in a MEC page (/events/, /events/*, or /event-category/*)?
        if(strpos($current_url,'/events/') !== false || strpos($current_url,'/event-category/') !== false) { 
    
            // Check if the user is a member
            $user = wp_get_current_user();
            if(!isset($user) || !in_array('um_member', (array) $user->roles)) {
                // User is not not logged in or is not a member, prevent access
                UM()->access()->allow_access = false;
                UM()->access()->redirect_handler = UM()->access()->set_referer(esc_url(add_query_arg('redirect_to', urlencode_deep($current_url), um_get_core_page('login'))), 'global');
            }
        }
    }
    
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @shaunco,

    Have you tried enabling the restriction of the event tags and category via UM > Settings > Access?

    Regards,

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Path or Plug-in Based Restrictions?’ is closed to new replies.