Skip to content

Commit

Permalink
Set values on new lines
Browse files Browse the repository at this point in the history
  • Loading branch information
buntybuddyboss committed Jan 2, 2021
1 parent c9d06b3 commit a84790b
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions app/main/class-bp-field-repeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public function __construct() {
add_filter( 'bp_xprofile_field_edit_html_elements', array( $this, 'bppfr_field_edit_html_elements' ), 10, 2 );

add_filter( 'bp_xprofile_set_field_data_pre_validate', array( $this, 'bppfr_set_field_data' ), 99, 3 );

add_filter( 'bp_get_the_profile_field_value', array( $this, 'bppfr_profile_field_value' ), 10, 3 );
}

/**
Expand Down Expand Up @@ -233,6 +235,41 @@ public function bppfr_set_field_data( $value, $field, $field_type_obj ) {
return $value;

}

/**
* Filters the XProfile field value.
*
* @since 1.0.0
*
* @param string $value Value for the profile field.
* @param string $type Type for the profile field.
* @param int $id ID for the profile field.
*/
public function bppfr_profile_field_value( $value, $type, $id ) {

// Bail, if anything goes wrong.
if ( ! function_exists( 'bp_displayed_user_id' ) || ! function_exists( 'xprofile_get_field_data' ) ) {
return $value;
}

// Get value if field is repeater or not.
$field_is_repeater = function_exists( 'bp_xprofile_get_meta' )
? bp_xprofile_get_meta( $id, 'field', 'field_is_repeater' )
: '';

if ( ! empty( $field_is_repeater ) && 'yes' === $field_is_repeater ) {

// Get value.
$value = xprofile_get_field_data( $id, bp_displayed_user_id() );

// Make all result on new line.
if ( ! empty( $value ) ) {
$value = implode( '<br/>', $value );
}
}

return $value;
}
}

new BP_Profile_Field_Repeater_Main();
Expand Down

0 comments on commit a84790b

Please sign in to comment.