• “If Menu” plugin was great in the past, but i bought add-on “More Visibility Rules” for using RCP membership levels, which one doesn’t work due to obsolescent code… I can confirm that because i fix it after several hours of work…

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

    (@jetaimecherie)

    If you bought ‘More Visibility Rules’ this is my fix for RCP :

    From file : …/plugins/if-menu/src/conditions-multiple-options.php
    Snippet of code fixed for conditions-multiple-options.php :

    // Third-party plugin integration - Restrict Content Pro
    if (in_array('restrict-content-pro/restrict-content-pro.php', $activePlugins)) {
        $conditions[] = array(
            'id'        =>  'restrict-content-pro-active',
            'name'      =>  __('Any RCP membership active', 'if-menu'),
            'condition' =>  'rcp_user_has_active_membership',
            'group'     =>  __('User', 'if-menu')
        );
    
        $levelsOptions = array();
        $levels = rcp_get_membership_levels();
    
        if ($levels) {
            foreach ($levels as $level) {
                $levelsOptions[$level->get_id()] = $level->get_name() . ' - Level ' . $level->get_access_level();
            }
        }
    
        $conditions[] = array(
            'id'        =>  'restrict-content-pro',
            'type'      =>  'multiple',
            'name'      =>  __('Has Restrict Membership', 'if-menu'),
            'condition' =>  function($item, $selectedLevels = array()) {
                $userId = get_current_user_id();
    
                if (!$userId) {
                    return false;
                }
    
                //RCP methods library : https://help.solidwp.com/hc/en-us/articles/360053121033-rcp-get-customer-by-user-id
    
                $customer = rcp_get_customer_by_user_id($userId);
                $customerid = $customer->get_id();
    
                $level_ids = rcp_get_customer_membership_level_ids($customerid);
    
                $access = false;
                //$selectedLevels = membership levels ids for the current menu item
                foreach ($selectedLevels as $selectedLevel) {
                    $access = $access || in_array($selectedLevel, $level_ids); //Show menu if at least one membership level allowed 
                }
    
                return $access;
            },
            'options'   =>  $levelsOptions,
            'group'     =>  __('User', 'if-menu')
        );
    
        $conditions[] = array(
            'id'        =>  'restrict-content-pro-expired',
            'name'      =>  __('Expired Restrict Membership', 'if-menu'),
            'condition' =>  'rcp_user_has_expired_membership',
            'group'     =>  __('User', 'if-menu')
        );
    }

    Maybe can do better but it works for me… 🙂

    Hi there!

    You saved my ass!!!

    Your code works so far.

    I will continue testing and using it and will inform in the future how it goes.

    THANKS!!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this review.