• Resolved dhewlette

    (@dhewlette)


    Hello everyone,

    I’m using the Alkivia Open Community plugin to give all of my members a stylized, public profile. Up until now, I’ve been using Register Plus to collect my custom user information at registration. I’ve taken this information and displayed almost all of it on each member’s public profile using the following code:

    <?php
    if ( is_user_logged_in() && ! empty($user->phone) ) {
    _e(‘Phone: ‘, $text_domain); echo $user->phone; }
    ?>

    This code will only display the member’s phone number if 1) the page visitor is logged in and 2) there is a phone number in the database for this member. Most of my custom user fields will be logged-in only, but some of them are open to the public (like name, etc.).

    However, the CIMY user extra plugin calls all of the extra field information by userid. I’m unsure how to replace “$user->phone” above with a variable that will work in this setting.

    I believe that Alkivia pulls the username right from the URL, but I don’t know how ot take that username, convert it to the userID, and then query the CIMY user extra fields database to see if a certain field of a certain user is empty or not.

    Does anyone know how I might do this?

    Thanks!

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

    (@dhewlette)

    Well I managed to figure it out on my own. Its probably really ugly code, but I’ll explain whats going on.

    First off, to recap: I’m using CIMY user extra fields and Alkivia Open Community plugins to expand wordpress’ built in user profile feature. CIMY plugin is for collecting, storing, and displaying any custom user data I want…Alkivia is for displaying custom member profiles publicly.

    ISSUE:
    Display CIMY user extra fields data on an Alkivia “profile page.” This is an issue because Alkivia calls of its information based on usernames which it pulls from the URL of the profile page (eg, the profile page is something like …profiles/user/JBlow).

    CIMY user extra field uses user_ID to display data.

    FIX (don’t laugh if this is obvious to you!):

    add the following code to the top of your Alkivia profile page

    <?php $user1 = get_userdatabylogin($username);
    		$useridnum = $user->ID;
    		?>
    
    <?php $user_ID = $useridnum ;?>

    This will set the “user1” variable to the user_ID of the member of the profile page you are looking at. The rest of the code just renames this variable to the standard “user_ID”

    Now, you call CIMY and set its return to a given variable using the following code

    <?php $cimyphone = get_cimyFieldValue($user_ID, 'PHONE') ;?>

    Here I simply ask CIMY for the value of the user extra field called “PHONE” (give teh user ID of the owner of this profile page) and set it equal to “$cimyphone” for later use. I do this because I want to do one more little trick before I display the results to the world…

    Now, using that newly created cimyphone variable, I do the following to display it wherever I want:

    <?php
    if ( is_user_logged_in() && ! empty($cimyphone) ) {
        _e('Phone: ', $text_domain); 	echo cimy_uef_sanitize_content($cimyphone); }
    ?>

    Here I check to see if the person viewing the profile page is logged in and to see if there is anything in the user extra field called above (“PHONE”). If both of these are true (user is logged in and there is stuff in this field), then I go ahead and display the information.

    I’ve done this to make sure public site visitors who are not members can not get sensitive member information. However, some fields are public (like name) and thus don’t have the Is_user_logged_in part. What’s great about this though, is that the information won’t display if the CIMY user extra field is blank.

    And you can just repeat this for all of your CIMY fields, ensuring they have a unique variable when they are called:

    <?php $SomeVariable = get_cimyFieldValue($user_ID, 'PHONE') ;?>

    Hope that helps some else out there, because I struggled with it for a while.

    Thanks.

    You can also do a conditional statement depending on whether the field is empty or not.

    <?php $values_by_name = array(  // Assign defaults to all CIMY fields
          'SOMEFIELD' => '',
          'SOMEOTHERFIELD' => ''
       );
       $values = get_cimyFieldValue($author, false);
       if ($values) {
          foreach ($values as $value) {
             $values_by_name[$value['NAME']] = cimy_uef_sanitize_content($value['VALUE']);
          }
       }; ?>

    Place your extra fields to be called to be used later.

    <?php if (empty($values_by_name['SOMEFIELD'])) : ?>
    Do something if it's emtpy.
    <?php else :?>
    It's not empty so we'll output the field contents: <?php echo $values_by_name['SOMEFIELD']; ?>
    <?php endif;?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Cimy User Extra Fields] Display user extra fields with username, not ID’ is closed to new replies.