• Open
  • Michael Sinclair
    Participant
    June 6, 2024 at 10:59 pm #49408

    Hi Evgeny,

    I have another menu query and I hope you might be able to help.

    I was hoping to use “Nav Menu Roles” plugin or similar to control which part of the primary menu shows to logged out and which part shows to logged in members, but because I believe, unless I’m mistaken, Evolve Plus does not use the walker_nav_menu function, it does not work.

    Can you suggest, please, how I might be able to accomplish this, i.e which part of the primary menu is visible to either logged out none members or which part is visible to logged in members?

    Log in details can be provided it will help.

    Thank you

    Evgeny
    Keymaster
    Posts: 997
    June 11, 2024 at 10:57 am #49409

    Hi. Sorry for the delay in my reply. I checked, and Nav Menu Roles works perfectly with Evolve. If you have issues with this, the conflict is not with the theme; it is with something else on your website. Try to find out what by deactivating all other plugins, making sure that everything is working as expected, and then starting to activate them one by one and checking again. You should be able to locate the issue this way.

    Michael Sinclair
    Participant
    Posts: 30
    July 24, 2024 at 4:14 pm #49504

    Hi Evgeny,

    Thank you for your excellent support so far.

    Following on from my last query, I’m hoping to use wp_ redirect(home _url) to control page access and what happens to non registered members.
    The function:
    // Restrict non logged users to certain pages
    function redirect_to_welcome_page() {
    if ( is_page(‘welcome’) || is_page(‘contact’) || is_page(‘about_us’) || is_page(‘login’) || is_page(‘register’) && !is_user_logged_in());
    wp_redirect(home_url( ), ‘302’ );
    exit( );
    }
    add_action(‘init’ , ‘redirect_to_welcome_page’);

    This just produces the error ‘too many redirects’ no matter what I try.

    Using the process of elimination on plugins and themes, there appears to be a conflict with the evolve plus theme, but I could be wrong.

    Any help in suggesting how I can get this function to work without redirect errors would be very much appreciated.

    Thank you

    Evgeny
    Keymaster
    Posts: 997
    July 25, 2024 at 11:14 am #49508

    Hi,
    Please allow me to offer some insights into your code. I see some things that might cause it to work differently than you expect.

    First, the full version of the code how I suggest to implement it:
    function redirect_to_welcome_page() {
    if ( (is_page(‘welcome’) || is_page(‘contact’) || is_page(‘about_us’) || is_page(‘login’) || is_page(‘register’)) && !is_user_logged_in() ) {
    wp_redirect(home_url(), 302);
    exit();
    }
    }
    add_action(‘init’, ‘redirect_to_welcome_page’);

    The differences:
    1. Your if() statement has a precedence issue. && has a higher precedence than ||, so your code works like this:

    if ( is_page(‘welcome’) || is_page(‘contact’) || is_page(‘about_us’) || is_page(‘login’) || (is_page(‘register’) && !is_user_logged_in()))

    And I don’t think that it is what you wanted. Hence the correction.
    2. After the if() statement you put a semicolon. So, you conclude its execution without having it do anything if the statement is true.
    3. the wp_redirect() function expects the redirect number as integer, so I removed the single quotes.

    That’s it, I hope it helps you.

    Evgeny
    Keymaster
    Posts: 997
    July 25, 2024 at 11:15 am #49509

    Oh, and btw, the single quotes are wrong here, but it is because of the forum’s output. You will need to adapt them to standard in your code.