Skip to:
Content
Pages
Categories
Search
Top
Bottom

Displaying email address in profile


  • stunley
    Participant

    @stunley

    I added the following code (from this post) to enable email addresses in user profiles – which works but only when a user is logged in.

    How can I change it to show the email address regardless of whether one is logged in or not?

    function tiquality_add_custom_field() {
    
    	if ( bp_is_active( 'xprofile' ) ) :
    
    		if ( is_user_logged_in() ) {
    ?>
    	<div class="bp-widget <?php bp_the_profile_group_slug(); ?>">
    		<table class="profile-fields">
    			<tr class="my_mail">
    
    				<td class="label">Contact me</td>
    
    				<td class="data"><a href="mailto:<?php bp_displayed_user_email(); ?>"><?php bp_displayed_user_email(); ?></a></td>
    
    			</tr>
    		</table>
    	</div>
    <?php 
    		}
    	endif; 
     
    }
    add_action('bp_profile_field_buttons', 'tiquality_add_custom_field');

    I tried deleting the line…

    if ( is_user_logged_in() ) {

    but it took down the whole site.

    WP v 4.7.1

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

  • shanebp
    Moderator

    @shanebp

    >I tried deleting the lineā€¦ if ( is_user_logged_in() ) {

    You need to also delete the closing }

    So

    		}
    	endif; 

    Should be

    		
    	endif; 

    stunley
    Participant

    @stunley

    Hi Shane. Like so? This still disables the site.

    function tiquality_add_custom_field() {
    
    	if ( bp_is_active( 'xprofile' ) ) :
    
    ?>
    	<div class="bp-widget <?php bp_the_profile_group_slug(); ?>">
    		<table class="profile-fields">
    			<tr class="my_mail">
    
    				<td class="label">Contact me</td>
    
    				<td class="data"><a href="mailto:<?php bp_displayed_user_email(); ?>"><?php bp_displayed_user_email(); ?></a></td>
    
    			</tr>
    		</table>
    	</div>
    <?php 
    
    	endif; 
     
    }
    add_action('bp_profile_field_buttons', 'tiquality_add_custom_field');

    shanebp
    Moderator

    @shanebp

    What does your error.log say?

    You might try using this hook instead: bp_after_profile_field_content


    stunley
    Participant

    @stunley

    [18-Jan-2017 13:09:06 UTC] PHP Parse error: syntax error, unexpected ‘endif’ (T_ENDIF) in /home/******/public_html/wp-content/plugins/bp-custom.php on line 20


    shanebp
    Moderator

    @shanebp

    It works for me, there must me some other issue in your file.


    stunley
    Participant

    @stunley

    Sorry Shane, all sorted – I forgot the opening and closing php tags!

    The new action though didn’t do anything however the original ones do.

    Thank you.

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