User Access Manager
IF/Else - how to show menu to members in UAM group (6 posts)

  1. bathory
    Posted 5 years ago #


    My php isn't amazing and I'm struggling with retrieving the value of a field in the UAM database so I can show a menu to only logged in users in the group I created called "members".

    I got as far as this...

    			global $wpdb;
    			$members = $wpdb->get_var(
    			"SELECT *
    			FROM  diamint_uam_accessgroups
    			GROUP BY groupname
    			ORDER BY groupname
    			LIMIT 	0, 30");
    			echo '<p>User is in group '.$members . '</p>';

    Returns "User is in group 1" (regardless of whether or not you're logged in - so it's not quite what I need)

    I need to get the correct syntax for the following...

    <?php if ( $user_ID) && ( $members = "1") ?>		
        <?php wp_nav_menu( array('menu' => 'Members' )); ?>
        <?php else : ?> 	
         <?php wp_nav_menu( array('menu' => 'Main Nav' )); ?>
         <?php endif; ?>

    [Please post code snippets between backticks or use the code button.]


  2. Adam Backstrom
    Posted 5 years ago #

    I'm new to the user-access-manager plugin, but it may be something like this, using the UAM API:

    global $userAccessManager;
    $uamAccessHandler = $userAccessManager->getAccessHandler();
    var_dump( $userAccessManager->getUserGroups() );

    That would dump out the contents of that getUserGroups() method, which may be a jumping-off point to the next step (actually checking that the user is in the group).

  3. bathory
    Posted 5 years ago #

    Yeah that next bit is the part I really need.

    I know it's something like this...

    if ( is_user_logged_in()  &&  IN THE GROUP MAGIC () ) {
    	 global $wpdb;
    			$members = $wpdb->get_var(
    			"SELECT groupname
    			FROM  diamint_uam_accessgroups ");
    			wp_nav_menu( array('menu' => 'Members' ));
    wp_nav_menu( array('menu' => 'Main Nav' ));

    [Please post code snippets between backticks or use the code button.]

    but that's where I'm stuck bc PHP isn't my strong suit!

    Thanks :)

  4. udip
    Posted 5 years ago #

    Why don't you learn basics of PHP with w3resource PHP tutorial.

  5. bathory
    Posted 5 years ago #

    It's not part of my core skill set and my workload is too high to futz around when someone who does have it as a skill set could probably solve this dilemma in a few minutes.

  6. juggledad
    Posted 5 years ago #

    If I'm not mistaken, the SQL has no where clause so it will return ALL rows in the table. You are probably getting an array ($members) which is why you get the number 1. Try using 'print_r($members)' and see what shows up.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • User Access Manager
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic