automator_buddyboss_xprofile_field_is_array
Filters BuddyBoss XProfile fields to determine if they are arrays, allowing customization of array field detection.
add_filter( 'automator_buddyboss_xprofile_field_is_array', $callback, 10, 1 );
Description
Filters whether a BuddyBoss xProfile field type should be treated as an array. This is useful for handling multi-value fields like checkboxes and multiselects when setting user profile data. Developers can add or remove field types from the default array of checkbox, multiselectbox, and socialnetworks.
Usage
add_filter( 'automator_buddyboss_xprofile_field_is_array', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
add_filter( 'automator_buddyboss_xprofile_field_is_array', 'my_custom_automator_array_xprofile_fields', 10, 1 );
/**
* Customizes the list of BuddyBoss/BuddyPress XProfile field types that are considered arrays.
* This allows Uncanny Automator to correctly handle data for these field types.
*
* For example, if you have a custom XProfile field type that behaves like an array (e.g., accepts multiple selections),
* you can add its type slug to this filter to ensure Uncanny Automator treats it as such.
*
* @param array $array_field_types The default array of field types considered to be arrays.
* @return array The modified array of field types considered to be arrays.
*/
function my_custom_automator_array_xprofile_fields( $array_field_types ) {
// Let's say we have a custom XProfile field type called 'custom_multi_select'
// that also needs to be treated as an array by Uncanny Automator.
$array_field_types[] = 'custom_multi_select';
// You could also conditionally remove types if needed, for instance:
// if ( ( $key = array_search( 'socialnetworks', $array_field_types ) ) !== false ) {
// unset( $array_field_types[ $key ] );
// }
return $array_field_types;
}
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
uncanny-automator-pro/src/integrations/buddyboss/actions/bdb-setuserprofiledata.php:170
uncanny-automator-pro/src/integrations/buddypress/actions/bp-setuserprofiledata.php:170
private function maybe_format_field_value( $value, $field_id ) {
$field = xprofile_get_field( $field_id );
if ( ! is_a( $field, 'BP_XProfile_Field' ) ) {
return $value;
}
$is_array_type = apply_filters(
'automator_buddyboss_xprofile_field_is_array',
array(
'checkbox',
'multiselectbox',
'socialnetworks',
)
);
if ( in_array( $field->type, $is_array_type ) ) {
$value = ! is_array( $value ) ? explode( ',', $value ) : $value;
}
$is_date_type = apply_filters(
'automator_buddyboss_xprofile_field_is_date',
array(
'datebox',
)
);
// Date field.
if ( in_array( $field->type, $is_date_type ) ) {
// Check if value is a valid date.
if ( strtotime( $value ) ) {
// Check if time is set, if not set it to 00:00:00
$date = new DateTime( $value );
if ( $date->format( 'H:i:s' ) == '00:00:00' ) {
$value = $date->format( 'Y-m-d 00:00:00' );
} else {
$value = $date->format( 'Y-m-d H:i:s' );
}
}
}
return $value;
}