Filter
uncanny-automator
automator_bp_xprofile_field_data
Filters BuddyBoss xProfile field data before it's displayed or saved for a specific user.
add_filter( 'automator_bp_xprofile_field_data', $callback, 10, 3 );
Description
Filters BuddyBoss XProfile field data for a specific user. Developers can modify the retrieved field value before it's used by the Uncanny Automator integration, allowing for custom data manipulation based on field ID and user ID.
Usage
add_filter( 'automator_bp_xprofile_field_data', 'your_function_name', 10, 3 );
Parameters
-
$field_data(mixed) - This parameter holds the retrieved BuddyPress XProfile field data for the specified user.
-
$field_id(mixed) - This parameter contains the value of the BuddyPress XProfile field.
-
$user_id(mixed) - This parameter holds the ID of the BuddyPress XProfile field whose data is being processed.
Return Value
The filtered value.
Examples
add_filter( 'automator_bp_xprofile_field_data', 'my_custom_bp_xprofile_field_data_filter', 10, 3 );
/**
* Example filter to modify BuddyPress XProfile field data.
*
* This function demonstrates how to hook into the 'automator_bp_xprofile_field_data'
* filter to potentially alter the data retrieved for a BuddyPress XProfile field.
* In this example, we'll check if the field is a specific date field (e.g., 'Date of Birth')
* and if so, format it into a more readable string.
*
* @param mixed $field_data The original field data.
* @param mixed $field_id The ID of the XProfile field.
* @param mixed $user_id The ID of the user.
*
* @return mixed The potentially modified field data.
*/
function my_custom_bp_xprofile_field_data_filter( $field_data, $field_id, $user_id ) {
// Assuming you know the field ID for 'Date of Birth' or similar.
// Replace '123' with the actual ID of the date field you want to modify.
$date_of_birth_field_id = 123;
if ( $field_id == $date_of_birth_field_id && ! empty( $field_data ) ) {
// The field_data for date fields is typically a Unix timestamp or a date string.
// We'll attempt to convert it to a readable date format.
$timestamp = strtotime( $field_data );
if ( $timestamp ) {
// Format the date as 'F j, Y' (e.g., 'January 1, 1990')
$formatted_date = date_i18n( get_option( 'date_format' ), $timestamp );
$field_data = $formatted_date;
}
}
// You could also add logic here to:
// - Check the user_id and apply different modifications based on the user.
// - Check the type of field (though this is not directly provided by the hook parameters).
// - Add specific default values if $field_data is empty for certain fields.
return $field_data;
}
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
src/integrations/buddyboss/tokens/bdb-universal-token.php:61
src/integrations/buddypress/tokens/bp-universal-token.php:61
public function parse_integration_token( $return, $pieces, $recipe_id, $trigger_data, $user_id, $replace_args ) {
$field_id = $pieces[2];
// Change the user ID to the current iterated user in the context of a Loop.
if ( isset( $replace_args['loop'] ) && is_array( $replace_args['loop'] ) && isset( $replace_args['loop']['user_id'] ) ) {
$user_id = absint( $replace_args['loop']['user_id'] );
}
$field_data = xprofile_get_field_data( $field_id, $user_id );
return apply_filters( 'automator_bp_xprofile_field_data', $field_data, $field_id, $user_id );
}