Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Profile Fields Displaying Twice When Logged in


  • rezon8dev
    Participant

    @rezon8dev

    Hello,
    I have a new issue which has popped up after updating to the newest BP 2.3.3. I have altered the member/ profile-loop.php and when a user is logged in they now see their profile fields displayed 2 times. There are 3 shortcodes echo’ed on this page and the 2 from rtmedia are the only items on the page which are not displaying twice, the 3rs (events manager) is also displaying 2x just as the profile fields and xprofile fields are. I’m assuming it has to do with the php I’ve entered but I cannot for the life of me find the issue. Any help would be great, as this issues is only visible when a user is logged in a site link probably wont help much. Everything is up to date and running on WPE/HHVM with php 5.5.
    Here is the contents on my member-profile.php

    <?php $user_ID = bp_displayed_user_id(); ?>
    <?php do_action( 'bp_before_profile_loop_content' ); ?>
    
    <?php if ( bp_has_profile() ) : ?>
    
    	<?php while ( bp_profile_groups() ) : bp_the_profile_group(); ?>
    
    		<?php if ( bp_profile_group_has_fields() ) : ?>
    
    			<?php do_action( 'bp_before_profile_field_content' ); ?>
    
    			<div class="bp-widget <?php bp_the_profile_group_slug(); ?>">
    
    		
    				<div class="hr-title hr-full hr-double"><abbr><?php bp_the_profile_group_name(); ?></abbr></div>
    				<div class="gap-10"></div>
    		
    					<?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
    
    						<?php if ( bp_field_has_data() ) : ?>
                  
                  
                  
                  <dl<?php bp_field_css_class('dl-horizontal'); ?>>
                    <dt><?php bp_the_profile_field_name(); ?></dt>
                    <dd><?php bp_the_profile_field_value(); ?></dd>
                  </dl>
                  
    
    						<?php endif; ?>
    
    						<?php do_action( 'bp_profile_field_item' ); ?>
    
    					<?php endwhile; ?>
    
                            
                            
                            
    			</div><!-- end bp-widget -->
    
    			<?php do_action( 'bp_after_profile_field_content' ); ?>
    
    		<?php endif; ?>
    
    	<?php endwhile; ?>
    
    	<?php do_action( 'bp_profile_field_buttons' ); ?>
    
    <?php endif; ?>
    
    <?php do_action( 'bp_after_profile_loop_content' ); ?>
    
    <?php if(bp_is_my_profile() ) 
    {
     ?>
    
    <?php if(pmpro_hasMembershipLevel(array(1,2,3)))
    {
     ?>
    
    <div class="bp-widget">
    	<div class="epkpmgallery">
    		
    		<div class="hr-title hr-full hr-double"><abbr>Promotional Media</abbr></div>
    						<div class="gap-10"></div>
    	
    		<div class="hr-title hr-full"><abbr>Pics</abbr></div>
    
    	</div>
    
    	<div class="epkpgallery">
    
    <?php echo do_shortcode( '[rtmedia_gallery media_type="photo" global="false" attribute_slug="epk-photo" term_slug="current-press-photo" per_page="20" context="profile" media_author="' .$user_ID. '" media_title="true" lightbox="false"]' ); ?>
    
        </div>
    
    		
    		<div class="hr-title hr-full"><abbr>Songs</abbr></div>
        
       
    
        <div class="epkagallery">
    
    <?php echo do_shortcode( '[rtmedia_gallery media_type="music" global="false" attribute_slug="epk-album" term_slug="current-album" per_page="40" context="profile" media_author="' .$user_ID. '" media_title="true" lightbox="false"]' ); ?>
    
        </div>
    </div>
    
    <div class="bp-widget">
    	<div class="epkggallery">
    		
    		<div class="hr-title hr-full hr-double"><abbr>Upcoming Gigs</abbr></div>
    						<div class="gap-10"></div>
    <a id="epkanc"></a>
    
    <?php echo do_shortcode( '[events_list owner="' .$user_ID. '"]' ); ?>
        </div>
    </div>
    
    <hr>
    
    <div class="epkgalleryprint">
    				<section class="container-wrap main-color" style=""><div class="section-container container"><div class="row">
    	<div class="col-sm-12 wpb_column column_container">
    		<div class="wpb_wrapper">
    				<div class="vc_btn3-container vc_btn3-center"><a class="vc_general vc_btn3 vc_btn3-size-lg vc_btn3-shape-rounded vc_btn3-style-outline vc_btn3-block vc_btn3-icon-left vc_btn3-color-success" href="javascript:window.print()" title="Print Your Press Kit" target="_blank"><i class="vc_btn3-icon fa fa-file-pdf-o"></i>Print Press Kit</a></div>
    		</div> 
    	</div> 
    </div></div></section><!-- end section -->
    </div>
    
    <?php 
    }
     ?>
    <?php 
    }
     ?>
Viewing 25 replies - 1 through 25 (of 25 total)

  • shanebp
    Moderator

    @shanebp

    >they now see their profile fields displayed 2 times.

    Rhetorical questions:
    As 2 sets or double entries?
    Does the issue remain if you remove the 3rd shortcode?

    It should be easy to narrow it down by following the clues given when you explore those questions.


    rezon8dev
    Participant

    @rezon8dev

    They see the duplicated fields as 2 sets, so fields 1-5 and then again fields 1-5. After trying to remove the 3rd shortcode the issue still persists…


    rezon8dev
    Participant

    @rezon8dev

    @shanebp I appreciate your confidence, unfortunately I’m lost and have not gotten anything that is helping me narrow things down, not from logs or debug either….


    shanebp
    Moderator

    @shanebp

    This is basic debugging…
    Does the issue remain if you use the standard profile-loop.php?
    Where do the duplicate sets appear?
    Did you try making small changes rather than add all the custom code at once?
    Etc, etc.


    rezon8dev
    Participant

    @rezon8dev

    @shanebp, I’ve tracked it down but still cant figure out what is wrong. This was all working until I upgraded to the latest bp… It is in my functions file for my theme, it is this function to place 3 xprofile fields in the member header area:

    /** 
     *  Add extended profile fields to the member profile header area  
    */
    
    add_action( 'bp_profile_header_meta' , 'display_user_xprofile_fields' );
    function display_user_xprofile_fields() {
    
     	$artistname = bp_get_member_profile_data('field=Artist Name');
        $musicalgenre = bp_get_member_profile_data('field=Musical Genre');
        $location = bp_get_member_profile_data('field=Location');
    
        if ($artistname || $musicalgenre || $location) {
    
            echo '<div class="mdetcenter artist"><h4 class="user-nicename">'. '' . $artistname . '</h4></div>';
            echo '<div class="mdetcenter genre">'. '' . $musicalgenre . '</div>';
            echo '<div class="mdetcenter location">'. '' . $location . '</div>';
        }
    }

    Can you see what is wrong? This is driving me crazy…


    shanebp
    Moderator

    @shanebp

    If you think you’ve found a bug in 2.3.3, you can submit a ticket here.
    Be sure to include some screenshots.


    rezon8dev
    Participant

    @rezon8dev

    OK will do @shanebp.
    Can anyone give me a hand and let me know if this code looks proper? Even if I remove this from my child theme functions.php file and add the following to my member-header.php file:

    
    bp_member_profile_data( 'field=Artist Name' );
    bp_member_profile_data( 'field=Musical Genre' );
    bp_member_profile_data( 'field=Location' );

    I get similar results; the custom fields being displayed multiple times, oddly when I add the above to the member-header.php I get the Artist name field showing 4 times in a row rather than repeating sets of fields 1-4 and then fields 1-4 again duplicating when the code in a previous post above is in the functions file…


    rezon8dev
    Participant

    @rezon8dev

    Has anyone seen the duplicating profile fields issue happen when displaying xprofile fields in the member header before?


    danbp
    Participant

    @danbp

    Is your child theme working correctly with Kleo ?
    Is the altered member-header.php file in your child-theme ?
    Do you really use a file called member-profile.php, as stated in your first topic ? Bad !

    Remove all your custom snippets and revert back to original BP template fisrt, then try this in bp-custom.php:

    function custom_display_xprofile_fields() {
    
    echo 'Custom display fields';
    echo '<ul>';
    if ( $data = bp_get_profile_field_data( 'field=Artist Name' ) ) : 
    	echo '<li>'. xprofile_get_field_data( 'Artist Name', bp_displayed_user_id() ) .'</li>';
    endif;
    
    if ( $data = bp_get_profile_field_data( 'field=Musical Genre' ) ) : 
    	echo '<li>'. xprofile_get_field_data( 'Musical Genre', bp_displayed_user_id() ) .'</li>';
    endif;
    
    if ( $data = bp_get_profile_field_data( 'field=Location' ) ) : 
    	echo '<li>'. xprofile_get_field_data( 'Location', bp_displayed_user_id() ) .'</li>';
    endif;
    
    echo '</ul>';
    }
    add_action( 'bp_profile_header_meta' , 'custom_display_xprofile_fields' );
    add_filter( 'bp_before_member_header_meta', 'custom_display_xprofile_fields' );

    rezon8dev
    Participant

    @rezon8dev

    Is your child theme working correctly with Kleo ?
    Is the altered member-header.php file in your child-theme ?

    Yes and Yes..

    Do you really use a file called member-profile.php, as stated in your first topic ? Bad !

    How else would I override the buddypress file unless it was in my child theme with the same name?

    I’ll give this a go and report back, thank you very much!


    rezon8dev
    Participant

    @rezon8dev

    I guess I see how, I would use my bp-custom.php plugin file but I thought overriding files in this manor was the acceptable way to do it? I guess it makes sense that if the file changes shi* will break…


    danbp
    Participant

    @danbp

    How else would I override the buddypress file unless it was in my child theme with the same name?

    You should NOT override core files. The only files you alter from child theme are template files.

    To alter core functions, you use custom functions and add them via filter hooks, preferably added to bp-custom.php – so you won’t loose your work at next update.

    member-profile.php doesn’t exist in BuddyPress.

    Codex is your friend !

    Theme Compatibility & Template Files

    Displaying Extended Profile Fields on Member Profiles

    … and forum search too. 😉


    rezon8dev
    Participant

    @rezon8dev

    OK this mostly worked and I do not know how to fix the portion that is not working. I’ve entered this:

    /*
    * Add xprofile fields to member header
    */
    function custom_display_xprofile_fields() {
    
    if ( $data = bp_get_profile_field_data( 'field=Artist Name' ) ) : 
    	echo '<div class="mdetcenter artist"><h4 class="user-nicename">'. xprofile_get_field_data( 'Artist Name', bp_displayed_user_id() ) .'</div>';
    endif;
    
    if ( $data = bp_get_profile_field_data( 'field=Musical Genre' ) ) : 
    	echo '<div class="mdetcenter genre">'. xprofile_get_field_data( 'Musical Genre', bp_displayed_user_id() ) .'</div>';
    endif;
    
    if ( $data = bp_get_profile_field_data( 'field=Location' ) ) : 
    	echo '<div class="mdetcenter location">'. xprofile_get_field_data( 'Location', bp_displayed_user_id() ) .'</div>';
    endif;
    
    }
    add_action( 'bp_profile_header_meta' , 'custom_display_xprofile_fields' );
    add_filter( 'bp_before_member_header_meta', 'custom_display_xprofile_fields' );
    

    The Musical Genre field is a multi-select field type and the echo is printing “array” rather than the array of selected values in this field…


    @danbp
    can you help here?


    rezon8dev
    Participant

    @rezon8dev

    OK so I switched to bp_member_profile_data() for the Musical Genre field and seem to be getting a result with the proper data but its not taking the formatting still… Almost there…


    rezon8dev
    Participant

    @rezon8dev

    For some reason this line

    if ( $data = bp_get_profile_field_data( 'field=Musical Genre' ) ) : 
    	echo '<div class="mdetcenter genre">'. xprofile_get_field_data( 'Musical Genre', bp_displayed_user_id() ) .'</div>';
    endif;

    Is not printing the div class, it’s just printing the values. I’ve tried to create a new field, first renaming the previous and recreating the new with the same name “Musical Genre” but I’m not getting and <div class=”…. to print. @danbp any ideas?


    rezon8dev
    Participant

    @rezon8dev

    @danbp I’ve also tried it like this without any success:

    if ( $data =  bp_member_profile_data( 'field=Musical Genre' ) ) : 
    	echo '<div class="mdetcenter genre">';
    	echo  xprofile_get_field_data( 'Musical Genre', bp_displayed_user_id() );
    	echo '</div>';
    
    endif;

    rezon8dev
    Participant

    @rezon8dev

    @danbp several searches seemed to turn up that this is an open issue with this field type. What I did was basically workaround and added a echo <br> to the following line in the function which is using bp_get_profile_field_data rather than bp_member_profile_data. If you or anyone can point to the direct so I could properly allow this to output my html classes around a multi-select field type being called with bp_member_profile_data, I would be greatful. @danbp Thanks a million for your assistance!


    danbp
    Participant

    @danbp

    Despite your efforts, it seems that you miss some basics.
    Your class name may be wrong. CSS class names cannot contain spaces.

    Try to use mdetcenter-genre. And do same thing for all other custom class.

    That said, i don’t know why only this div doesn’t show up while the 2 other are showing (?).
    What is the field type of Musical genre being an “open issue” ? A multi-select box ? A checkbox ?…

    The snippet i provided is working and shows up in two places. You can(should) remove the one or the other. Are both places affected by this div issue ? Try with p, but i doubt that it will work better if div or li don’t work. An values ouput has nothing to do with html in this case.

    add_filter is handled near user name, add_action is going underneath all messages buttons.


    rezon8dev
    Participant

    @rezon8dev

    they are 2 classes, do I need “” around each of them?
    This is a multi-select field.
    The other 2 work fine its just the musical genre field that is not printing the classes, or any of the html…


    rezon8dev
    Participant

    @rezon8dev

    Changing the function to this:

    /*
    * Add xprofile fields to member header
    */
    function custom_display_xprofile_fields() {
    
    if ( $data = bp_get_profile_field_data( 'field=Artist Name' ) ) : 
    	echo '<div class="mdetcenter"><div class="artist"><h4 class="user-nicename">'. xprofile_get_field_data( 'Artist Name', bp_displayed_user_id() ) .'</h4></div></div>';
    endif;
    
    if ( $data = bp_member_profile_data( 'field=Musical Genre' ) ) : 
    
    	echo '<div class="mdetcenter"><div class="genre">'. xprofile_get_field_data( 'Musical Genre', bp_displayed_user_id() ) .'</div></div>';
    
    endif;
    
    if ( $data = bp_get_profile_field_data( 'field=Location' ) ) : 
        echo '<br>';
    	echo '<div class="mdetcenter"><div class="location">'. xprofile_get_field_data( 'Location', bp_displayed_user_id() ) .'</div></div>';
    endif;

    Gives me this HTML output:

    	<div class="mdetcenter"><div class="artist"><h4 class="user-nicename">No Way Back</h4></div></div>
    Alternative, Blues, Country, Electronic
    <br><div class="mdetcenter"><div class="location">Detroit, MI. US</div></div>

    danbp
    Participant

    @danbp

    Ok, i see… multiselectbox/checkbox values are returned in a array.

    if ( $data = bp_member_profile_data( 'field=Musical Genre' ) )....endif; thing cannot work, because we have to fetch the whole array of values, not only one.
    Give this a try:

    function custom_display_xprofile_fields() {
    
    if ( $data = bp_get_profile_field_data( 'field=Artist Name' ) ) : 
    	echo '<div class="artist"><h4 class="user-nicename">'. xprofile_get_field_data( 'Artist Name', bp_displayed_user_id() ) .'</h4></div>';
    endif;
    
    if ( $datas = bp_get_profile_field_data( array( 'field' => 'Musical Genre' ) ) ) :
        foreach ( $datas as $data ) { 
           echo '<div class="genre">'. $data .'</div>';
        }
    endif;
    
    if ( $data = bp_get_profile_field_data( 'field=Location' ) ) : 
    	echo '<div class="location">'. xprofile_get_field_data( 'Location', bp_displayed_user_id() ) .'</div>';
    endif;
    }
    add_action( 'bp_profile_header_meta' , 'custom_display_xprofile_fields' );

    rezon8dev
    Participant

    @rezon8dev

    OK yup that does it. A question and one more request. @danbp I really do appreciate this, you’re helping me learn some basic stuff and some more detail on BP in general!

    Question, why does bp_member_profile_data pull in the array data but not print the classes?

    Request, I need the fields returned from musical genre to all be on one line and they should be if all the values of the array are returned wrapped in the class rather than than each of the values being wrapped in the class, I just can’t figure out the syntax to make that happen…

    Thanks a million!


    danbp
    Participant

    @danbp

    why does bp_member_profile_data pull in the array data but not print the classes ?

    1) Because this function handles only the field value and the user ID.

    2) You add the div outside of the array.

    if ( $datas = bp_get_profile_field_data( array( 'field' => 'Service' ) ) ) :
    echo '<div class="whatever">';
    	foreach ( $datas as $data ) { 		
    echo $data.'&nbsp;';
        }
    echo '</div>';
    endif;

    nbsp is needed to space datas


    rezon8dev
    Participant

    @rezon8dev

    And putting , before the &nbsp; I get that comma!
    Thank so much @danbp!
    Case Closed…


    danbp
    Participant

    @danbp

    You’re welcome 😉

Viewing 25 replies - 1 through 25 (of 25 total)
  • The topic ‘[Resolved] Profile Fields Displaying Twice When Logged in’ is closed to new replies.
Skip to toolbar