Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'hide xprofile fields'

Viewing 25 results - 51 through 75 (of 129 total)
  • Author
    Search Results
  • #183636
    Iurie Malai
    Participant

    @simpleone,

    Can you show how you solved your problem? danbp‘s code did not work for me. As you, I also wanted to hide some xprofile fields and tabs that I don’t want users to be able to edit.

    FACT
    Participant

    Hello People,

    i got 2 Problems.

    I Add for the Buddypress Profile that people can add their Homepage Links. The Problem is now that the URL´s opened in the same tab and not in a new. Its Possible to change this? Thats when somebody clicks on the URL Link that it opened in a New Tab?

    ANd 2nd:

    Its Possible do Hide the Dashboard on the left side for normal Users? They cant do nothing on my site (Just a Community with a Forum and later Groups) but i think when they click on the dashboard and edit profile they think that they can change nothing Oo

    Sry for my bad english guys, but i think u understand what i mean

    EDIT:

    Oh yeah and i Use WordPress 3.9.1, Buddypress 2.0.1, Buddypress – Who clicked at my Profile? 1.7, BuddyPress Security Check 1.2.0, Buddypress Xprofile Custom Fields Type 1.5.9.5

    Iurie Malai
    Participant

    @danbp, I know how to check for errors, but this didn’t helped me too much :). I solved with the blank page, but no more. Your solution works for hiding some xProfile tabs from viewing, but not from editing them. Am I wrong? Sorry!

    This is my tested function (as I said, it hiding only from viewing, not from editing):

    
    function flegmatiq_profiles( $retval ) {
    
       if ( is_user_logged_in() && !bp_is_profile_edit() ) {
          $myfield = xprofile_get_field_data( 'User Type' );
          if( $myfield == "Faculty" ) {
             $retval['exclude_groups'] = '2';
    	 //$retval['exclude_fields'] = '6,18,39';
          }
       }
    
       return $retval;
    
    }
    
    add_filter( 'bp_after_has_profile_parse_args', 'flegmatiq_profiles' );
    

    The next code works as I need, but I think it is not so elegant, and it not allow to use the group ID, only his order number, as ordered by admin:

    
    function hide_profile_group_tabs_from_editing( $group_names ){
    
       if ( is_user_logged_in() && bp_is_profile_edit() && xprofile_get_field_data( "User Type") != "Faculty" ) {
          for ($x=0; $x<=sizeof($group_names); $x++) {
             if ( $x != 3 ) echo $group_names[$x]; //3 is the order number (from 0) of the tab that I need to hide in the profile edit page. This is not the group ID.
          }
       } else {
          return $group_names;
       }
    
    }
    
    add_filter('xprofile_filter_profile_group_tabs', 'hide_profile_group_tabs_from_editing');
    
    danbp
    Moderator

    Since BP 2.0, you can use bp_parse_args to customise template loops and on a much easier way as never before.

    The example function below will hide profile groups with ID 1 and profile fields IDs 6, 18 & 39 on the public profile screen of each member and stay visible on the edit screen. Tested & approved 2.0.1

    If you get some php warning while using this function, be aware that there is a bug in 2.0.1 bp-xprofile-classes.php (fixed. See ticket). Simply apply the lattest patch to get rid of this error.

    function flegmatiq_profiles( $retval ) {	
       // conditionnals to set accordingly to your purpose
    	if( !is_user_logged_in()  && !bp_is_profile_edit() ) { 
    		$retval['exclude_groups'] = '2';	
    		$retval['exclude_fields'] = '6,18,39';	
    		
    	} 
    	return $retval;
    	
    }
    add_filter( 'bp_after_has_profile_parse_args', 'flegmatiq_profiles' );

    In your particular case, you have to play with the conditionnals

    The example below is to give you an idea how to handle this. Not tested !

    function flegmatiq_profiles( $retval ) {
    $myfield = xprofile_get_field_data( 'Faculty', $user_id );
    if( empty( $myfield ) )
    return; // or echo
    
       if( $myfield == "Faculty" ) 
          if( bp_is_profile_edit() ) { 
    		$retval['exclude_groups'] = '1,56';	
    		$retval['exclude_fields'] = '6,18,39';	.
          }
       if $myfield == "field_name_2";
         // do something other...
    
    return $myfield;
    
    add_filter( 'bp_after_has_profile_parse_args', 'flegmatiq_profiles' );
    Iurie Malai
    Participant

    Hi!

    I have created in the Base (Primary) extended profile group a drop-down menu/field ‘User Type’ with three options (Faculty, Student, Visitor). Also, I have created an extended profile fields group ‘Academic Profile’ (id number 2).

    What I want to do is to hide the ‘Academic Profile’ fields group from editing (not displaying on the user edit profile page) if the drop-down field ‘User Type’ from the Base group is empty or not ‘Faculty’.

    I have the next code in the bp-custom.php, but it not works. What am I doing wrong?

    /* xProfile display for faculties */
    function exclude_xProfile_group_if_user_is_not_a_faculty( $args = array() ) {
    
       //Check if the user is not a faculty
       if ( xprofile_get_field_data( 'User Type', $user_ID ) != 'Faculty' ) :
          //Comma-separated list of xProfile fields group IDs to exclude
          $args['exclude_groups'] = "2";
       endif; 
    
       return $args;
    }
    
    add_filter( 'has_profile', 'exclude_xProfile_group_if_user_is_not_a_faculty');
    

    WordPress 3.9.1
    Buddypress 2.0.1
    http://upsic.org/

    #183075
    danbp
    Moderator

    Hi @SimpleOne,

    read from line 154 in bp-xprofile-classes.php file. It contains many information for what you want to do.
    See also on Codex here and here

    You can also revert your changes back and use this kind of function (goes into theme’s functions.php or bp-custom.php):

    function simple_one_hide_some_profile_fields( $retval ) {	
    	
    	if(  bp_is_profile_edit() ) {		
    		$retval['exclude_fields'] = '48';	//field ID's separated by comma
    		
    	}	
    	
    	return $retval;
    	
    }
    add_filter( 'bp_after_has_profile_parse_args', 'simple_one_hide_some_profile_fields' );

    May this help ? 😉

    SimpleOne
    Participant

    I’m a total novice with PHP and need some help with creating some code to go inside my functions.php file. The code I need is a clone of the call to bp_the_profile_group_field_ids() that will filter out 3 xprofile field names that I don’t want users to be able to edit.

    Background: I’ve successfully modified the edit.php file to not display those 3 “required” fields (because I don’t want users to be able to edit them). However, the problem I discovered is that after modifying the edit.php file to hide those 3 fields (which I make “required” during registration), when a user clicks “Save Changes” on their Edit Profile page, it results in the message: “Please make sure you fill in all required fields in this profile field group before saving” (even though all required fields have data in them).

    Through my online research, I found that the following line of code in the edit.php file is the problem…

    <input type="hidden" name="field_ids" id="field_ids" value="<?php bp_the_profile_group_field_ids() ?>" />

    Apparently, the call to bp_the_profile_group_field_ids() which creates a list of the expected field names does not have a filter. So I would need to clone that function in my functions.php file and manually filter out my 3 desired fields from the string that gets generated.

    Anyone able to help with this… PLEASE?

    #181170
    serks
    Participant

    Hi have a very similar issue and I think it may be related to the same cause.

    I have set up a xprofile group where I have a bunch of different radio fields like so…

    About You Widget
    Show | Hide

    Display Avatar On Profile
    Show | Hide

    Subscribed Member Badge
    Show | Hide

    etc.

    I have put code all around my website to show or hide things according to a users settings and it all works as it should BUT, the only problem is that the settings don’t take effect until a user goes to edit the particular profile group and clicks the ‘Save Changes’ button.

    Even though the defaults are set as they should be initially, they do not actually work until the user saves them.

    Any help on this issue would be much appreciated.

    Thanks

    #180614
    serks
    Participant

    Hi,

    I am using the plugin Buddypress Xprofile Custom Fields Type and I am having a problem with it.

    I have set up a some radio buttons under a custom profile tab called ‘Display Options’.
    Each radio button is basically just a ‘Show’ and ‘Hide’ for a specific element around the website.

    For example, one of them is to show or hide a particular widget (which I have gotten to work using a conditional statement and Widget Logic plugin).

    Also there are a whole lot of options for css changes etc.

    If anyone wants it, I can provide details on how I achieved the above.

    Anyway, all that is fine and working. The only problem I am having is that when a new user signs up to the site, even though these ‘Show’ and ‘Hide’ settings are all correctly defaulted in their profile, they aren’t activated until the user actually goes to that ‘Display Options’ tab and clicks the save button. Only then does everything take effect.

    Any ideas as to how this can be fixed?

    Thanks in advance to anyone for any help.

    Wordpress 3.8.1
    Buddypress 1.8

    Serks

    #177164
    shallowjeff
    Participant

    Hi,
    I need help. I’ve managed to get rid of the auto linking default function within the profile section of my members page, but am unable to place anything that has java and/or button qualities. I have a place for “profile widgets” but instead of the actual widget, I get an H-ref ugly link. http://www.poetsatwork.com

    For example:
    I paste this,

    <SCRIPT charset=”utf-8″ type=”text/javascript” src=”http://ws-na.amazon-adsystem.com/widgets/q?rt=tf_cw&ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Flovecourses-20%2F8010%2F5a411cc7-5346-4d91-86c2-9808086e235e&Operation=GetScriptTemplate”> </SCRIPT> <NOSCRIPT>Amazon.com Widgets</NOSCRIPT>

    On the page it shows this,

    <a-HREF=”http://ws-na.amazon-adsystem.com/widgets/q?rt=tf_cw&ServiceVersion=20070822&MarketPlace=US&ID=V20070822%2FUS%2Flovecourses-20%2F8010%2F5a411cc7-5346-4d91-86c2-9808086e235e&Operation=NoScript=” Amazon.com Widgets

    This is the same for all link type images/widgets I place within BP. The stuff I put on the sidebars within wordpress works fine.

    Why? I’m sure it’s a filter/function, but not sure where/what to change.

    Here is my code:buddypress-xprofile-custom-fields-type/bp-xprofile-custom-fields-type.php
    THE CODE I USED TO GET RID OF AUTO LINKING IS ON THE VERY BOTTOM, THANKS http://www.poetsatwork.com

    
    /*
    Plugin Name: Buddypress Xprofile Custom Fields Type
    Plugin URI: https://github.com/donmik/buddypress-xprofile-custom-fields-type/
    Description: Buddypress installation required!! Add more custom fields type to extended profiles in buddypress: Birthdate, Email, Web, Datepicker. If you need more fields type, you are free to add them yourself or request us at miguel@donmik.com.
    Version: 1.5.8.4
    Author: donmik
    Author URI: http://donmik.com
    */
    //load text domain
    function bxcft_load_textdomain() {
    $locale = apply_filters( 'bxcft_load_load_textdomain_get_locale', get_locale() );
    // if load .mo file
    if ( !empty( $locale ) ) {
    $mofile_default = sprintf( '%slang/%s.mo', plugin_dir_path(__FILE__), $locale );
    $mofile = apply_filters( 'bxcft_load_textdomain_mofile', $mofile_default );
    
    if ( file_exists( $mofile ) )
    load_textdomain( “bxcft”, $mofile );
    }
    }
    add_action ( 'bp_init', 'bxcft_load_textdomain', 2 );
    
    function bxcft_add_new_xprofile_field_type($field_types){
    $new_field_types = array('birthdate', 'email', 'web', 'datepicker',
    'select_custom_post_type', 'multiselect_custom_post_type',
    'checkbox_acceptance', 'image', 'file', 'color', 'number');
    $field_types = array_merge($field_types, $new_field_types);
    return $field_types;
    }
    add_filter( 'xprofile_field_types', 'bxcft_add_new_xprofile_field_type' );
    
    function bxcft_admin_render_new_xprofile_field_type($field, $echo = true) {
    $html = ”;
    switch ( $field->type ) {
    case 'number':
    $html .= '<input type=”number” name=”field_'.$field->id.'” id=”'.$field->id.'” class=”input-number” />';
    break;
    
    case 'color':
    $html .= '<input type=”color” name=”field_'.$field->id.'” id=”'.$field->id.'” class=”input-color” />';
    break;
    
    case 'image':
    case 'file':
    $html .= '<input type=”file” name=”field_'.$field->id.'” id=”'.$field->id.'” class=”input-file” /> ';
    break;
    
    case 'checkbox_acceptance':
    $html .= '<input type=”checkbox” name=”field_'.$field->id.'” id=”'.$field->id.'” class=”input-checkbox” value=”” /> ';
    $html .= $field->description;
    $field->description = ”;
    break;
    
    case 'select_custom_post_type':
    $childs = $field->get_children();
    if (isset($childs) && count($childs) > 0 && is_object($childs[0])) {
    // Get the name of custom post type.
    $custom_post_type = $childs[0]->name;
    // Get the posts of custom post type.
    $loop = new WP_Query(array('posts_per_page' => -1, 'post_type' => $custom_post_type, 'orderby' => 'title', 'order' => 'ASC' ));
    }
    $select_custom_post_type = BP_XProfile_ProfileData::get_value_byid( $field->id );
    $html .= '<select name=”field_'.$field->id.'” id=”field_'.$field->id.'”>';
    if (isset($loop)) {
    foreach ($loop->posts as $post) {
    $html .= '<option value=”'.$post->ID.'”>'.$post->post_title.'</option>';
    }
    }
    $html .= '</select>';
    break;
    
    case “multiselect_custom_post_type”:
    $childs = $field->get_children();
    if (isset($childs) && count($childs) > 0 && is_object($childs[0])) {
    // Get the name of custom post type.
    $custom_post_type = $childs[0]->name;
    // Get the posts of custom post type.
    $loop = new WP_Query(array('posts_per_page' => -1, 'post_type' => $custom_post_type, 'orderby' => 'title', 'order' => 'ASC' ));
    }
    $select_custom_post_type = BP_XProfile_ProfileData::get_value_byid( $field->id );
    $html .= '<select name=”field_'.$field->id.'” id=”field_'.$field->id.'” multiple=”multiple”>';
    if (isset($loop)) {
    foreach ($loop->posts as $post) {
    $html .= '<option value=”'.$post->ID.'”>'.$post->post_title.'</option>';
    }
    }
    $html .= '</select>';
    break;
    
    case “datepicker”:
    $html .= '<input type=”date” name=”field_'.$field->id.'” id=”'.$field->id.'” class=”input” value=”” />';
    break;
    
    case “web”:
    $html .= '<input type=”url” name=”field_'.$field->id.'” id=”'.$field->id.'” class=”input” placeholder=”'.__('yourwebsite.com', 'bxcft').'” value=”” />';
    break;
    
    case “email”:
    $html .= '<input type=”email” name=”field_'.$field->id.'” id=”'.$field->id.'” class=”input” placeholder=”'.__('example@mail.com', 'bxcft').'” value=”” />';
    break;
    
    case “birthdate”:
    $date = BP_XProfile_ProfileData::get_value_byid( $field->id );
    
    // Set day, month, year defaults
    $day = ”;
    $month = ”;
    $year = ”;
    
    if ( !empty( $date ) ) {
    
    // If Unix timestamp
    if ( is_numeric( $date ) ) {
    $day = date( 'j', $date );
    $month = date( 'F', $date );
    $year = date( 'Y', $date );
    
    // If MySQL timestamp
    } else {
    $day = mysql2date( 'j', $date );
    $month = mysql2date( 'F', $date, false ); // Not localized, so that selected() works below
    $year = mysql2date( 'Y', $date );
    }
    }
    
    // Check for updated posted values, and errors preventing
    // them from being saved first time.
    if ( !empty( $_POST['field_' . $field->id . '_day'] ) ) {
    if ( $day != $_POST['field_' . $field->id . '_day'] ) {
    $day = $_POST['field_' . $field->id . '_day'];
    }
    }
    
    if ( !empty( $_POST['field_' . $field->id . '_month'] ) ) {
    if ( $month != $_POST['field_' . $field->id . '_month'] ) {
    $month = $_POST['field_' . $field->id . '_month'];
    }
    }
    
    if ( !empty( $_POST['field_' . $field->id . '_year'] ) ) {
    if ( $year != date( “j”, $_POST['field_' . $field->id . '_year'] ) ) {
    $year = $_POST['field_' . $field->id . '_year'];
    }
    }
    
    // Day.
    $html .= '<select name=”field_'.$field->id.'_day” id=”field_'.$field->id.'_day”>';
    $html .= '<option value=””' . selected( $day, ”, false ) . '>–</option>';
    for ( $i = 1; $i < 32; ++$i ) {
    $html .= '<option value=”' . $i .'”' . selected( $day, $i, false ) . '>' . $i . '</option>';
    }
    $html .= '</select>';
    
    // Month.
    $html .= '<select name=”field_'.$field->id.'_month” id=”field_'.$field->id.'_month”>';
    $eng_months = array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' );
    $months = array(
    __( 'January', 'buddypress' ),
    __( 'February', 'buddypress' ),
    __( 'March', 'buddypress' ),
    __( 'April', 'buddypress' ),
    __( 'May', 'buddypress' ),
    __( 'June', 'buddypress' ),
    __( 'July', 'buddypress' ),
    __( 'August', 'buddypress' ),
    __( 'September', 'buddypress' ),
    __( 'October', 'buddypress' ),
    __( 'November', 'buddypress' ),
    __( 'December', 'buddypress' )
    );
    $html .= '<option value=””' . selected( $month, ”, false ) . '>——</option>';
    for ( $i = 0; $i < 12; ++$i ) {
    $html .= '<option value=”' . $eng_months[$i] . '”' . selected( $month, $eng_months[$i], false ) . '>' . $months[$i] . '</option>';
    }
    $html .= '</select>';
    
    // Year.
    $html .= '<select name=”field_'.$field->id.'_year” id=”field_'.$field->id.'_year”>';
    $html .= '<option value=””' . selected( $year, ”, false ) . '>—-</option>';
    for ( $i = date('Y')-1; $i > 1901; $i– ) {
    $html .= '<option value=”' . $i .'”' . selected( $year, $i, false ) . '>' . $i . '</option>';
    }
    $html .= '</select>';
    break;
    
    default:
    // Field type unrecognized.
    // $html = “<p>”.__('Field type unrecognized', 'bxcft').”</p>”;
    break;
    }
    
    if ($echo){
    echo $html;
    return;
    } else {
    return $html;
    }
    
    }
    add_filter( 'xprofile_admin_field', 'bxcft_admin_render_new_xprofile_field_type' );
    
    function bxcft_edit_render_new_xprofile_field($echo = true) {
    global $field;
    if (!is_bool($echo)) {
    $echo = true;
    }
    
    $uploads = wp_upload_dir();
    
    ob_start();
    if ( bp_get_the_profile_field_type() == 'birthdate' ) {
    $date = BP_XProfile_ProfileData::get_value_byid( $field->id );
    // Set day, month, year defaults
    $day = ”;
    $month = ”;
    $year = ”;
    
    if ( !empty( $date ) ) {
    
    // If Unix timestamp
    if ( is_numeric( $date ) ) {
    $day = date( 'j', $date );
    $month = date( 'F', $date );
    $year = date( 'Y', $date );
    
    // If MySQL timestamp
    } else {
    $day = mysql2date( 'j', $date );
    $month = mysql2date( 'F', $date, false ); // Not localized, so that selected() works below
    $year = mysql2date( 'Y', $date );
    }
    }
    
    // Check for updated posted values, and errors preventing
    // them from being saved first time.
    if ( !empty( $_POST['field_' . $field->id . '_day'] ) ) {
    if ( $day != $_POST['field_' . $field->id . '_day'] ) {
    $day = $_POST['field_' . $field->id . '_day'];
    }
    }
    
    if ( !empty( $_POST['field_' . $field->id . '_month'] ) ) {
    if ( $month != $_POST['field_' . $field->id . '_month'] ) {
    $month = $_POST['field_' . $field->id . '_month'];
    }
    }
    
    if ( !empty( $_POST['field_' . $field->id . '_year'] ) ) {
    if ( $year != date( “j”, $_POST['field_' . $field->id . '_year'] ) ) {
    $year = $_POST['field_' . $field->id . '_year'];
    }
    }
    ?>
    <div class=”datebox”>
    <?php
    $label = sprintf('<label class=”label-form%s” for=”%s_day”>%s%s</label>',
    bp_get_the_profile_field_is_required()?' required':”,
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_name(),
    bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):”);
    
    // Dropdown => Day of month.
    $options_day = ”;
    for ($i=1; $i<32; ++$i) {
    $options_day .= sprintf('<option value=”%s”%s>%s</option>',
    $i,
    selected($day, $i, false),
    $i);
    }
    $input = sprintf('<select name=”%s_day” id=”%s_day”%s><option value=””%s>–</option>%s</select>',
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_is_required()?'aria-required=”true”':”,
    selected($day, ”, false),
    $options_day);
    
    // Dropdown => Month.
    $eng_months = array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' );
    $months = array(
    __( 'January', 'buddypress' ),
    __( 'February', 'buddypress' ),
    __( 'March', 'buddypress' ),
    __( 'April', 'buddypress' ),
    __( 'May', 'buddypress' ),
    __( 'June', 'buddypress' ),
    __( 'July', 'buddypress' ),
    __( 'August', 'buddypress' ),
    __( 'September', 'buddypress' ),
    __( 'October', 'buddypress' ),
    __( 'November', 'buddypress' ),
    __( 'December', 'buddypress' )
    );
    $options_month = ”;
    for ($i=0; $i<12; ++$i) {
    $options_month .= sprintf('<option value=”%s”%s>%s</option>',
    $eng_months[$i],
    selected( $month, $eng_months[$i], false ),
    $months[$i]);
    }
    $input .= sprintf('<select name=”%s_month” id=”%s_month”%s><option value=””%s>——</option>%s</select>',
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_is_required()?'aria-required=”true”':”,
    selected($month, ”, false),
    $options_month);
    
    // Dropdown => Year.
    $birthdate_start_year = date('Y')-1;
    $options_year = ”;
    for ($i=$birthdate_start_year; $i>1901; $i–) {
    $options_year .= sprintf('<option value=”%s”%s>%s</option>',
    $i,
    selected($year, $i, false),
    $i);
    }
    $input .= sprintf('<select name=”%s_year” id=”%s_year”%s><option value=””%s>—-</option>%s</select>',
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_is_required()?'aria-required=”true” required=”required”':”,
    selected($year, ”, false),
    $options_year);
    
    echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required());
    
    do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' );
    
    echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required());
    ?>
    </div>
    <?php
    }
    elseif ( bp_get_the_profile_field_type() == 'email' ) {
    ?>
    <div class=”input-email”>
    <?php
    $label = sprintf('<label class=”label-form%s” for=”%s”>%s%s</label>',
    bp_get_the_profile_field_is_required()?' required':”,
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_name(),
    bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):”);
    
    $input = sprintf('<input type=”email” name=”%s” id=”%s”%s class=”input” value=”%s” placeholder=”%s” />',
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_is_required()?' aria-required=”true” required=”required”':”,
    bp_get_the_profile_field_edit_value(),
    __('example@mail.com', 'bxcft'));
    
    echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required());
    
    do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' );
    
    echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required());
    ?>
    </div>
    <?php
    }
    elseif ( bp_get_the_profile_field_type() == 'web' ) {
    ?>
    <div class=”input-web”>
    <?php
    $label = sprintf('<label class=”label-form%s” for=”%s”>%s%s</label>',
    bp_get_the_profile_field_is_required()?' required':”,
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_name(),
    bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):”);
    
    $input = sprintf('<input type=”url” name=”%s” id=”%s”%s class=”input” value=”%s” placeholder=”%s” />',
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_is_required()?' aria-required=”true” required=”required”':”,
    bp_get_the_profile_field_edit_value(),
    __('http://yourwebsite.com', 'bxcft'));
    
    echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required());
    
    do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' );
    
    echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required());
    ?>
    </div>
    <?php
    }
    elseif ( bp_get_the_profile_field_type() == 'datepicker' ) {
    ?>
    <div class=”input-datepicker”>
    <?php
    $label = sprintf('<label class=”label-form%s” for=”%s”>%s%s</label>',
    bp_get_the_profile_field_is_required()?' required':”,
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_name(),
    bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):”);
    
    $input = sprintf('<input type=”date” name=”%s” id=”%s”%s class=”input” value=”%s” />',
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_is_required()?' aria-required=”true” required=”required”':”,
    bp_get_the_profile_field_edit_value());
    
    echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required());
    
    do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' );
    
    echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required());
    ?>
    </div>
    <?php
    }
    elseif ( bp_get_the_profile_field_type() == 'select_custom_post_type' ) {
    ?>
    <div class=”input-custom-post-type”>
    <?php
    $custom_post_type_selected = BP_XProfile_ProfileData::get_value_byid( $field->id );
    if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id] != ” ) {
    if ( !empty( $_POST['field_' . $field->id] ) ) {
    $custom_post_type_selected = $_POST['field_' . $field->id];
    }
    }
    if (is_null($custom_post_type_selected)) {
    $custom_post_type_selected = array();
    }
    // Get field's data.
    $field_data = new BP_XProfile_Field($field->id);
    // Get the childs of field
    $childs = $field_data->get_children();
    if (isset($childs) && count($childs) > 0 && is_object($childs[0])) {
    // Get the name of custom post type.
    $custom_post_type = $childs[0]->name;
    // Get the posts of custom post type.
    $loop = new WP_Query(array('posts_per_page' => -1, 'post_type' => $custom_post_type, 'orderby' => 'title', 'order' => 'ASC' ));
    
    $label = sprintf('<label class=”label-form%s” for=”%s”>%s%s</label>',
    bp_get_the_profile_field_is_required()?' required':”,
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_name(),
    bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):”);
    
    $options_posts = ”;
    foreach ($loop->posts as $post) {
    $options_posts .= sprintf('<option value=”%s”%s>%s</option>',
    $post->ID,
    ($custom_post_type_selected==$post->ID)?' selected=”selected”':”,
    $post->post_title);
    }
    $input = sprintf('<select name=”%s” id=”%s”%s class=”select”><option value=””>%s</option>%s</select>',
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_is_required()?' aria-required=”true” required=”required”':”,
    __('Select…', 'bxcft'),
    $options_posts);
    
    echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required());
    
    do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' );
    
    echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required());
    } else {
    _e('There is no custom post type selected.', 'bxcft');
    }
    ?>
    </div>
    <?php
    }
    elseif ( bp_get_the_profile_field_type() == 'multiselect_custom_post_type' ) {
    ?>
    <div class=”input-custom-post-type-multi”>
    <?php
    $custom_post_type_selected = maybe_unserialize(BP_XProfile_ProfileData::get_value_byid( $field->id ));
    if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id] != ” ) {
    if ( !empty( $_POST['field_' . $field->id] ) ) {
    $custom_post_type_selected = $_POST['field_' . $field->id];
    }
    }
    // Get field's data.
    $field_data = new BP_XProfile_Field($field->id);
    // Get the childs of field
    $childs = $field_data->get_children();
    if (isset($childs) && $childs && count($childs) > 0 && is_object($childs[0])) {
    // Get the name of custom post type.
    $custom_post_type = $childs[0]->name;
    // Get the posts of custom post type.
    $loop = new WP_Query(array('posts_per_page' => -1, 'post_type' => $custom_post_type, 'orderby' => 'title', 'order' => 'ASC' ));
    
    $label = sprintf('<label class=”label-form%s” for=”%s”>%s%s</label>',
    bp_get_the_profile_field_is_required()?' required':”,
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_name(),
    bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):”);
    
    $options_posts = ”;
    foreach ($loop->posts as $post) {
    $options_posts .= sprintf('<option value=”%s”%s>%s</option>',
    $post->ID,
    (!empty($custom_post_type_selected) &&in_array($post->ID, $custom_post_type_selected))?' selected=”selected”':”,
    $post->post_title);
    }
    $input = sprintf('<select name=”%s[]” id=”%s”%s class=”select” multiple=”multiple”><option value=””>%s</option>%s</select>',
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_is_required()?' aria-required=”true” required=”required”':”,
    __('Select…', 'bxcft'),
    $options_posts);
    
    echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required());
    
    do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' );
    
    echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required());
    } else {
    _e('There is no custom post type selected.', 'bxcft');
    }
    ?>
    </div>
    <?php
    }
    elseif (bp_get_the_profile_field_type() == 'checkbox_acceptance') {
    ?>
    <div class=”checkbox-acceptance”>
    <?php
    $label = sprintf('<label class=”label-form%s” for=”%s”>%s%s</label>',
    bp_get_the_profile_field_is_required()?' required':”,
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_name(),
    bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):”);
    
    $input = sprintf('<input type=”checkbox” name=”%s” id=”%s”%s class=”checkbox” value=”1″%s />%s',
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_is_required()?' aria-required=”true” required=”required”':”,
    bp_get_the_profile_field_edit_value()?' checked=”checked”':”,
    bp_get_the_profile_field_description());
    
    echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required());
    
    do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' );
    
    echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required());
    $field_description = ”;
    ?>
    </div>
    <?php
    }
    elseif (bp_get_the_profile_field_type() == 'image') {
    ?>
    <div class=”input-image”>
    <?php
    $label = sprintf('<label class=”label-form%s” for=”%s”>%s%s</label>',
    bp_get_the_profile_field_is_required()?' required':”,
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_name(),
    bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):”);
    
    if (bp_get_the_profile_field_edit_value() != ”) {
    $actual_image = sprintf('%s<label for=”%s_deleteimg”><input type=”checkbox” name=”%s_deleteimg” id=”%s_deleteimg” value=”1″ />%s</label><input type=”hidden” name=”%s_hiddenimg” id=”%s_hiddenimg” value=”%s” />',
    $uploads['baseurl'].bp_get_the_profile_field_edit_value(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    __('Check this to delete this image', 'bxcft'),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_edit_value());
    } else {
    $actual_image = ”;
    }
    $input = sprintf('<input type=”file” name=”%s” id=”%s”%s />',
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_is_required()?' aria-required=”true” required=”required”':”);
    
    echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required());
    
    do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' );
    
    echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required());
    
    echo apply_filters('bxcft_field_actual_image', $actual_image, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_edit_value());
    ?>
    <script type=”text/javascript”>
    jQuery('#profile-edit-form').attr('enctype', 'multipart/form-data');
    </script>
    </div>
    <?php
    }
    elseif (bp_get_the_profile_field_type() == 'file') {
    ?>
    <div class=”input-file”>
    <?php
    $label = sprintf('<label class=”label-form%s” for=”%s”>%s%s</label>',
    bp_get_the_profile_field_is_required()?' required':”,
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_name(),
    bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):”);
    
    if (bp_get_the_profile_field_edit_value() != ”) {
    $actual_file = sprintf('%s<label for=”%s_deletefile”><input type=”checkbox” name=”%s_deletefile” id=”%s_deletefile” value=”1″ />%s</label><input type=”hidden” name=”%s_hiddenfile” id=”%s_hiddenfile” value=”%s” />',
    apply_filters('bxcft_show_download_file_link', '' . __('Download file', 'bxcft') . '', bp_get_the_profile_field_type(), bp_get_the_profile_field_id(), bp_get_the_profile_field_edit_value()),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    __('Check this to delete this file', 'bxcft'),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_edit_value());
    } else {
    $actual_file = ”;
    }
    $input = sprintf('<input type=”file” name=”%s” id=”%s”%s />',
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_is_required()?' aria-required=”true” required=”required”':”);
    
    echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required());
    
    do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' );
    
    echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required());
    
    echo apply_filters('bxcft_field_actual_file', $actual_file, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_edit_value());
    ?>
    <script type=”text/javascript”>
    jQuery('#profile-edit-form').attr('enctype', 'multipart/form-data');
    </script>
    </div>
    <?php
    }
    elseif (bp_get_the_profile_field_type() == 'color') {
    $color_selected = bp_get_the_profile_field_edit_value();
    if (strpos($color_selected, '#') === false) {
    $color_selected = '#'.$color_selected;
    }
    ?>
    <div class=”input-color”>
    <?php
    $label = sprintf('<label class=”label-form%s” for=”%s”>%s%s</label>',
    bp_get_the_profile_field_is_required()?' required':”,
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_name(),
    bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):”);
    
    $input = sprintf('<input type=”color” name=”%s” id=”%s”%s class=”input” value=”%s” />',
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_is_required()?' aria-required=”true” required=”required”':”,
    $color_selected);
    
    echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required());
    
    do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' );
    
    echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required());
    ?>
    </div>
    <script>
    if (!Modernizr.inputtypes.color) {
    // No html5 field colorpicker => Calling jscolor.
    jQuery('input#<?php bp_the_profile_field_input_name() ?>').addClass('color');
    }
    </script>
    <?php
    }
    elseif (bp_get_the_profile_field_type() == 'number') {
    ?>
    <div class=”input-number”>
    <?php
    $label = sprintf('<label class=”label-form%s” for=”%s”>%s%s</label>',
    bp_get_the_profile_field_is_required()?' required':”,
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_name(),
    bp_get_the_profile_field_is_required()?' '.__('(required)', 'buddypress'):”);
    
    $input = sprintf('<input type=”number” name=”%s” id=”%s”%s class=”input” value=”%s” />',
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_input_name(),
    bp_get_the_profile_field_is_required()?' aria-required=”true” required=”required”':”,
    bp_get_the_profile_field_edit_value());
    
    echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required());
    
    do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' );
    
    echo apply_filters('bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required());
    ?>
    </div>
    <?php
    }
    
    $output = ob_get_contents();
    ob_end_clean();
    
    if ($echo) {
    echo $output;
    return;
    }
    return $output;
    }
    
    /*
    * Buddypress v1.7 has better hook bp_custom_profile_edit_fields_pre_visibility which shows fields before visibility settings.
    * In case buddypress previous version is installed, we use the other tag bp_custom_profile_edit_fields.
    */
    $version_bp = 0;
    $data = get_file_data(WP_PLUGIN_DIR . '/buddypress/bp-loader.php', array('Version'));
    if (isset($data) && count($data) > 0 && $data[0] != ”)
    $version_bp = (float)$data[0];
    if ($version_bp >= 1.7)
    add_action( 'bp_custom_profile_edit_fields_pre_visibility', 'bxcft_edit_render_new_xprofile_field' );
    else
    add_action( 'bp_custom_profile_edit_fields', 'bxcft_edit_render_new_xprofile_field' );
    
    function bxcft_get_field_value( $value=”, $type=”, $id=”) {
    
    $value_to_return = $value;
    
    if ($value_to_return == ”)
    return apply_filters('bxcft_show_field_value', $value_to_return, $type, $id, $value);
    
    $uploads = wp_upload_dir();
    
    if ($type == 'birthdate') {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    $field = new BP_XProfile_Field($id);
    // Get children.
    $childs = $field->get_children();
    $show_age = false;
    if (isset($childs) && $childs && count($childs) > 0 && is_object($childs[0])) {
    // Get the name of custom post type.
    if ($childs[0]->name == 'show_age')
    $show_age = true;
    }
    if ($value != ”) {
    if ($show_age) {
    $value_to_return = '<p>'.floor((time() – strtotime($value))/31556926).'</p>';
    } else {
    $value_to_return = '<p>'.date_i18n(get_option('date_format') ,strtotime($value) ).'</p>';
    }
    }
    }
    elseif ($type == 'datepicker') {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    $value_to_return = '<p>'.date_i18n(get_option('date_format') ,strtotime($value) ).'</p>';
    }
    elseif ($type == 'email') {
    if (strpos($value, 'mailto') === false) {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    $value_to_return = '<p>'.$value.'</p>';
    }
    }
    elseif ($type == 'web') {
    if (strpos($value, 'href=') === false) {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    $value_to_return = '<p>'.$value.'</p>';
    }
    }
    elseif ($type == 'select_custom_post_type') {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    // Get field's data.
    $field = new BP_XProfile_Field($id);
    // Get children.
    $childs = $field->get_children();
    if (isset($childs) && count($childs) > 0) {
    // Get the name of custom post type.
    $custom_post_type = $childs[0]->name;
    }
    $post = get_post($value);
    if ($post->post_type == $custom_post_type) {
    $value_to_return = '<p>'.$post->post_title.'</p>';
    } else {
    // Custom post type is not the same.
    $value_to_return = '<p>–</p>';
    }
    }
    elseif ($type == 'multiselect_custom_post_type') {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    // Get field's data.
    $field = new BP_XProfile_Field($id);
    // Get children.
    $childs = $field->get_children();
    if (isset($childs) && count($childs) > 0 && is_object($childs[0])) {
    // Get the name of custom post type.
    $custom_post_type = $childs[0]->name;
    } else {
    $custom_post_type = ”;
    }
    $values = explode(“,”, $value);
    $cad = ”;
    foreach ($values as $v) {
    $post = get_post($v);
    if ($post->post_type == $custom_post_type) {
    if ($cad == ”)
    $cad .= '<ul class=”list_custom_post_type”>';
    $cad .= '
    '.$post->post_title.'
    
    ';
    }
    }
    if ($cad != ”) {
    $cad .= '';
    $value_to_return = '<p>'.$cad.'</p>';
    } else {
    $value_to_return = '<p>–</p>';
    }
    } elseif ($type == 'checkbox_acceptance') {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    $value_to_return = '<p>'.(($value==1)?__('yes', 'bxcft'):__('no', 'bxcft')).'</p>';
    } elseif ($type == 'image') {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    $value_to_return = '<p></p>';
    } elseif ($type == 'file') {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    $value_to_return = '<p>'.__('Download file', 'bxcft').'</p>';
    } elseif ($type == 'color') {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    if (strpos($value, '#') === false) {
    $value = '#'.$value;
    }
    $value_to_return = '<p>'.$value.'</p>';
    }
    // Number nothing to do.
    
    return apply_filters('bxcft_show_field_value', $value_to_return, $type, $id, $value);
    }
    add_filter( 'bp_get_the_profile_field_value', 'bxcft_get_field_value', 15, 3);
    
    /**
    * Filter for those who use xprofile_get_field_data instead of get_field_value.
    * @param type $value
    * @param type $field_id
    * @param type $user_id
    * @return string
    */
    function bxcft_get_field_data($value, $field_id) {
    
    $value_to_return = $value;
    $field = new BP_XProfile_Field($field_id);
    
    if ($value_to_return == ”)
    return apply_filters('bxcft_show_field_value', $value_to_return, $field->type, $field_id, $value);
    
    $uploads = wp_upload_dir();
    if ($field->type == 'birthdate') {
    // Get children.
    $childs = $field->get_children();
    $show_age = false;
    if (isset($childs) && $childs && count($childs) > 0 && is_object($childs[0])) {
    if ($childs[0]->name == 'show_age')
    $show_age = true;
    }
    if ($value != ”) {
    if ($show_age) {
    $value_to_return = '<p>'.floor((time() – strtotime($value))/31556926).'</p>';
    } else {
    $value_to_return = '<p>'.date_i18n(get_option('date_format') ,strtotime($value) ).'</p>';
    }
    }
    }
    elseif ($field->type == 'datepicker') {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    $value_to_return = '<p>'.date_i18n(get_option('date_format') ,strtotime($value) ).'</p>';
    }
    elseif ($field->type == 'email') {
    if (strpos($value, 'mailto') === false) {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    $value_to_return = '<p>'.$value.'</p>';
    }
    }
    elseif ($field->type == 'web') {
    if (strpos($value, 'href=') === false) {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    $value_to_return = '<p>'.$value.'</p>';
    }
    }
    elseif ($field->type == 'select_custom_post_type') {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    // Get children.
    $childs = $field->get_children();
    if (isset($childs) && count($childs) > 0) {
    // Get the name of custom post type.
    $custom_post_type = $childs[0]->name;
    }
    $post = get_post($value);
    if ($post->post_type == $custom_post_type) {
    $value_to_return = '<p>'.$post->post_title.'</p>';
    } else {
    // Custom post type is not the same.
    $value_to_return = '<p>–</p>';
    }
    }
    elseif ($field->type == 'multiselect_custom_post_type') {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    // Get children.
    $childs = $field->get_children();
    $values = explode(“,”, $value);
    $cad = ”;
    if (isset($childs) && is_array($childs) && count($childs) > 0) {
    // Get the name of custom post type.
    $custom_post_type = $childs[0]->name;
    
    foreach ($values as $v) {
    $post = get_post($v);
    if ($post->post_type == $custom_post_type) {
    if ($cad == ”)
    $cad .= '<ul class=”list_custom_post_type”>';
    $cad .= '
    '.$post->post_title.'
    
    ';
    }
    }
    }
    if ($cad != ”) {
    $cad .= '';
    $value_to_return = '<p>'.$cad.'</p>';
    } else {
    $value_to_return = '<p>–</p>';
    }
    } elseif ($field->type == 'checkbox_acceptance') {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    $value_to_return = '<p>'.(($value==1)?__('yes', 'bxcft'):__('no', 'bxcft')).'</p>';
    } elseif ($field->type == 'image') {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    $value_to_return = '<p></p>';
    } elseif ($field->type == 'file') {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    $value_to_return = '<p>'.__('Download file', 'bxcft').'</p>';
    } elseif ($field->type == 'color') {
    $value = str_replace(“<p>”, “”, $value);
    $value = str_replace(“</p>”, “”, $value);
    if (strpos($value, '#') === false) {
    $value = '#'.$value;
    }
    $value_to_return = '<p>'.$value.'</p>';
    }
    // Number nothing to do.
    
    return apply_filters('bxcft_show_field_value', $value_to_return, $field->type, $field_id, $value);
    
    }
    add_filter( 'xprofile_get_field_data', 'bxcft_get_field_data', 15, 2);
    
    /**
    * Function replacing the original buddypress filter.
    * @param type $field_value
    * @param type $field_type
    * @return string
    */
    function bxcft_xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) {
    if ( 'datebox' == $field_type || 'email' == $field_type || 'birthdate' == $field_type ||
    'datepicker' == $field_type || 'web' == $field_type || 'select_custom_post_type' == $field_type ||
    'multiselect_custom_post_type' == $field_type || 'image' == $field_type || 'file' == $field_type ||
    'color' == $field_type || 'number' == $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[] = '' . $value . '';
    }
    }
    }
    
    $values = implode( ', ', $new_values );
    }
    
    return $values;
    }
    
    /**
    * Adding js for admin.
    * @param type $hook
    * @return type
    */
    function bxcft_add_js($hook) {
    if ('users_page_bp-profile-setup' != $hook && 'buddypress_page_bp-profile-setup' != $hook)
    return;
    
    wp_enqueue_script( 'bxcft-js', plugins_url('assets/js/addfields.js', __FILE__), array( 'jquery' ), '1.5.7′ );
    $params = array(
    'birthdate' => __('Birthdate', 'bxcft'),
    'email' => __('Email', 'bxcft'),
    'web' => __('Website', 'bxcft'),
    'datepicker' => __('Datepicker', 'bxcft'),
    'select_custom_post_type' => __('Custom Post Type Selector', 'bxcft'),
    'multiselect_custom_post_type' => __('Custom Post Type Multiselector', 'bxcft'),
    'checkbox_acceptance' => __('Checkbox acceptance', 'bxcft'),
    'image' => __('Image', 'bxcft'),
    'file' => __('File', 'bxcft'),
    'color' => __('Color', 'bxcft'),
    'number' => __('Number', 'bxcft')
    );
    wp_localize_script('bxcft-js', 'params', $params);
    }
    add_action( 'admin_enqueue_scripts', 'bxcft_add_js');
    
    /**
    * Adding js for edit form.
    */
    function bxcft_add_js_public() {
    // Modernizr to test html5 fields.
    wp_enqueue_script( 'bxcft-modernizr', plugins_url('assets/js/modernizr.js', __FILE__), array( 'jquery' ), '2.6.2′ );
    // Plugin jscolor fallback colorpicker.
    wp_enqueue_script( 'bxcft-jscolor', plugins_url('assets/js/jscolor/jscolor.js', __FILE__), array( 'bxcft-modernizr' ), '1.4.1′ );
    }
    add_action( 'wp_enqueue_scripts', 'bxcft_add_js_public');
    
    function bxcft_save_custom_option($field) {
    global $bp, $wpdb;
    
    if ( 'select_custom_post_type' == $field->type ) {
    $post_option = !empty( $_POST['select_custom_post_type_option']) ? $_POST['select_custom_post_type_option'] : ”;
    if ( ” != $post_option ) {
    if ( !empty( $field->id ) ) {
    $field_id = $field->id;
    } else {
    $field_id = $wpdb->insert_id;
    }
    if ( !$wpdb->query( $wpdb->prepare( “INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'custom_post_type_option', %s, ”, 0, %d, %d)”, $field->group_id, $field_id, $post_option, 1, 1 ) ) ) {
    return false;
    }
    }
    }
    elseif ( 'multiselect_custom_post_type' == $field->type) {
    $post_option = !empty( $_POST['multiselect_custom_post_type_option']) ? $_POST['multiselect_custom_post_type_option'] : ”;
    if ( ” != $post_option ) {
    if ( !empty( $field->id ) ) {
    $field_id = $field->id;
    } else {
    $field_id = $wpdb->insert_id;
    }
    if ( !$wpdb->query( $wpdb->prepare( “INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'multi_custom_post_type_option', %s, ”, 0, %d, %d)”, $field->group_id, $field_id, $post_option, 1, 1 ) ) ) {
    return false;
    }
    }
    }
    elseif ( 'birthdate' == $field->type) {
    $post_option = !empty( $_POST['birthdate_option']) ? $_POST['birthdate_option'] : ”;
    if ( ” != $post_option ) {
    if ( !empty( $field->id ) ) {
    $field_id = $field->id;
    } else {
    $field_id = $wpdb->insert_id;
    }
    if ( !$wpdb->query( $wpdb->prepare( “INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'birthdate_option', %s, ”, 0, %d, %d)”, $field->group_id, $field_id, $post_option, 1, 1 ) ) ) {
    return false;
    }
    }
    }
    
    }
    add_action( 'xprofile_field_after_save', 'bxcft_save_custom_option');
    
    function bxcft_delete_field_custom($field) {
    if ($field->type == 'select_custom_post_type' || $field->type == 'multiselect_custom_post_type'
    || $field->type == 'birthdate') {
    $field->delete_children();
    }
    }
    add_action( 'xprofile_fields_deleted_field', 'bxcft_delete_field_custom');
    
    function bxcft_selected_field($field) {
    $childs = $field->get_children();
    if (isset($childs) && count($childs) > 0 && is_object($childs[0]) && $field->type == 'select_custom_post_type') {
    $selected_option = $childs[0]->name;
    } else {
    $selected_option = null;
    }
    
    if (!empty($_POST['select_custom_post_type_option'])) {
    $selected_option = $_POST['select_custom_post_type_option'];
    }
    ?>
    <div style=”display: none; margin-left: 15px;” class=”options-box” id=”select_custom_post_type”>
    <h4><?php _e('Please, select custom post type', 'bxcft'); ?></h4>
    <p>
    <?php _e('Custom Post Type:', 'bxcft'); ?>
    <select name=”select_custom_post_type_option” id=”select_custom_post_type_option”>
    <?php
    $args = array(
    'public' => true,
    '_builtin' => false
    );
    $custom_post_types = get_post_types($args);
    foreach ($custom_post_types as $post_type) :
    ?>
    <option value=”<?php echo $post_type; ?>” <?php if ($selected_option == $post_type): ?>selected=”selected”<?php endif; ?>>
    <?php echo $post_type; ?>
    </option>
    <?php endforeach; ?>
    </select>
    </p>
    </div>
    <?php
    if (isset($childs) && count($childs) > 0 && is_object($childs[0]) && $field->type == 'multiselect_custom_post_type') {
    $selected_option = $childs[0]->name;
    } else {
    $selected_option = null;
    }
    
    if (!empty($_POST['multiselect_custom_post_type_option'])) {
    $selected_option = $_POST['multiselect_custom_post_type_option'];
    }
    ?>
    <div style=”display: none; margin-left: 15px;” class=”options-box” id=”multiselect_custom_post_type”>
    <h4><?php _e('Please, select custom post type', 'bxcft'); ?></h4>
    <p>
    <?php _e('Custom Post Type:', 'bxcft'); ?>
    <select name=”multiselect_custom_post_type_option” id=”multiselect_custom_post_type_option”>
    <?php
    foreach ($custom_post_types as $post_type) :
    ?>
    <option value=”<?php echo $post_type; ?>” <?php if ($selected_option == $post_type): ?>selected=”selected”<?php endif; ?>>
    <?php echo $post_type; ?>
    </option>
    <?php endforeach; ?>
    </select>
    </p>
    </div>
    <?php
    if (isset($childs) && $childs && count($childs) > 0 && is_object($childs[0]) && $field->type == 'birthdate') {
    $selected_option = $childs[0]->name;
    } else {
    $selected_option = null;
    }
    
    if (!empty($_POST['birthdate_option'])) {
    $selected_option = $_POST['birthdate_option'];
    }
    ?>
    <div style=”display: none; margin-left: 15px;” class=”options-box” id=”birthdate”>
    <h4><?php _e('Show age (hide birthdate)', 'bxcft'); ?></h4>
    <p>
    <?php _e('Check this if you want to show age instead of birthdate:', 'bxcft'); ?>
    <input type=”checkbox” name=”birthdate_option” value=”show_age” id=”birthdate_option”
    <?php if ($selected_option == 'show_age') : ?>checked=”checked”<?php endif; ?>/>
    </p>
    </div>
    <?php if (!is_null($field->type)) : ?>
    <script type=”text/javascript”>
    jQuery(document).ready(function() {
    bxcft.select('<?php echo $field->type; ?>');
    });
    </script>
    <?php
    endif;
    }
    add_action('xprofile_field_additional_options', 'bxcft_selected_field');
    
    /**
    * This filter add a new level of visibility. Hide this field for everyone. Nobody can see.
    * @param type $visibility_levels
    * @return type
    */
    function bxcft_xprofile_get_visibility_levels($visibility_levels) {
    $visibility_levels['nobody'] = array('id' => 'nobody', 'label' => __('Nobody', 'bxcft'));
    return $visibility_levels;
    }
    add_filter('bp_xprofile_get_visibility_levels', 'bxcft_xprofile_get_visibility_levels', 1);
    
    /**
    * This filter is necessary to hide fields when 'nobody' new visibility is selected.
    * @param type $hidden_fields
    * @param type $displayed_user_id
    * @param type $current_user_id
    * @return type
    */
    function bxcft_xprofile_get_hidden_fields_for_user($hidden_fields, $displayed_user_id=0, $current_user_id=0) {
    if ( !$displayed_user_id ) {
    $displayed_user_id = bp_displayed_user_id();
    }
    
    if ( !$displayed_user_id ) {
    return array();
    }
    
    if ( !$current_user_id ) {
    $current_user_id = bp_loggedin_user_id();
    }
    
    // @todo – This is where you'd swap out for current_user_can() checks
    $new_hidden_fields = array();
    
    if ( $current_user_id ) {
    // Current user is logged in
    if ( $displayed_user_id == $current_user_id ) {
    // If you're viewing your own profile, nothing's private
    
    } elseif ( bp_is_active( 'friends' ) && friends_check_friendship( $displayed_user_id, $current_user_id ) ) {
    // If the current user and displayed user are friends, so exclude nobody
    $hidden_levels[] = 'nobody';
    $new_hidden_fields = bp_xprofile_get_fields_by_visibility_levels( $displayed_user_id, $hidden_levels );
    
    } else {
    // current user is logged-in but not friends, so exclude friends-only
    $hidden_levels[] = 'nobody';
    
    $new_hidden_fields = bp_xprofile_get_fields_by_visibility_levels( $displayed_user_id, $hidden_levels );
    }
    
    } else {
    // Current user is not logged in, so exclude friends-only and loggedin
    $hidden_levels[] = 'nobody';
    
    $new_hidden_fields = bp_xprofile_get_fields_by_visibility_levels( $displayed_user_id, $hidden_levels );
    }
    
    if (is_array($new_hidden_fields))
    $hidden_fields = array_merge($hidden_fields, $new_hidden_fields);
    
    return $hidden_fields;
    }
    add_filter('bp_xprofile_get_hidden_fields_for_user', 'bxcft_xprofile_get_hidden_fields_for_user', 10, 3);
    
    /**
    * Update profile
    */
    function bxcft_updated_profile($bp_user_id, $posted_field_ids, $errors) {
    
    global $bp;
    
    // There are errors
    if ( empty( $errors ) ) {
    
    // Reset the errors var
    $errors = false;
    
    // Now we've checked for required fields, lets save the values.
    foreach ( (array) $posted_field_ids as $field_id ) {
    
    // Certain types of fields (checkboxes, multiselects) may come through empty. Save them as an empty array so that they don't get overwritten by the default on the next edit.
    if ( empty( $_POST['field_' . $field_id] ) )
    $value = array();
    else
    $value = $_POST['field_' . $field_id];
    
    // Handles delete checkbox.
    $uploads = wp_upload_dir();
    $field = new BP_XProfile_Field($field_id);
    if ($field->type == 'image' && isset($_POST['field_'.$field_id.'_deleteimg']) && $_POST['field_'.$field_id.'_deleteimg']) {
    if (file_exists($uploads['basedir'] . $_POST['field_'.$field_id.'_hiddenimg'])) {
    unlink($uploads['basedir'] . $_POST['field_'.$field_id.'_hiddenimg']);
    }
    $value = array();
    }
    if ($field->type == 'file' && isset($_POST['field_'.$field_id.'_deletefile']) && $_POST['field_'.$field_id.'_deletefile']) {
    if (file_exists($uploads['basedir'] . $_POST['field_'.$field_id.'_hiddenfile'])) {
    unlink($uploads['basedir'] . $_POST['field_'.$field_id.'_hiddenfile']);
    }
    $value = array();
    }
    
    // Handles image field type saving.
    if (isset($_FILES['field_'.$field_id]) && $_FILES['field_'.$field_id]['size'] > 0) {
    $field = new BP_XProfile_Field($field_id);
    if ($field->type == 'image') {
    $ext_allowed = array('jpg','jpeg','gif','png');
    apply_filters('images_ext_allowed', $ext_allowed);
    } elseif ($field->type == 'file') {
    $ext_allowed = array('doc','docx','pdf');
    apply_filters('files_ext_allowed', $ext_allowed);
    }
    
    $ext = strtolower(substr($_FILES['field_'.$field_id]['name'], strrpos($_FILES['field_'.$field_id]['name'],'.')+1));
    if (!in_array($ext, $ext_allowed)) {
    $errors = true;
    } else {
    require_once( ABSPATH . '/wp-admin/includes/file.php' );
    add_filter( 'upload_dir', 'bxcft_profile_upload_dir', 10, 1 );
    $_POST['action'] = 'wp_handle_upload';
    $uploaded_file = wp_handle_upload( $_FILES['field_'.$field_id] );
    $uploads = wp_upload_dir();
    $value = str_replace($uploads['baseurl'], ”, $uploaded_file['url']);
    }
    } else {
    if ($field->type == 'image' && (!isset($_POST['field_'.$field_id.'_deleteimg']) || !$_POST['field_'.$field_id.'_deleteimg']) && isset($_POST['field_'.$field_id.'_hiddenimg']) && $_POST['field_'.$field_id.'_hiddenimg'] != ”) {
    $value = $_POST['field_'.$field_id.'_hiddenimg'];
    }
    elseif ($field->type == 'file' && (!isset($_POST['field_'.$field_id.'_deletefile']) || !$_POST['field_'.$field_id.'_deletefile']) && isset($_POST['field_'.$field_id.'_hiddenfile']) && $_POST['field_'.$field_id.'_hiddenfile'] != ”) {
    $value = $_POST['field_'.$field_id.'_hiddenfile'];
    }
    }
    if ( !xprofile_set_field_data( $field_id, $bp_user_id, $value ) ) {
    $errors = true;
    } else {
    do_action( 'xprofile_profile_field_data_updated', $field_id, $value );
    }
    }
    }
    }
    add_action('xprofile_updated_profile', 'bxcft_updated_profile', 10, 3);
    
    function bxcft_signup_user($user_id, $user_login, $user_password, $user_email, $usermeta)
    {
    // Set any profile data
    if ( bp_is_active( 'xprofile' ) ) {
    if ( !empty( $usermeta['profile_field_ids'] ) ) {
    $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] );
    
    foreach( (array) $profile_field_ids as $field_id ) {
    
    if (!empty($usermeta["field_{$field_id}"]))
    $value = $usermeta["field_{$field_id}"];
    else
    $value = array();
    
    // Handles delete checkbox.
    $uploads = wp_upload_dir();
    $field = new BP_XProfile_Field($field_id);
    if ($field->type == 'image' && isset($_POST['field_'.$field_id.'_deleteimg']) && $_POST['field_'.$field_id.'_deleteimg']) {
    if (file_exists($uploads['basedir'] . $_POST['field_'.$field_id.'_hiddenimg'])) {
    unlink($uploads['basedir'] . $_POST['field_'.$field_id.'_hiddenimg']);
    }
    $value = array();
    }
    if ($field->type == 'file' && isset($_POST['field_'.$field_id.'_deletefile']) && $_POST['field_'.$field_id.'_deletefile']) {
    if (file_exists($uploads['basedir'] . $_POST['field_'.$field_id.'_hiddenfile'])) {
    unlink($uploads['basedir'] . $_POST['field_'.$field_id.'_hiddenfile']);
    }
    $value = array();
    }
    
    // Handles image field type saving.
    if (isset($_FILES['field_'.$field_id]) && $_FILES['field_'.$field_id]['size'] > 0) {
    $field = new BP_XProfile_Field($field_id);
    if ($field->type == 'image') {
    $ext_allowed = array('jpg','jpeg','gif','png');
    apply_filters('images_ext_allowed', $ext_allowed);
    } elseif ($field->type == 'file') {
    $ext_allowed = array('doc','docx','pdf');
    apply_filters('files_ext_allowed', $ext_allowed);
    }
    
    $ext = strtolower(substr($_FILES['field_'.$field_id]['name'], strrpos($_FILES['field_'.$field_id]['name'],'.')+1));
    if (in_array($ext, $ext_allowed)) {
    require_once( ABSPATH . '/wp-admin/includes/file.php' );
    add_filter( 'upload_dir', 'bxcft_profile_upload_dir', 10, 1 );
    $_POST['action'] = 'wp_handle_upload';
    $uploaded_file = wp_handle_upload( $_FILES['field_'.$field_id] );
    $destino = str_replace('0′, $user_id, $uploaded_file['file']);
    $aux = explode(“/”, $destino);
    if (!file_exists(str_replace('/'.$aux[count($aux)-1], ”, $destino))) {
    mkdir(str_replace('/'.$aux[count($aux)-1], ”, $destino));
    }
    copy($uploaded_file['file'], $destino);
    unlink($uploaded_file['file']);
    $value = str_replace($uploads['baseurl'], ”, str_replace('0′, $user_id, $uploaded_file['url']));
    }
    } else {
    if ($field->type == 'image' && (!isset($_POST['field_'.$field_id.'_deleteimg']) || !$_POST['field_'.$field_id.'_deleteimg']) && isset($_POST['field_'.$field_id.'_hiddenimg']) && $_POST['field_'.$field_id.'_hiddenimg'] != ”) {
    $value = $_POST['field_'.$field_id.'_hiddenimg'];
    }
    elseif ($field->type == 'file' && (!isset($_POST['field_'.$field_id.'_deletefile']) || !$_POST['field_'.$field_id.'_deletefile']) && isset($_POST['field_'.$field_id.'_hiddenfile']) && $_POST['field_'.$field_id.'_hiddenfile'] != ”) {
    $value = $_POST['field_'.$field_id.'_hiddenfile'];
    }
    }
    
    xprofile_set_field_data( $field_id, $user_id, $value );
    }
    }
    }
    }
    add_action('bp_core_signup_user', 'bxcft_signup_user', 10, 5);
    
    function bxcft_profile_upload_dir( $upload_dir, $user_id=0 ) {
    if ($user_id == 0)
    $user_id = bp_displayed_user_id();
    $profile_subdir = '/profiles/' . $user_id;
    
    $upload_dir['path'] = $upload_dir['basedir'] . $profile_subdir;
    $upload_dir['url'] = $upload_dir['baseurl'] . $profile_subdir;
    $upload_dir['subdir'] = $profile_subdir;
    
    return $upload_dir;
    }
    
    /**
    * Replacing the buddypress filter link profile is it has the filter.
    * If user deactivated the filter, we don't add another filter.
    */
    function bxcft_remove_xprofile_links() {
    if (has_filter('bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data')) {
    remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
    add_filter( 'bp_get_the_profile_field_value', 'bxcft_xprofile_filter_link_profile_data', 9, 2);
    }
    }
    add_action( 'bp_setup_globals', 'bxcft_remove_xprofile_links', 9999 );
    
    /**
    * This function only works if plugin bp-profile search is active.
    * @global type $bps_options
    * @param type $type
    * @return string
    */
    function bxcft_profile_field_type($type) {
    if (function_exists('is_plugin_active') && is_plugin_active('bp-profile-search/bps-main.php')
    || in_array( 'bp-profile-search/bps-main.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )) {
    global $bps_options;
    $id = bp_get_the_profile_field_id ();
    
    if ( ((is_admin() && strpos($_SERVER['REQUEST_URI'], 'page=bp-profile-search'))
    || (isset($bps_options) && $bps_options['agerange'] == $id
    && isset($_POST['bp_profile_search']) && $_POST['bp_profile_search']))
    && $type == 'birthdate') {
    return 'datebox';
    }
    }
    
    return $type;
    }
    add_filter('bp_the_profile_field_type', 'bxcft_profile_field_type', 1);
    
    add_action('init', 'my_xprofile_links');
    function my_xprofile_links() {
    if (has_filter('bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data')) {
    remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9 );
    }
    if (has_filter('bp_get_the_profile_field_value', 'bxcft_xprofile_filter_link_profile_data')) {
    remove_filter( 'bp_get_the_profile_field_value', 'bxcft_xprofile_filter_link_profile_data', 9);
    }
    add_filter( 'bp_get_the_profile_field_value', 'my_xprofile_filter_link_profile_data', 10, 2);
    }
    
    function my_xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) {
    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 );
    $new_values[] = make_clickable( $value );
    }
    $values = implode( ', ', $new_values );
    }
    return $values;
    }
    
    #176347
    Hugo Ashmore
    Keymaster

    You’re not attempting to hide anything, if you have created xprofile field groups other than the default ‘Base’ then anything in those groups for user profile input will not show on the standard BP registration form only on the users account profile screen. If you are following that principle and those fields are showing on the main registration form then something is going wrong and likely you have third party plugins at work?

    #175772
    Shmoo
    Participant

    It’s my theme and I code WordPress themes for like 5 years now but I don’t see myself as a Developer it’s more a hobby 🙂

    I’m solid at HTML-CSS and can read PHP when I see it happen but I can’t write PHP it out of the box.

    This error shows up when I try to hide a complete xProfile-group-ID or just an unique xProfile-field-ID from the loop.

    This is what I did.
    Inside: my-theme/buddypress/members/single/profile/profile-loop.php
    I found the start of the loop

    
    <?php if ( bp_has_profile() ) : ?>
    ....
    

    My first thought was, maybe there are default options here to control the output of which ID’s will be visible so I started the search how the bp_has_profile() was build and looked into plugins/buddypress/bp-xprofile/bp-xprofile-template.php and found this at line 150:

    
    ....
    
    $defaults = array(
    	'user_id'             => bp_displayed_user_id(),
    	'profile_group_id'    => false,
    	'hide_empty_groups'   => true,
    	'hide_empty_fields'   => $hide_empty_fields_default,
    	'fetch_fields'        => true,
    	'fetch_field_data'    => true,
    	'fetch_visibility_level' => $fetch_visibility_level_default,
    	'exclude_groups'      => false, // Comma-separated list of profile field group IDs to exclude
    	'exclude_fields'      => false  // Comma-separated list of profile field IDs to exclude
    );
    

    This looks very familiar to bbPress so my first thoughts was lets try to add one of those Array’s to the loop and overwrite the default value.
    Just like this.

    
    <?php if ( bp_has_profile( array ( 'exclude_groups' => 1 ) ) ) : ?>
    ...
    

    This works perfect, it hides all xProfile-fields from the first Base primary Tab (back-end). Just like I wanted it because I didn’t want all the fields to show up front-end, I’ve got a few xProfile-fields that I use for user-customization of the profile-page. Each user can add color-codes to change the default menu-color and add background-images to their profile-page to make each profile a little more unique.
    Those field-ID’s are just urls or color-codes and don’t have to be visable to the public, thats why I try to hide them front-end.

    buddypress member pofile tab

    noizeburger
    Participant

    This topic has been always important to my community project. Throughout the last 4 years I’ve tried several ways to reach a way working with different user profiles. If you search the forums you’ll see that others also did and still do.

    Maybe my approach/solution will fit some of the requests.
    First of all, I’ve to say THANK YOU to the following people/users:


    @henrywright-1
    for some hints into the right direction
    donmik, publisher of the wonderful Buddypress Xprofile Custom Fields Type plugin
    and Brajesh Singh @sbrajesh for his usefull code snippets.

    So, what I needed and what was the solution?

    I’m working on a platform for musicians and music fans. To give both usertypes different capabilities in their profiles I decided to give them different user roles.
    To achive this, there are several wordpress plugins. Below you will find a list of the plugins I use.
    In earlier versions of Buddypress I’ve used the WP Roles at Registration plugin together with Buddypress xProfiles ACL plugin. So I had the possibility to make the user chose a role at registration and a way to define what buddypress profile groups are shown in the different profile types. Both plugins haven’t been updated in the last two years but both still work. xProfiles ACL needs to be hacked – see this support thread .

    So far so good. But there is no way to include the user role (in my case “band” and “fan”) in buddypress search. My first attempt was to include the user role via some code snippet in my member-loop, but that seemed a bit complicated to me. I wanted a conjunction between the user role and buddypress search. So there had to be a way to select the user role through a xprofile field, ’cause xprofile fields can be searched and also displayed in the member-loop in several ways.

    To stop confusing you, here’s what I’ve done:

    required plugins:

    1. Buddypress xProfiles ACL with the hack mentioned a few lines earlier.
    2. 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, modify the ACL plugin and define some profile field groups that can be finally added to the different user roles/types.
    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.

    In a second step you need to create a bp-custom.php in the root of your wordpress plugin folder (if you haven’t done this yet, cause you have other custom functions).
    Put the following snippet in your bp-custom:

    <?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);

    As you can see, I’ve included the title of the xprofile field in line 3. It’s important to put in the exact title of your xprofile field. The case “Band Role” and case “Fan Role” is the place to put your select options of the field. Finally $new_role has to be filled with the wordpress or custom user roles – important, otherwise it won’t work: in lowercase letters – in my case “band” and “fan”.

    Save your bp-custom.php and you’re nearly done.
    In my case I want to prevent the users to change their user role after registration (if you want to give them the possibility to do so, more hacking has to be done – but I’m not sure how to). Put another snippet in your bp-custom.php:

    //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;
    }

    Again, fill in the title of the profile field (User Role), where it’s indicated in the code.

    That’s it. I hope I haven’t been too confusing. Ask if you need help.

    #175180
    applegateian
    Participant

    Hi guys

    We have a sidebar custom plugin, where we return different user profile data based on the user type.

    One of these fields returns one of 6 drop down options. However, what I want to do is only one of 5 of the options if selected, and not display the 6th if present. I still need the 6th option but just don’t want to show it in the sidebar.

    Here is the line of code in the plugin to display this data:

     echo " <h2 class='sidebarRole'>".xprofile_get_field_data( 'Role (architect)', get_the_author_id()) ."</h2>";						
    

    Is there a way to say, if the returned result is ‘x’, then don’t display anything?

    Thanks,

    Ian

    dta_madrid
    Participant

    Hi,
    I’m a complete novice at Buddypress and I have spent a long time on these forums and the codex pages trying to figure out if this is possible…

    (excuse me if this has been repeated elsewhere – please point me in the right direction if it has)

    I’m trying to create a buddypress network for 2 different types of users (volunteers and hosts), each with their own different xprofile fields. I would only like the volunteers to view and contact the hosts and the hosts to view and contact the volunteers.
    I understand there is a great plugin to help part way with this ( buddypress user account type pro).
    This plugin can display different user types (in a filtered member’s directory) in a menu but It cannot hide the volunteer’s member’s directory from a logged-in volunteer and vice versa for the host.

    Does anyone have any other ideas or plugins that may be able to help? Is it possible to set up two different buddypress networks on two different installations / multi-network but be able to view each other’s profiles and message each other once logged in?

    I have very limited knowledge of php. So if it’s a case of changing something here, please can someone point me in the right direction.

    Thank you for your help.

    #170209
    webheadcoder
    Participant

    I have a request to not depend on the ‘bp_xprofile_visibility_levels’ user meta setting in order to hide fields. Or simply add a hidden input explained in the workaround. Here is why:

    I developed a private membership site so naturally I wanted to disallow the ‘public’ visibility setting. I added something like:

    function myfunction($levels) {
        unset($levels['public']);
        return $levels;
    }
    add_filter( 'bp_xprofile_get_visibility_levels', 'myfunction');

    This caused a chain reaction to show all fields with an enforced visibility.

    I have a Mobile Phone field along with several others to be forced to be ‘adminsonly’. So there is no form input (radio buttons) to switch the visibility. BuddyPress checks _POST[‘field_123_visibility’] and if there is no post field, the default visibility is ‘public’. Then BuddyPress checks for the allowed visibilities. Since i took out ‘public’, ‘public’ is not an allowed visibility and does not save the users’ visibility preference (in bp_xprofile_visibility_levels) . Because the user does not have a visibility preference saved for this field it is not checked to be hidden (bp_xprofile_get_fields_by_visibility_levels()). Since it’s not even considered to be hidden, it shows. This is where I’d like a change to the code. I don’t think it’s right to skip a field if it is not in the user meta.

    I’m not expert at BuddyPress so maybe unsetting the ‘public’ visibility setting is a big no-no. It just seems very strange that unsetting the ‘public’ visibility can cause ‘adminsonly’ fields to show publicly.

    My workaround for this is to just add a hidden field so that the usermeta is saved. in members/single/profile/edit.php I added the following:
    <input type="hidden" name="field_<?php bp_the_profile_field_id();?>_visibility" value="adminsonly">

    #167792
    nobodymove
    Participant

    @bphelp. I think I have discovered the culprit to this little mystery.. I have been using the Buddypress Members Import plugin: http://www.youngtechleads.com/buddypress-members-import/

    For some reason when I import my database, the plugin does not seem to process the xProfile Field visibility settings properly.. The profile fields are still listed as “Admins Only” But for some reason they are still visible to all users.

    Earlier, I manually added some new test profile fields and they worked fine. I also discovered, that if I edit, and re-save a user’s profile field after import, all profile fields for that user will then revert to the proper visibility settings.

    I have contacted the plugin author to make him aware of the issue, hopefully he can fix it. If you have any suggestions that might be a quick fix for this I’m all ears! 🙂

    #167443
    nobodymove
    Participant

    Thanks @bphelp. Info listed below:

    1. Which version of WordPress are you running?

    3.5.2

    2. Did you install WordPress as a directory or subdomain install?

    Directory

    3. If a directory install, is it in root or in a subdirectory?

    root

    4. Did you upgrade from a previous version of WordPress? If so, from which version?

    3.5

    5. Was WordPress functioning properly before installing/upgrading BuddyPress (BP)? e.g. permalinks, creating a new post, commenting.

    Wordpress seems to be working fine

    6. Which version of BP are you running?

    1.7.2

    7. Did you upgraded from a previous version of BP? If so, from which version?

    1.7

    8. Do you have any plugins other than BuddyPress installed and activated? If so, which ones?

    Yes, a lot. 🙂

    Allow Multiple Accounts
    amr users + buddypress
    buddypress group email subscription
    buddypress member import
    buddypress message attachement
    Buddypress Toolbar
    Buddypress Xprofile custom fields type
    comprehensive google map
    contact form manager
    events manager pro
    easy table
    form lightbox
    GRAND Flash Album Gallery
    Lightbox Galleries EWSEL
    Mass Messaging in Buddypress
    Online Backup for WordPress
    Peter’s Login Redirect
    SHortcode Widget
    User Switching
    WP Full Calendar
    WP Wunderground

    9. Are you using the standard BuddyPress themes or customized themes?

    I’m using Razor 1.1.3 from Themeforest/Parallelus

    10. Have you modified the core files in any way?

    No

    11. Do you have any custom functions in bp-custom.php?

    No

    12. If running bbPress, which version? Or did your BuddyPress install come with a copy of bbPress built-in?

    13. Please provide a list of any errors in your server’s log files.

    14. Which company provides your hosting?

    Network Solutions

    15. Is your server running Windows, or if Linux; Apache, nginx or something else?

    VPS hosting package

    #154621
    OccipitaL
    Participant

    Hi,

    I want to use wordpress username in every field of my site instead of buddypress’ “Name”.  Is it possible to disable the whole name system and use Username instead or to hide Name from every possible field and display Username instead.

    I’m totally newbie to this whole coding stuff, found a code and managed to hide “Name” field in profile edit but this is only preventing from changing it. I need to disable it or change it’s usage to Username. (in Activity feed, mentions & comments at least)

    In case anybody wonders what did I use for hiding Name from profile edit section;
    `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(“Name”,””);

    $count=count($fields);

    $flds=array();

    for($i=0;$iname,$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;`
    Added this code to bp-members-functions.php

    #150724
    haughtam
    Participant

    I can’t find the answer to this anywhere.  I have a profile group named “hidden” with xprofile fields that are used by me to track hidden information about users.  I can prevent this profile group from displaying while viewing the profile, but not while editing the profile.  In the members/single/edit.php file, there’s a function bp_profile_group_tabs() that displays the profile group buttons.  Does anyone know how I hide one of those?

    #144322
    David Cavins
    Keymaster

    I think a better bet is to collect that info on the BP registration page and then not display it on the user profile (that way you’ll still be able to use it in other ways). With BP 1.6. you can change the visibility of each xprofile field to friends only, logged-in users, or public (and force that level or allow the user to override your selection). (Visible to admin only is coming in BP 1.7, btw, which would totally fix you up.) At the moment, you can modify your theme template file (themes/yourtheme/members/single/profile/profile-loop.php) to hide some fields like this:
    `about line 17:

    <?php $no_display_fields = array( // Enter the field name of any field that you don't want to appear on the user profile.
    ‘E-mail’,
    ‘Name of Field Hide’,
    ‘Another’
    );

    if ( bp_field_has_data() && !in_array( bp_get_the_profile_field_name(), $no_display_fields ) ) : ?>`

    It’s a hack, but it works for me (until BP 1.7).

    #140405
    johndavis84
    Member

    I need to be able to show / Hide XProfile groups based on select value during the registration phase. I’m a newbie to all this so could someone please help on how accomplish this.

    Is that possible with buddypress? Has this plugin been created?

    Roger Coathup
    Participant

    @natetheaverage

    an outline solution (there are lots of areas where you’d have to work to implement it):

    When a group is created, you could write a hook that creates a corresponding xprofile field group (remember to hook on delete group as well to remove the profile field group)
    In the member’s profile screens, you would hide that xprofile field group if the member is not a member of the group
    In a hook on Join Group, you’d want to display an additional screen that prompts for the user fields, and when that is submitted use the xprofile API to write the data to the user’s profile
    I guess finally, you’d also want to modify the members loop inside the group to show that information

    There’s a lot of code for you to trawl through

    #28753
    fmeroney
    Member

    I have a question about profile data control. It seems that data displayin the member profile is controlled by the active theme. In my case it is themes/buddyboss/members/single/profile/profile-loop.php, I think?

    So my question is:
    If i want to modify the code to display all empty fields, hide_empty_fields=false, do i change the code in BuddyPress’s bp_xprofile_template.php? When i set hide_empty_field to false, it does nothing.

    Any ideas?

    Hugo Ashmore
    Keymaster

    You’ll need to do something like wrap the custom xprofile loop section in a check for a specific field name ‘birthdate’ and do something like ‘if not’ ‘birthdate’ go ahead and display field item or display if is_admin if you want to be able to see users data as a site admin.

    To remove a field you could do:
    `

    <tr>

    `
    in the profile loop; equally if you wanted to remove a complete field group you can copy the approach seen in the file for ensuring that the base group is not shown `if ( 1 != bp_get_the_profile_group_id() ) ` adding an OR followed by a check on the group id to hide.

Viewing 25 results - 51 through 75 (of 129 total)
Skip to toolbar