xprofile_sanitize_data_value_before_save( string $field_value, int $field_id, bool $reserialize = true, object|null $data_obj = null )

Safely runs profile field data through kses and force_balance_tags.


Parameters Parameters

$field_value

(string) (Required) Field value being sanitized.

$field_id

(int) (Required) Field ID being sanitized.

$reserialize

(bool) (Optional) Whether to reserialize arrays before returning. Defaults to true.

Default value: true

$data_obj

(object|null) (Optional) The BP_XProfile_ProfileData object.

Default value: null


Top ↑

Return Return

(string)


Source Source

File: bp-xprofile/bp-xprofile-filters.php

function xprofile_sanitize_data_value_before_save( $field_value, $field_id = 0, $reserialize = true, $data_obj = null ) {

	// Return if empty.
	if ( empty( $field_value ) ) {
		return $field_value;
	}

	// Force reserialization if serialized (avoids mutation, retains integrity)
	if ( is_serialized( $field_value ) && ( false === $reserialize ) ) {
		$reserialize = true;
	}

	// Value might be a serialized array of options.
	$field_value = maybe_unserialize( $field_value );

	// Sanitize single field value.
	if ( ! is_array( $field_value ) ) {
		$kses_field_value     = xprofile_filter_kses( $field_value, $data_obj );
		$filtered_field_value = wp_rel_nofollow( force_balance_tags( $kses_field_value ) );

		/**
		 * Filters the kses-filtered data before saving to database.
		 *
		 * @since 1.5.0
		 *
		 * @param string                  $filtered_field_value The filtered value.
		 * @param string                  $field_value          The original value before filtering.
		 * @param BP_XProfile_ProfileData $data_obj             The BP_XProfile_ProfileData object.
		 */
		$filtered_field_value = apply_filters( 'xprofile_filtered_data_value_before_save', $filtered_field_value, $field_value, $data_obj );

	// Sanitize multiple individual option values.
	} else {
		$filtered_values = array();
		foreach ( (array) $field_value as $value ) {
			$kses_field_value = xprofile_filter_kses( $value, $data_obj );
			$filtered_value   = wp_rel_nofollow( force_balance_tags( $kses_field_value ) );

			/** This filter is documented in bp-xprofile/bp-xprofile-filters.php */
			$filtered_values[] = apply_filters( 'xprofile_filtered_data_value_before_save', $filtered_value, $value, $data_obj );
		}

		if ( !empty( $reserialize ) ) {
			$filtered_field_value = serialize( $filtered_values );
		} else {
			$filtered_field_value = $filtered_values;
		}
	}

	return $filtered_field_value;
}


Top ↑

Changelog Changelog

Changelog
Version Description
1.2.6 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.