Skip to:
Content
Pages
Categories
Search
Top
Bottom

Unhide Profile Email Adresses

  • I would like to make email addresses viewable in member profiles to all of my forum members (but not unregistered viewers). By default, email addresses are only viewable to admins. How can I change this?

Viewing 8 replies - 1 through 8 (of 8 total)
  • On line 2368 of functions.bb-template under bb-includes dir of your bbPress resides the code you want to change.

    bb_current_user_can( 'edit_users' )

    Editing a core file is not recommended but I am unsure of how to mask it to call a custom function instead of the core function.

    If its unmaskable for now (architectural) and you want a fix, then either you can change that bb_current_user_can( 'edit_users' ) with bb_is_user_logged_in() but you will have to do it again when you upgrade (or till someone posts a recommended fix) or you can append this line in your profile.php after the call to the bb_profile_data()

    <?php
    if ( bb_is_user_logged_in() ) {
    echo $user->user_email;
    }?>

    [untested but should work]

    With what I understand, the thing is only functions in functions.bb-pluggable.php can be masked (plugged) as its the last file to look for undefined functions. Defining any function which is there overrides the definition in that file. But what if we need to change the behaviour of a function which is somewhere else?

    I would love to see someone prove me wrong.


    chrishajer
    Participant

    @chrishajer

    Maybe you could add that capability to the member role?

    https://bbpress.org/plugins/topic/role-manager/

    @chrishajer

    Won’t such a workaround will be an overkill?

    And am I write about the pluggable nature of functions in the above post?

    I’m not sure what you mean about overkill… but I’ve gone to huge lengths to avoid hacking the core in the past, and it’s almost always been worth it.

    Hacking the core is really inadvisable, as it makes upgrades extremely difficult!

    <?php

    function add_email_spec_meta( $arr ) {

    if( !bb_is_user_logged_in() || bb_current_user_can( 'edit_users' ) )
    return $arr;

    if( bb_get_location() != 'profile-page' || stripos( $_SERVER[ 'QUERY_STRING' ], 'tab=edit' ) !== false )
    return $arr;

    $arr['email_spec'] = $arr['user_email'];

    global $wp_users_object;

    $id = bb_get_current_user_info( 'id' );

    $meta_key = 'email_spec';

    $meta_value = bb_get_usermeta( $id, 'user_email' );

    $wp_users_object->update_meta( compact( 'id', 'meta_key', 'meta_value' ) );

    return $arr;

    }
    add_filter( 'get_profile_info_keys', 'add_email_spec_meta' );

    ?>

    @johnhiler

    Using the plugin to change roles of a member is overkill in my opinion. I am not in favor of hacking core files either. My method of adding a check for user logged in & then spitting out the code should be enough for the required functionality. Along with a user logged in check it should also check if current user is not an admin so that email addresses are not repeated for admins.


    @Kawauso

    I put your code in functions.php and it didn’t seem to work.

    With a normal user on my test setup, I wasn’t able to see the admin’s email id

    Thanks for the replies!

    I wouldn’t mind installing a plugin to accomplish this, but I tried out Role Manager and it didn’t have any option for displaying emails.

    Ashfame, I just went with your method of putting it in profile.php. It’d be nice to not have it as a per template thingy, but it works fine for now. You’re right about it needing to check to see if the current user is an admin to prevent duplicates. I’m new to bbpress so I don’t know if there’s a proper way to do this or not, but I figure the admin is the only one who can edit users, so I plopped in this little guy:

    <?php

    if ( bb_is_user_logged_in() && !bb_current_user_can( 'edit_users' ) ) {

    echo 'user_email .'">' . $user->user_email . '';

    }

    ?>

    It seems to work.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Skip to toolbar