Filter uncanny-automator-pro

automator_buddyboss_set_user_profile_data_value

Filters the value of a BuddyBoss profile field before it's set for a user.

add_filter( 'automator_buddyboss_set_user_profile_data_value', $callback, 10, 5 );

Description

Fires before BuddyBoss or BuddyPress profile field data is set for a user. Developers can use this filter to modify the value being saved, alter the field ID, or influence the process based on user ID, recipe, or arguments. It's crucial to ensure data integrity and compatibility with profile field types.


Usage

add_filter( 'automator_buddyboss_set_user_profile_data_value', 'your_function_name', 10, 5 );

Parameters

$value (mixed)
This parameter contains the value that will be set for the user's profile field.
$field_id (mixed)
This parameter represents the value that will be set for the user's profile field.
$user_id (mixed)
This parameter holds the unique identifier of the BuddyBoss profile field to which data will be set.
$recipe_id (mixed)
This parameter contains the unique identifier of the user whose profile data is being updated.
$args (mixed)
This parameter contains the unique identifier for the specific Uncanny Automator recipe that is triggering the update of the user's profile data.

Return Value

The filtered value.


Examples

/**
 * Example: Modify the value of a BuddyBoss profile field before it's set.
 *
 * This filter allows you to intercept and modify the value that will be saved
 * to a BuddyBoss user profile field. For instance, you might want to ensure
 * a specific string is always appended, or perhaps convert a value to a different format.
 *
 * @param mixed $value The current value to be set for the profile field.
 * @param mixed $field_id The ID of the BuddyBoss profile field.
 * @param mixed $user_id The ID of the user whose profile is being updated.
 * @param mixed $recipe_id The ID of the Uncanny Automator recipe.
 * @param mixed $args An array of additional arguments passed to the action.
 *
 * @return mixed The modified or original value to be saved.
 */
add_filter(
	'automator_buddyboss_set_user_profile_data_value',
	function ( $value, $field_id, $user_id, $recipe_id, $args ) {

		// Example: If the field is a 'Website' field (assuming you know its ID, e.g., 123)
		// and the value is not empty, prepend 'https://' if it's missing.
		if ( absint( $field_id ) === 123 && ! empty( $value ) ) {
			if ( ! filter_var( $value, FILTER_VALIDATE_URL ) ) {
				$value = 'https://' . esc_url( $value );
			}
		}

		// Example: If it's a 'City' field (assuming you know its ID, e.g., 456)
		// and the value is not empty, always capitalize the first letter of each word.
		if ( absint( $field_id ) === 456 && ! empty( $value ) ) {
			$value = ucwords( sanitize_text_field( $value ) );
		}

		// Always return the value, whether modified or not.
		return $value;
	},
	10, // Priority
	5  // Number of accepted arguments
);

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:128
uncanny-automator-pro/src/integrations/buddypress/actions/bp-setuserprofiledata.php:128

public function update_user_profile_data( $user_id, $action_data, $recipe_id, $args ) {

		// Bail required function doesn't exist.
		if ( ! function_exists( 'xprofile_set_field_data' ) ) {
			$action_data['complete_with_errors'] = true;
			Automator()->complete_action( $user_id, $action_data, $recipe_id, __( 'xprofile_set_field_data function does not exist.', 'uncanny-automator-pro' ) );
			return;
		}

		$user_fields_data = $action_data['meta']['BDBPROFILEDATA'];

		// Set Variables in case we need to do xprofile_updated_profile action.
		$posted_field_ids = array();
		$old_values       = array();
		$new_values       = array();

		// Adding other users
		if ( ! empty( $user_fields_data ) ) {
			$user_selectors = json_decode( $user_fields_data, true );
			if ( ! empty( $user_selectors ) ) {
				foreach ( $user_selectors as $user_selector ) {
					$field_id = $user_selector['BDBUSERFIELD'];
					if ( ! empty( $user_selector['VALUE'] ) ) {
						$value = Automator()->parse->text( $user_selector['VALUE'], $recipe_id, $user_id, $args );

						// Format value based on field type.
						$value = $this->maybe_format_field_value( $value, $field_id );
						$value = apply_filters( 'automator_buddyboss_set_user_profile_data_value', $value, $field_id, $user_id, $recipe_id, $args );

						// Populate variables for do xprofile_updated_profile action.
						$field_array             = array(
							'value'      => xprofile_get_field_data( $field_id, $user_id ),
							'visibility' => xprofile_get_field_visibility_level( $field_id, $user_id ),
						);
						$posted_field_ids[]      = $field_id;
						$old_values[ $field_id ] = $field_array;
						$field_array['value']    = $value;
						$new_values[ $field_id ] = $field_array;

						// Update Field.
						xprofile_set_field_data( $field_id, $user_id, $value );
					}
				}
			}
		}

		// Maybe do xprofile_updated_profile action.
		if ( empty( did_action( 'xprofile_updated_profile' ) ) && ! empty( $posted_field_ids ) ) {
			do_action( 'xprofile_updated_profile', $user_id, $posted_field_ids, false, $old_values, $new_values );
		}

		Automator()->complete_action( $user_id, $action_data, $recipe_id );
	}


Scroll to Top