Forum Replies Created

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter valosip

    (@valosip)

    I’ll take a guess and say that you made an error in the format. It worked by adding one at a time with a new function and its working fine after following their plugin code:

    <?php
    add_filter( 'if_menu_conditions', 'my_new_menu_conditions' );
    function my_new_menu_conditions( $conditions ) {
      if (function_exists("EWD_FEUP_Get_All_Users")) {
        $conditions[] = array(
          'name'    =>   __( 'FEUP is logged in', 'if-menu' ),
          'condition' =>  'if_FEUP_is_logged_in'
        );
      }
        if (function_exists("EWD_FEUP_Get_All_Users")) {
        $conditions[] = array(
          'name'    =>   __( 'FEUP Level 1', 'if-menu' ),
          'condition' =>  'if_FEUP_Level_1'
        );
      }
      return $conditions;
    }
    
    function if_FEUP_is_logged_in() {
              $CheckCookie = CheckLoginCookie();
              $currentUser = $CheckCookie['Username'];
              if( $currentUser ) return true;
              return false;
    }
    
    function if_FEUP_Level_1() {
              global $wpdb;
              global $ewd_feup_user_table_name, $ewd_feup_levels_table_name;
              $FEUP = new FEUP_User;
                if($FEUP->Is_Logged_In()){
                $Level_ID = $wpdb->get_var("SELECT Level_ID FROM $ewd_feup_user_table_name WHERE User_ID='" . $FEUP->Get_User_ID() . "'");
                $Level = $wpdb->get_var("SELECT Level_Privilege FROM $ewd_feup_levels_table_name WHERE Level_ID='" . $Level_ID . "'");
                }
              if( $Level == 1 ) return true;
              return false;
    }
    Thread Starter valosip

    (@valosip)

    post your code. I ran this on my test site and it works

    Thread Starter valosip

    (@valosip)

    Try the below. I quickly wrote it, it should work in theory. But im sure there is a better way.
    You’ll need to add a different condition for each user level…

    let me know if it works

    add_filter( 'if_menu_conditions', 'my_new_menu_conditions2' );
    function my_new_menu_conditions2( $conditions ) {
      if (function_exists("EWD_FEUP_Get_All_Users")) {
        $conditions[] = array(
          'name'    =>  'FEUP Level 1', // name of the condition
          'condition' =>  function($item) {          // callback - must return TRUE or FALSE
              global $wpdb;
              global $ewd_feup_user_table_name, $ewd_feup_levels_table_name;
              $FEUP = new FEUP_User;
                if($FEUP->Is_Logged_In()){
                $Level_ID = $wpdb->get_var("SELECT Level_ID FROM $ewd_feup_user_table_name WHERE User_ID='" . $FEUP->Get_User_ID() . "'");
                $Level = $wpdb->get_var("SELECT Level_Privilege FROM $ewd_feup_levels_table_name WHERE Level_ID='" . $Level_ID . "'");
                }
              if( $Level == 1 ) return true;
              return false;
          }
        );
      }
      return $conditions;
    }

    Thread Starter valosip

    (@valosip)

    I don’t have the premium FEOP, i think user levels are only for premiums?
    So I haven’t looked into that.
    I’m assuming it might be possible though, if you check user level

    Thread Starter valosip

    (@valosip)

    add something like this in a functions.php or in a plugin.
    It’s not perfect, but it allowed me to demonstrate the functionality for my friend. I’ll return to this later to clean it up, or wait and see if the devs of the plugin will add this into their code. Hope it helps

    add_filter( 'if_menu_conditions', 'my_new_menu_conditions' );
    function my_new_menu_conditions( $conditions ) {
      if (function_exists("EWD_FEUP_Get_All_Users")) {
        $conditions[] = array(
          'name'    =>  'FEUP is logged in', // name of the condition
          'condition' =>  function($item) {
              $CheckCookie = CheckLoginCookie();
              $currentUser = $CheckCookie['Username'];
              if( $currentUser ) return true;
              return false;
          }
        );
      }
      return $conditions;
    }
    Thread Starter valosip

    (@valosip)

    If you’re using the “if menu” plugin, you can just add your own menu conditions by following the code below:

    // theme's functions.php or plugin file
    add_filter( 'if_menu_conditions', 'my_new_menu_conditions' );
    
    function my_new_menu_conditions( $conditions ) {
      $conditions[] = array(
        'name'    =>  'If single custom-post-type', // name of the condition
        'condition' =>  function($item) {          // callback - must return TRUE or FALSE
          return is_singular( 'my-custom-post-type' );
        }
      );
    
      return $conditions;
    }
    Thread Starter valosip

    (@valosip)

    I ended up using the “if menu” plugin and added the FEUP option into that.
    So I can easily select menu options from the admin.

    screen shot

    Thread Starter valosip

    (@valosip)

    So I ended up looping though and finding which user is logged in.

    But im sure there is an easier, faster way. please let me know if so:

    ` if (function_exists(“EWD_FEUP_Get_All_Users”)) {
    $Users = EWD_FEUP_Get_All_Users();
    }
    foreach ($Users as $User) {
    if($User->Is_Logged_In()){
    echo $User->Get_Username(). ” is logged in \n”;
    } else {
    echo $User->Get_Username(). ” is not logged in \n”;
    }
    }`

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