Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'hide xprofile fields'

Viewing 25 results - 26 through 50 (of 129 total)
  • Author
    Search Results
  • #246500
    danbp
    Moderator

    Hi @ma3ry,

    unable to visit the indicated page due to redirection… BP’s xProfile text box contains are autolinked by default for the 5 first words.
    This is handy when you use a field called city for example. The city name is autolinked and let each user click on it to find other who may entered the same name.

    Of course, an about me box with a long description, which several autolinked words has less interrest. Fortunately, you can deactivate xprofile autolinking.
    Two options for this: all or selected.

    Here 3 snippets. The first can be used if you want to completely remove autolink from all field values.
    The second is a new filter to let you choose the field(s) you want to deactivate. This need two snippet. The first to rewrite a filter and the second to remove / replace the existing BP filter.

    Add the snippet to bp-custom.php.

    // remove any autolink from profile
    function remove_xprofile_links() {
    remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
    }
    add_action( 'bp_init', 'remove_xprofile_links' ); 
    
    // custom filter to selectively remove autolink
    function my_xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) {
    
        // Access the field you are going to display value.
        global $field;
    
        // In this array you write the ids (separated by comma) of the fields you want to hide the link.
        $excluded_field_ids = array(2);
    
        // If the id of this $field is in the array, we return the value only and not the link.
        if (in_array($field->id, $excluded_field_ids))
    	return $field_value;
    	
    	if ( 'datebox' == $field_type )
    	return $field_value;
    	
    	if ( !strpos( $field_value, ',' ) && ( count( explode( ' ', $field_value ) ) > 5 ) )
    	return $field_value;
    	
    	$values = explode( ',', $field_value );
    	
    	if ( !empty( $values ) ) {
    		foreach ( (array) $values as $value ) {
    			$value = trim( $value );
    			
    			// If the value is a URL, skip it and just make it clickable.
    			if ( preg_match( '@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', $value ) ) {
    				$new_values[] = make_clickable( $value );
    				
    				// Is not clickable
    			} else {
    				
    				// More than 5 spaces
    				if ( count( explode( ' ', $value ) ) > 5 ) {
    					$new_values[] = $value;
    					
    					// Less than 5 spaces
    				} else {
    					$search_url   = add_query_arg( array( 's' => urlencode( $value ) ), bp_get_members_directory_permalink() );
    					$new_values[] = '<a href="' . $search_url . '" rel="nofollow">' . $value . '</a>';
    				}
    			}
    		}
    		
    		$values = implode( ', ', $new_values );
    	}
    	
    	return $values;
    }
    
    /**
     * We remove the buddypress filter and add our custom filter.
     */
    function remove_xprofile_links() {
        // Remove the old filter.
        remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
        // Add your custom filter.
        add_filter( 'bp_get_the_profile_field_value', 'my_xprofile_filter_link_profile_data', 9, 2);
    }
    add_action('bp_setup_globals', 'remove_xprofile_links');
    #244685
    Prangesco
    Participant

    Hi @danbp,

    My question may sound obvious so my apologies in advance if that’s the case.

    The issue: I was trying to hide a specific xprofile field group and used the code you provided here https://buddypress.org/support/topic/conditional-exclusion-of-a-xprofile-fields-group-from-editing/ adding it to bpcustom.php.

    It worked as a charm, and the group is currently visible only to logged-in users (both in profile view and profile edit). However I no longer need the group to be publicly hidden, but removing the function and the respective add_filter from bpcustom.php does not seem to work: the group stays visible to logged-in users only.

    Unfortunately I have no idea about how to address this issue, the best clue I could figure out is I might have to remove the filter registered by your bit of code (and yet that’s but a guess as my php knowledge is pretty amateurish). I would really appreciate if you could help me figuring out what’s happened, considering that my only change to your code was using my own group ID number.

    Thanks in advance for you attention.

    #238134
    danbp
    Moderator

    hi @utahman1971,

    this is the default behave of extended profile fields. Also it’s very handy, as those links became searcheable keywords. This let users click and find other entered same words.

    That said, a bio is generally more personnal, so those links maybe less important…

    Here’s a snippet (bp 2.0.1 +) you can add to bp-custom.php. It let’s you selectively disable those automated linking from some fields and let some other in place.

    function my_xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) {
        // Access the field you are going to display value.
        global $field;
        // In this array you write the ids of the fields you want to hide the link.
        $excluded_field_ids = array(2,6,7);
        // If the id of this $field is in the array, we return the value only and not the link.
        if (in_array($field->id, $excluded_field_ids))
    	return $field_value;
    	
    	if ( 'datebox' == $field_type )
    	return $field_value;
    	
    	if ( !strpos( $field_value, ',' ) && ( count( explode( ' ', $field_value ) ) > 5 ) )
    	return $field_value;
    	
    	$values = explode( ',', $field_value );
    	
    	if ( !empty( $values ) ) {
    		foreach ( (array) $values as $value ) {
    			$value = trim( $value );
    			
    			// If the value is a URL, skip it and just make it clickable.
    			if ( preg_match( '@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', $value ) ) {
    				$new_values[] = make_clickable( $value );
    				
    				// Is not clickable
    			} else {
    				
    				// More than 5 spaces
    				if ( count( explode( ' ', $value ) ) > 5 ) {
    					$new_values[] = $value;
    					
    					// Less than 5 spaces
    				} else {
    					$search_url   = add_query_arg( array( 's' => urlencode( $value ) ), bp_get_members_directory_permalink() );
    					$new_values[] = '<a href="' . $search_url . '" rel="nofollow">' . $value . '</a>';
    				}
    			}
    		}
    		
    		$values = implode( ', ', $new_values );
    	}
    	
    	return $values;
    }
    
    /**
     * We remove the buddypress filter and add our custom filter.
     */
    function remove_xprofile_links() {
        // Remove the old filter.
        remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
        // Add your custom filter.
        add_filter( 'bp_get_the_profile_field_value', 'my_xprofile_filter_link_profile_data', 9, 2);
    }
    add_action('bp_setup_globals', 'remove_xprofile_links');

    If you want to deactivate completely profile fied links, you can use this function:

    function bpfr_remove_xprofile_links() {
        remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
    }
    add_action('bp_setup_globals', 'bpfr_remove_xprofile_links'); 
    danbp
    Moderator

    hi @mcpeanut,

    this snippet useable from BP 2.0.1 and above, can be added to bp-custom.php
    it will hide the field ID 1 which is the default Name field to all, except site admin.

    it will also avoid the user to edit that field. So if you use this, i recommand you tell them on register page that once they entered a name it they could change it later. You can than ask them $$$$ to do it. 😀

    function bpfr_hide_profile_field_group( $retval ) {
    	if ( bp_is_active( 'xprofile' ) ) :	
    	
    	// hide profile group/field to all except admin	
    	if ( !is_super_admin() ) {		
    		//exlude fields, separated by comma
    		$retval['exclude_fields'] = '1';  
    		//exlude field groups, separated by comma
    		$retval['exclude_groups'] = '1'; 			
    	} 
    	return $retval;		
    	
    	endif;
    }
    add_filter( 'bp_after_has_profile_parse_args', 'bpfr_hide_profile_field_group' );

    More here:

    Using bp_parse_args() to filter BuddyPress template loops

    evitorino
    Participant

    My wordpress is 4.1 and Buddypress 2.1.1

    Hello Community,

    I am having a problem with a custom member page pagination, when clicking link to pagination page 2, pagination takes us to page 2 and adds the string “?upage=2” to the site URL.

    After that, clicking page 1 or back symbol on pagination links does nothing, only refreshes page.

    Problematic page: http://wp1.kodeserver.net/coach/
    I have set the page above in Twentyfifteen theme as to exclude any third party theme related errors.

    If we use the default member page “http://wp1.kodeserver.net/members/&#8221; then pagination works ok.

    I believe the error might be caused by the member filter i made or maybe i messed up the template.

    Hope you can help.

    Below is the code i am using:

    functions that i use to filter member loop by member types on the site:

    function bp_exclude_users_but_player() {
    $excluded_users_but_player = implode(',',get_users('role=coach&fields=ID'));
    $excluded_users_but_player = $excluded_users_but_player.','.implode(',',get_users('role=seniorcoach&fields=ID'));
    $excluded_users_but_player = $excluded_users_but_player.','.implode(',',get_users('role=subscriber&fields=ID'));
    $excluded_users_but_player = $excluded_users_but_player.','.implode(',',get_users('role=editor&fields=ID'));
    $excluded_users_but_player = $excluded_users_but_player.','.implode(',',get_users('role=administrator&fields=ID'));
    return $excluded_users_but_player;
    }

    function bp_exclude_users_but_coach() {
    $excluded_users_but_coach = implode(',',get_users('role=player&fields=ID'));
    //$excluded_users_but_coach = $excluded_users_but_coach.','.implode(',',get_users('role=seniorcoach&fields=ID'));
    $excluded_users_but_coach = $excluded_users_but_coach.','.implode(',',get_users('role=subscriber&fields=ID'));
    $excluded_users_but_coach = $excluded_users_but_coach.','.implode(',',get_users('role=editor&fields=ID'));
    $excluded_users_but_coach = $excluded_users_but_coach.','.implode(',',get_users('role=administrator&fields=ID'));
    return $excluded_users_but_coach;
    }

    function bp_exclude_users_but_senior_coach() {
    $excluded_users_but_senior_coach = implode(',',get_users('role=player&fields=ID'));
    $excluded_users_but_senior_coach = $excluded_users_but_senior_coach.','.implode(',',get_users('role=coach&fields=ID'));
    $excluded_users_but_senior_coach = $excluded_users_but_senior_coach.','.implode(',',get_users('role=subscriber&fields=ID'));
    $excluded_users_but_senior_coach = $excluded_users_but_senior_coach.','.implode(',',get_users('role=editor&fields=ID'));
    $excluded_users_but_senior_coach = $excluded_users_but_senior_coach.','.implode(',',get_users('role=administrator&fields=ID'));
    return $excluded_users_but_senior_coach;
    }

    function bp_exclude_cc_backend_users() {
    $excluded_cc_backend_users = implode(',',get_users('role=subscriber&fields=ID'));
    $excluded_cc_backend_users = $excluded_cc_backend_users.','.implode(',',get_users('role=editor&fields=ID'));
    $excluded_cc_backend_users = $excluded_cc_backend_users.','.implode(',',get_users('role=administrator&fields=ID'));
    return $excluded_cc_backend_users;
    }

    Member Loop that calls member “Coach” filter:
    <?php if ( bp_has_members( bp_ajax_querystring( 'members').'&exclude='.bp_exclude_users_but_coach().'&per_page=24' ) ) : ?>

    And this is the problematic page template code (The one that filters by role type (coach))

    <?php
    /**
    * The template for displaying all pages
    *
    * This is the template that displays all pages by default.
    * Please note that this is the WordPress construct of pages and that
    * other 'pages' on your WordPress site will use a different template.
    *
    * @package WordPress
    * @subpackage Kleo
    * @since Kleo 1.0
    */

    get_header(); ?>

    <?php get_template_part('page-parts/general-title-section'); ?>

    <?php get_template_part('page-parts/general-before-wrap'); ?>

    <?php
    if ( have_posts() ) :
    // Start the Loop.
    while ( have_posts() ) : the_post();
    /*
    * Include the post format-specific template for the content. If you want to
    * use this in a child theme, then include a file called called content-___.php
    * (where ___ is the post format) and that will be used instead.
    */
    get_template_part( 'content', 'page' );
    endwhile;
    endif;
    ?>

    <?php do_action( 'bp_before_directory_members_page' ); ?>
    <section class="container-wrap main-color">
    <div class="section-container container">

    <div id="buddypress">

    <?php do_action( 'bp_before_directory_members' ); ?>

    <?php do_action( 'bp_before_directory_members_content' ); ?>

    <!--<div id="members-dir-search" class="dir-search" role="search">
    <?php //bp_directory_members_search_form(); ?>
    </div>--><!-- #members-dir-search -->

    <?php do_action( 'bp_before_directory_members_tabs' ); ?>

    <form action="" method="post" id="members-directory-form" class="dir-form">

    <div id="subnav" class="item-list-tabs" role="navigation">

      <!--<li class="selected" id="members-all">"><?php //printf( __( 'All Members <span>%s</span>', 'buddypress' ), bp_get_total_member_count() ); ?>--> <!--Contatore membri totali-->

      <?php //if ( is_user_logged_in() && bp_is_active( 'friends' ) && bp_get_total_friend_count( bp_loggedin_user_id() ) ) : ?>
      <!--<li id="members-personal">"><?php //printf( __( 'My Friends <span>%s</span>', 'buddypress' ), bp_get_total_friend_count( bp_loggedin_user_id() ) ); ?>-->
      <?php //endif; ?>

      <?php //do_action( 'bp_members_directory_member_types' ); ?>

      <?php //do_action( 'bp_members_directory_member_sub_types' ); ?>

      <!--<li id="members-order-select" class="last filter">
      <label for="members-order-by"><?php //_e( 'Order By:', 'buddypress' ); ?></label>
      <select id="members-order-by">
      <option value="active"><?php //_e( 'Last Active', 'buddypress' ); ?></option>
      <option value="newest"><?php //_e( 'Newest Registered', 'buddypress' ); ?></option>

      <?php //if ( bp_is_active( 'xprofile' ) ) : ?>
      <option value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ); ?></option>
      <?php //endif; ?>

      <?php //do_action( 'bp_members_directory_order_options' ); ?>
      </select>
      -->

    </div><!-- .item-list-tabs -->

    <div id="members-dir-list" class="members dir-list">

    <?php

    /**
    * BuddyPress - Members Loop
    *
    * Querystring is set via AJAX in _inc/ajax.php - bp_legacy_theme_object_filter()
    *
    * @package BuddyPress
    * @subpackage bp-legacy
    */

    ?>

    <?php if ( bp_has_members( bp_ajax_querystring( 'members').'&exclude='.bp_exclude_users_but_coach().'&per_page=24' ) ) : ?>

    <div id="pag-top" class="pagination">
    <div class="pag-count" id="member-dir-count-top">
    <?php bp_members_pagination_count(); ?>
    </div>
    <div class="pagination-links" id="member-dir-pag-top">
    <?php bp_members_pagination_links(); ?>
    </div>
    </div>

    <?php do_action( 'bp_before_directory_members_list' ); ?>

    <ul id="members-list" class="item-list row kleo-isotope masonry">

    <?php while ( bp_members() ) : bp_the_member(); ?>

    <?php $user_info = get_userdata(bp_get_member_user_id()); ?>
    <?php
    $user_roles = $user_info->roles;
    $user_role = array_shift($user_roles);

    // echo 'User ID: ' . $user_info->ID . "\n";
    // echo bp_core_get_user_displayname( $user_info->ID ) ;
    // echo $user_info->ID ;
    ?>

    <li class="kleo-masonry-item type-<?php echo $user_role; ?>">

    ID ; ?>' value='show/hide'> <!-- link che apre info's nascoste -->

    <div class="member-inner-list animated animate-when-almost-visible bottom-to-top">

    <div class="item-avatar rounded">
    <!--
    ">
    --> <?php bp_member_avatar( 'type=full&height=150&width=150' ); ?>
    <!--
    -->
    <?php //do_action('bp_member_online_status', bp_get_member_user_id()); ?>
    </div>
    <!-- "> -->
    <div class="item">
    <div class="item-title"><span class="loop-nome"><?php bp_member_name(); ?></span><span class="loop-cognome"><?php bp_member_profile_data( 'field=Cognome' ); ?></span></div>

    <!-- <?php if ( bp_get_member_latest_update() ) : ?>
    <span class="update"> <?php bp_member_latest_update(); ?></span>
    <?php endif; ?>
    -->
    <?php do_action( 'bp_directory_members_item' ); ?>

    <?php
    /***
    * If you want to show specific profile fields here you can,
    * but it'll add an extra query for each member in the loop
    * (only one regardless of the number of fields you show):
    *
    * bp_member_profile_data( 'field=the field name' );
    */
    ?>

    </div>

    </div><!--end member-inner-list-->
    <!-- link che apre informazioni nascoste -->
    <div id="contenuto-nascosto-<?php echo $user_info->ID ; ?>" class="hidden-infos">
    <div class="nascondi-infos">
    ID ; ?>' value='show/hide'>
    <i class="icon-cancel"></i>

    </div>
    <div class="unhidden-infos unhidden-infos-first ">
    <div class="item-avatar-small">
    ">
    <?php bp_member_avatar( 'type=full&height=50&width=50' ); ?>

    <?php do_action('bp_member_online_status', bp_get_member_user_id()); ?>
    </div>
    </div>
    <div class="unhidden-infos">
    <div class="item-title">
    ">
    <span class="loop-nome"><?php bp_member_name(); ?></span>

    ">
    <span class="loop-cognome"><?php bp_member_profile_data( 'field=Cognome' ); ?></span>

    </div>
    </div>
    <div class="unhidden-infos">
    <span class="nomeazienda-titolo custom-title">Azienda:</span>
    <span class="nomeazienda custom-infos"><?php bp_member_profile_data( 'field=Azienda' ); ?></span>
    </div>
    <div class="unhidden-infos">
    <span class="pos-lavorativa-title custom-title">Funzione:</span>
    <span class="pos-lavorativa custom-infos"><?php bp_member_profile_data( 'field=Funzione' ); ?></span>
    </div>
    <div class="unhidden-infos">
    <span class="settore-title custom-title">Settore:</span>
    <span class="settore custom-infos"><?php bp_member_profile_data( 'field=Settore' ); ?></span>
    </div>
    <div class="unhidden-infos">
    <span class="laurea-title custom-title">Laurea:</span>
    <span class="laurea custom-infos"><?php bp_member_profile_data( 'field=Laurea' ); ?></span>
    </div>

    <div class="action">

    <div class="generic-button" id="send-private-message">
    " title="Clicca per profilo completo" class="send-message">Profilo Completo
    </div>

    <?php //do_action( 'bp_directory_members_actions' ); ?>

    </div>
    </div>

    <script type="text/javascript">
    jQuery(document).ready(function(){
    jQuery('#nascondi-mostra-<?php echo $user_info->ID ; ?>').live('click', function(event) {
    jQuery('#contenuto-nascosto-<?php echo $user_info->ID ; ?>').toggle('show');
    });
    });
    </script>

    <?php endwhile; ?>

    <?php do_action( 'bp_after_directory_members_list' ); ?>

    <?php bp_member_hidden_fields(); ?>

    <?php else: ?>

    <div id="message" class="info">
    <p><?php _e( "Sorry, no members were found.", 'buddypress' ); ?></p>
    </div>

    <?php endif; ?>

    <?php do_action( 'bp_after_members_loop' ); ?>

    </div><!-- #members-dir-list -->

    <?php do_action( 'bp_directory_members_content' ); ?>

    <?php wp_nonce_field( 'directory_members', '_wpnonce-member-filter' ); ?>

    <?php do_action( 'bp_after_directory_members_content' ); ?>

    </form><!-- #members-directory-form -->

    <?php do_action( 'bp_after_directory_members' ); ?>

    </div><!-- #buddypress -->

    </div>
    </section>

    <?php do_action( 'bp_after_directory_members_page' ); ?>

    <?php get_template_part('page-parts/general-after-wrap'); ?>

    <?php get_footer(); ?>

    #230724
    danbp
    Moderator

    Sorry to answer you with a big laught, it’s not html but php. 😀
    You should also find the time to read more attentively the forum, or search by keywords.
    in this case: hide xprofile fields

    https://buddypress.org/support/search/hide+xprofile+fields/

    You’re welcome. Glad you got it. 😉

    #230718
    danbp
    Moderator

    Hi @amic58, @tecca

    When BP is installed and xProfile is activated, the original WP profile settings are not accessible to user.

    The WP register process use only username, password and email and BuddyPress add by default a Name field as base for other extended profile fields.

    In short this means that username and name fields can contain a same information(a name, a pseudonym, a first or/and a last name). The plugin you mention is best for a WP install where user had choosen first/last name as output on post, comments, etc Once BP is activated, this became a little different.

    Now to the initial question.
    The CSS trick is a very inelegant solution as it lets everybody knowing how BP works to surround this invisibility. You’re also loosing any flexibility if you want to show some fields privately for example.

    You can do this properly with a little snippet, as explained here:

    Using bp_parse_args() to filter BuddyPress template loops

    Here’s an example which let you hide fields or fiels group to members, but not to site admin

    function bpfr_hide_profile_field_group( $retval ) {
    	if ( bp_is_active( 'xprofile' ) ) :	
    	
    	// hide profile group/field to all except admin	
    	if ( !is_super_admin() ) {		
    		//exlude fields, separated by comma
    		$retval['exclude_fields'] = '1';  
    		//exlude groups, separated by comma
    		$retval['exclude_groups'] = '1'; 			
    	} 
    	return $retval;		
    	
    	endif;
    }
    add_filter( 'bp_after_has_profile_parse_args', 'bpfr_hide_profile_field_group' );

    Add it to bp-custom.php or your child-theme functions.php

    Of course you can also choose to show a field or group, but remove the possibility for the user to edit it later. Simply add more conditionnal to the function.

    Here another example:

    function bpfr_hide_profile_edit( $retval ) {	
    	// remove field from edit tab
    	if(  bp_is_user_profile_edit() ) {		
    		$retval['exclude_fields'] = '54'; // ID's separated by comma
    	}	
    	// allow field on register page
    	if ( bp_is_register_page() ) {
    		$retval['include_fields'] = '54'; // ID's separated by comma
    		}		
    	
    	// hide the field on profile view tab
    	if ( $data = bp_get_profile_field_data( 'field=54' ) ) : 
    		$retval['exclude_fields'] = '54'; // ID's separated by comma	
    	endif;	
    	
    	return $retval;	
    }
    add_filter( 'bp_after_has_profile_parse_args', 'bpfr_hide_profile_edit' );

    Hope to be clear.

    #227729

    In reply to: Separate Business User

    Henry Wright
    Moderator

    Hi @navinachettri

    1. Have you searched the plugin directory?
    2. This can be done via hooks. It will need some custom code (not much, just a few lines).
    3. You could hide or show xProfile fields according to role. How exactly roles are created and managed will be dependent on point 1
    4. Again, to distinguish business users from ‘normal’ users, you’d use the roles created via the plugin you’re using from point 1. The jobs and adverts could each have their own custom post type
    5. This will need to be custom coded

    Hope that helps?

    1a-spielwiese
    Participant

    The problems are still unresolved:

    ++ Cfr. regarding problem A. (Making xProfile fields required only for members with a certain user role):

    https://wordpress.org/support/topic/making-bp-xprofile-fields-required-for-certain-user (posted today)

    ++ Hide theses xProfile fields for members with other user roles:

    https://wordpress.org/support/topic/bb-xprofiles-acl-does-not-work (posted one week ago)

    ++ Cfr. regarding problem D. (Making answers unchangeable):

    https://buddypress.org/support/topic/how-to-make-some-xprofile-field-to-uneditable/#post-206808 (posted two days ago).

    #206284
    1a-spielwiese
    Participant

    For me also not:

    I tried it with

    Mitglieder-Kategorie (Team oder Fan?)

    instead of

    'name of your field'

    as well as with

    'Mitglieder-Kategorie (Team oder Fan?)'

    But my users can still change the values for this field. –

    I tried as well – already before and now again – this code of @noizeburger:

    //hide the user role select field in edit-screen to prevent changes after registration
    add_filter("xprofile_group_fields","bpdev_filter_profile_fields_by_usertype",10,2);
    function bpdev_filter_profile_fields_by_usertype($fields,$group_id){
    //only disable these fields on edit page
    if(!bp_is_profile_edit())
    return $fields;
    //please change it with the name of fields you don't want to allow editing
    $field_to_remove=array("User Role");
    $count=count($fields);
    $flds=array();
    for($i=0;$i<$count;$i++){
    if(in_array($fields[$i]->name,$field_to_remove))
    unset($fields[$i]);
    else
    $flds[]=$fields[$i];//doh, I did not remember a way to reset the index, so creating a new array
    }
    return $flds;
    }

    It works neither with

    "Mitglieder-Kategorie (Team oder Fan?)"

    nor with

    Mitglieder-Kategorie (Team oder Fan?)

    nor with:

    'Mitglieder-Kategorie (Team oder Fan?)'

    #201151
    1a-spielwiese
    Participant

    Follow-up:

    7th:

    Capability Manager Enhanced to define custom user roles, if you’re not satisfied with the default wordpress roles (subscriber, contributor,…).
    The first step is to create your user roles

    https://buddypress.org/support/topic/resolved-different-profile-types-and-different-user-roles/

    As ready implied there: I did this – and it works so far.

    8th:

    Create a xprofile field (selectbox) with the title “User Role” and name the options “Band Role” and “Fan Role” – in my case. You can call them whatever you want. Place this field in the “base” profile group, otherwise it won’t be shown during registration. Also make the field “required”. In my case the user can’t decide, if the visibility of the field can be changed.

    I did it already, when I installed and activated ‘BP Profile Search’-plugin – and it works.

    However, to choosed a dropdown menu and the categories ‘team’ and ‘fan’.

    9th:

    I modified:

    ?php
    function custom_bp_core_signup_user($user_id) {
        $user_role = strtolower(xprofile_get_field_data('User Role', $user_id));
        switch($user_role) {
            case "Band Role":
                $new_role = 'band';
                break;
            case "Fan Role":
                $new_role = 'fan';
                break;
        }
        wp_update_user(array(
            'ID' => $user_id,
            'role' => $new_role
        ));
    }
    add_action( 'bp_core_signup_user', 'custom_bp_core_signup_user', 10, 1);

    into:

    function custom_bp_core_signup_user($user_id) {
        $user_role = strtolower(xprofile_get_field_data('Mitglieder-Kategorie (Team oder Fan?)', $user_id));
        switch($user_role) {
            case "Team":
                $new_role = team';
                break;
            case "Fan":
                $new_role = 'fan';
                break;
        }
        wp_update_user(array(
            'ID' => $user_id,
            'role' => $new_role
        ));
    }
    add_action( 'bp_core_signup_user', 'custom_bp_core_signup_user', 10, 1);

    (I omitted <?php, because I created not a new bp-costum.php, rather inserted the code into my yet existing bp-costum.php. I inserted the modified code above the line ?>.)

    I did not understand, which effect this insertion should have – but, however, – as far as I see – it causes no harm.

    Did anyone understood, for which purpose the above mentioned code is?

    10th:

    I inserted as well:

    //hide the user role select field in edit-screen to prevent changes after registration
    add_filter("xprofile_group_fields","bpdev_filter_profile_fields_by_usertype",10,2);
    function bpdev_filter_profile_fields_by_usertype($fields,$group_id){
    
    //only disable these fields on edit page
    if(!bp_is_profile_edit())
    return $fields;
    //please change it with the name of fields you don't want to allow editing
    $field_to_remove=array("User Role");
    $count=count($fields);
    $flds=array();
    for($i=0;$i<$count;$i++){
    if(in_array($fields[$i]->name,$field_to_remove))
    unset($fields[$i]);
    else
    $flds[]=$fields[$i];//doh, I did not remember a way to reset the index, so creating a new array
    }
    return $flds;
    }

    into my bp-costum.php – again above the line ?>.

    It does not work:

    — threre the user role is still changeable:

    http://kampfsportlerinnenneuwied.1a-spielwiese.de/wp-content/uploads/sites/2/2014/09/user_role_still_changeble.jpg

    http://1a-spielwiese.de/members/kampfsportlerinnenneuwied/profile/edit/group/1 causes an redirection error. – The redirection error disappears, when I’m not logged in as kampfsportlerinnenneuwied, rather as superadmin.

    #193476
    danbp
    Moderator

    @jessicana,

    The field NAME in the field group BASE is required. This group is used for the registration page to work. As you already know, it’s also this group who allows you to show custom fields on the registration page.
    The NAME field in BuddyPress is intended to receive first and last name and replace the two original fields (first name, last name) coming with WordPress.

    That said, you can hide this field to users, but you can’t give them the choice to show/hide it.

    The above snippet will hide the field NAME to all visitors/members, but not to site admin and the concerned profile.

    function bpfr_make_name_members_only( $retval ) {	
    	//hold all of our info
    	global $bp;
    	
    	// is xprofile component active ?	
    	if ( bp_is_active( 'xprofile' ) )
    	
        // The user ID of the currently logged in user
        $current_user_id = (int) trim($bp->loggedin_user->id);
    	
        // The author that we are currently viewing
        $author_id  = (int) trim($bp->displayed_user->id);
    	
    	// user can see only his name && admin can see everyone 
    	if ($current_user_id !== $author_id && !current_user_can('delete_others_pages') ) {
    		$retval['exclude_fields'] = '1';	
    	}
    	return $retval;	
    }
    add_filter( 'bp_after_has_profile_parse_args', 'bpfr_make_name_members_only' );

    Add this to your child-theme functions.php or to bp-custom.php

    ChiefAlchemist
    Participant

    => re: “Note that you need to add the correct id(s) for exclude_fields.”

    Thanks shanebp. But is this the only way? I mean, I can’t do mucking with the code every time the client wants something new? Can I?

    => re: …/buddypress-xprofile-custom-fields-type/

    “Add new visibility setting “Nobody”. Hide the field to all members.”

    So this means, I presume that custom visibility is possible. Yes?

    That said, I want to use standard fields, but I want to create the list via code, and not have to do it manually. Not possible? Mind you, it could be cause I’m new to BP but I’m trying to where / how the profile definitions are stored. I presume it’s an array, or close. So I want to do that but with code.

    Thanks again

    shanebp
    Moderator

    I wouldn’t rely on messing with visibility settings.
    To make a profile field only editable by admins, do this in bp-custom.php or a plugin:

    // only admins can edit the Skills field
    function chief_hide_profile_fields( $retval ) {
    	
    	if( is_super_admin () )
    		return $retval;
    
    	if(  bp_is_profile_edit() || bp_is_register_page() )
    		$retval['exclude_fields'] = '3';	//profile field ID's separated by comma
    
    	return $retval;
    
    }
    add_filter( 'bp_after_has_profile_parse_args', 'chief_hide_profile_fields' );

    Note that you need to add the correct id(s) for exclude_fields.
    And that ‘ || bp_is_register_page() ‘ keeps the field(s) off the register page – which you may not need to do.

    Re how to create profile fields in code, there a couple of ways to do it depending on the kind of field and how it will be used.
    Take a look at these plugins for more info:
    https://wordpress.org/plugins/buddypress-xprofile-custom-fields-type/
    https://wordpress.org/plugins/buddypress-xprofile-image-field/

    #188504
    danbp
    Moderator

    Another snippet, more accurate with the suggested way above. Snippet goes into bp-custom or functions.php

    The field/field group is only shown to site admins. A small bug in the current BP version(.0 -> 2.0.2) prevent of completely remove the group tab from the edit screen. Bug is fixed and this will work with BP 2.1.

    function bpfr_hide_profile_field_group( $retval ) {
    	if ( bp_is_active( 'xprofile' ) ) :	
    	
    	// hide profile group/field to all except admin	
    	if ( !is_super_admin() ) {		
    		//exlude fields, separated by comma
    		$retval['exclude_fields'] = '60';  
    		//exlude groups, separated by comma - this may work with BP 2.1
    		$retval['exclude_groups'] = '7'; 			
    	} 
    	return $retval;		
    	
    	endif;
    }
    add_filter( 'bp_after_has_profile_parse_args', 'bpfr_hide_profile_field_group' );
    #188500
    danbp
    Moderator

    @csimpson,

    oh crossposting ! haven’t seen henry’s answer.

    nobody visibility doesn’t exist. This setting is called “only me“. This means that only the member can see this field – and the site admins. Such fields are not for site admins, but for the members !

    I don’t really understand what is not working for you, as what you’re looking for doesn’t exist in BuddyPress. Sorry if i’m misunderstanding you.

    When you create such a field visibility, you should also set “Enforce the default visibility for all members“, so the member cannot modify it later on his profile settings.

    Little weird side effect, when a “only me” field is used and member A wrote hello, this word becames clickabke, by default. When member B write also hello, it becames also clickable. And if A or B clcik on Hello, it shows a list of all members who wrote the same word. In this case A and B !

    Not really confidential, isn’t it ? The solution is to remove the clickable link.
    Here’s a snippet which let you do that selectively.

    function my_xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) {
        // Access the field you are going to display value.
        global $field;
    	
        // In this array you write the ids of the fields you want to hide the link.
        $excluded_field_ids = array(2,9,54); // field ID separated by comma
    	
        // If the id of this $field is in the array, we return the value only and not the link.
        if (in_array($field->id, $excluded_field_ids))
    	return $field_value;
    
    	if ( 'datebox' == $field_type )
    	return $field_value;
    	
    	if ( !strpos( $field_value, ',' ) && ( count( explode( ' ', $field_value ) ) > 5 ) )
    	return $field_value;
    	
    	$values = explode( ',', $field_value );
    
    	if ( !empty( $values ) ) {
    		foreach ( (array) $values as $value ) {
    			$value = trim( $value );
    			
    			// If the value is a URL, skip it and just make it clickable.
    			if ( preg_match( '@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', $value ) ) {
    				$new_values[] = make_clickable( $value );
    				
    				// Is not clickable
    			} else {
    				
    				// More than 5 spaces
    				if ( count( explode( ' ', $value ) ) > 5 ) {
    					$new_values[] = $value;
    					
    					// Less than 5 spaces
    				} else {
    					$search_url   = add_query_arg( array( 's' => urlencode( $value ) ), bp_get_members_directory_permalink() );
    					$new_values[] = '<a href="' . $search_url . '" rel="nofollow">' . $value . '</a>';
    				}
    			}
    		}
    		
    		$values = implode( ', ', $new_values );
    	}
    	
    	return $values;
    }
    
    /**
     * We remove the buddypress filter and add our custom filter.
     */
    function remove_xprofile_links() {
        // Remove the old filter.
        remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
        // Add your custom filter.
        add_filter( 'bp_get_the_profile_field_value', 'my_xprofile_filter_link_profile_data', 9, 2);
    }
    add_action('bp_setup_globals', 'remove_xprofile_links');
    #187184
    poundsixzeros
    Participant

    Hi,
    Is there a way users that have hidden fields can be excluded from member search results?
    It seems that if a user hides a field, their profile still shows in the search results when someone searches for whatever was hidden.

    For example, if a user #1 sets the visibility of an xprofile field “State” to “only me”. Then user #2 searches for the state that User #1 hid, then User #1’s profile should not show up on the search results. But it does. This kind of defeats the purpose of hiding a field so I’m hoping there is a way to exclude those results from searches. Any advice or insight is much appreciated!

    I am using WP 3.9.2 and BP 2.0.2.
    Thanks in advance!

    mrapino
    Participant

    Okay, this is my first piece: http://pastebin.com/pyz8XaaP

    This first link is some code findings that might continue the conversation toward an elegant solution.

    And then I came up with another possible solution here, which is actually partially working, but might be a bit clunky: http://pastebin.com/3JBCuZrx

    Basically, the first link is not working, but may give us more food for thought. The second link is working, but there are a few caveats. What I am doing in the second link is finding out what user role the logged in user is attached to. Then I create a conditional that states that if the user is under a certain role, it hides the profile group tabs from being seen, which essentially prevent them from adding content to them, and if there is no content for any of the fields in the group, it won’t show on the front end.

    CAVEAT: if you go directly to the profile group URL, you can still edit. I need to figure out how to actually prevent the URL from working, as opposed to/ or in addition to hiding it.

    Either way, I think there’s a bunch of good stuff to talk about here.

    Let me know what you think.

    NOTE: I am using some code found on this post:
    https://buddypress.org/support/topic/conditional-exclusion-of-a-xprofile-fields-group-from-editing/

    #187041
    danbp
    Moderator

    Would it matter that I have my group_order (i.e., the order in which my field groups are displayed) arranged in a specific order?

    No !
    Anyway, i was wrong myself. Apologize. My snippet hides groups from viewing, not from editing. But you can get another trick on this post. And this one works realy. 😉

    #186516
    danbp
    Moderator

    Hi @simpleone,

    you can actually only hide xprofile fields. Hiding field groups is not possible, due to a bug.
    But it is corrected for 2.1 and you’ll find a patch on the trac.

    You can already apply the patch to 2.0.2 bp-xprofile-classes.php and the above snippet will work. Add it to bp-custom.php or theme’s functions.php

    To hide an xprofile group, use bp_parse_args like this:

    function bpfr_make_profile_tab_members_only( $retval ) {
    	// hide to non members
    	if( !is_user_logged_in() ) {
               // exlude groups, separated by comma
    		$retval['exclude_groups'] = '4,5';
               // exclude fields, separated by comma
           		$retval['exclude_fields'] = '1,39';			
    	} 
    	return $retval;	
    }
    add_filter( 'bp_after_has_profile_parse_args', 'bpfr_make_profile_tab_members_only' );
    #183980
    paton400
    Participant

    Hey guys,

    How can I change the link of the ‘Change Avatar’ button so that it directs users to the settings page (where they can change their profile information).

    I am now using the Xprofile fields image upload on registration for the avatars, so original avatar settings are useless.

    Also, I’d like to change wording to ‘Change Photo” rather that ‘Avatar’

    Otherwise if this is too tricky, I’ll just hide/remove the button.

    Cheers guys.

    PS is it just me or has the BP theme changed to purple?

    CommonEasy
    Participant

    Hi there,

    I use both BP 2.0.1 and the BP custom fields type plugin and i got the the links removed with:

    function remove_xprofile_links() {
        remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
    }
    add_action('bp_setup_globals', 'remove_xprofile_links');

    I was wondering if you could use this to only hide the links from certain profile fields, like only for profile field 2, 6 & 7 ?

    #183743
    CommonEasy
    Participant

    Hi there,

    I have a profile field which i hided from the edit profile page, so it will basically function as a view only field. The data for this field is getting from another table (t2) i created in MYSQL, that data in t2 is generated from data from other profile fields from wp_bp_xprofile_data. (Data from all the users is used, you can see it has some kind of calculator. So i tried to update the wp_bp_xprofile_data table with a procedure triggered after an update on the profile fields, unfortunately this doesn’t seem to work (http://buddypress.org/support/topic/start-procedure-when-profile-is-edited/). So now i am asking if it is possible to load the data from profile field 15 directly from t2, instead of first transfer the data from t2 to wp_bp_xprofile_data? the columns from t2 are user_id | value and from wp_bp_xprofile_data are afcourse id | field_id | user_id | value. Where is the best place to start? Thanks in advance 🙂
    ps. i use BP 2.0.1. and WP 3.9.1.

    #183740

    In reply to: Remove profile links

    CommonEasy
    Participant

    sorry to bump this old topic. I use both BP 2.0.1 and BP custom fields type and i got the the links removed with:

    function remove_xprofile_links() {
        remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
    }
    add_action('bp_setup_globals', 'remove_xprofile_links');

    I was wondering if you could use this to only hide the links from certain profile fields, like only for profile field 2, 6 & 7 ?

    #183705
    compixonline
    Participant

    Hi –

    I really appreciate your reply… it’s a little above my head but working on it. How would you then populate the buddypress Xprofile fields (which would be the same, say user_meta is occupation I would have a BP Xprofile field “occupation” and I’d want to copy it across.

    I’d also want to hide the ability to change that field in the BP members profile, forcing them to use the Membermouse field in order to change their occupation both in the Membermouse Table and their BP profile…

    Hope you can help! Many thanks.

Viewing 25 results - 26 through 50 (of 129 total)
Skip to toolbar