• Resolved veeamdan

    (@veeamdan)


    I have a member directory that only logged on users can see. When a user is logged on, I want them to be able to see the birth dates of their children but I don’t want other users to see those birth dates. This is when someone is logged on and viewing (read only) the membership directory.

    For the profile owner, they should see:

    Child Name
    Child Date of Birth

    Other members, when logged on and viewing another members profile card, should only see:

    Child Name

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @veeamdan

    You can try this code snippet:

    add_filter("um_ajax_get_members_data","um_030321_profile_avatar_members_data", 10, 3 );
    function um_030321_profile_avatar_members_data( $data_array, $user_id, $directory_data ){
    
        $current_user_id = get_current_user_id();
        if( isset( $data_array['birth_date'] ) && $current_user_id != $user_id ){
            unset( $data_array['birth_date']) ;
        }
       
        return $data_array;
    
    }

    In the above example, we show the meta with meta key birth_date to the currently logged-in user in the member directory.

    Regards,

    Thread Starter veeamdan

    (@veeamdan)

    Hi Champ, where do I place that code? Thanks!

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @veeamdan

    You can add the code snippets in the theme’s functions.php file or use the Code Snippet plugin: https://www.ads-software.com/plugins/code-snippets/

    Regards,

    Thread Starter veeamdan

    (@veeamdan)

    Quick follow up. That worked for the default birthdate field. Not sure if it will work for the custom date of birth fields I created. They have custom field names. I assume I just edit the code to add those fields. I think I can do that.

    Secondly, I need the code to only allow admins to see these date fields. Can you share the code to add to only allow accounts with admin access? Thank you!

    Thread Starter veeamdan

    (@veeamdan)

    I was able to create filter code (based on your code above) for the custom fields. Now I need to filter the member’s age field (birth_date) so that only admins can see that field when viewing profiles.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Hide fields on profile card’ is closed to new replies.