Tribe__Tickets_Plus__Meta__Export::csv_cleanup_checkbox_value( mixed $value, array $item, string $column )
Fix column value based on meta data.
Contents
This method retrieves meta data for the attendee and checks if the column represents a checkbox field. If so, it returns the label value for checked checkboxes. If not, it returns the original value.
Parameters
- $value
-
(mixed) (Required) The value of the column.
- $item
-
(array) (Required) The item being processed.
- $column
-
(string) (Required) The column identifier.
Return
(mixed) The fixed column value.
Source
File: src/Tribe/Meta/Export.php
public function csv_cleanup_checkbox_value( $value, $item, $column ) {
$meta_data = get_post_meta( $item['attendee_id'], Tribe__Tickets_Plus__Meta::META_KEY, true );
// Make sure $meta_data is an array.
if ( ! is_array( $meta_data ) ) {
return $value;
}
$original_value = $value;
$checkbox_label = $this->apply_checkbox_label();
if ( false === $checkbox_label ) {
return $original_value;
}
// Validate if Checkbox type.
$checkbox_parts = explode( '_', $column );
if ( 2 !== count( $checkbox_parts ) ) {
return $original_value;
}
// Check if the column exists in the meta data.
if ( isset( $meta_data[ $column ] ) || isset( $meta_data[ $checkbox_parts[0] . '_' . md5( $checkbox_parts[1] ) ] ) ) {
return $checkbox_label;
}
// Check for non-hashed data.
foreach ( $meta_data as $key => $value ) {
// Check if the key starts with the checkbox identifier followed by an underscore.
if ( str_starts_with( $key, $checkbox_parts[0] . '_' ) ) {
// Extract the hash part of the key.
$hash = substr( $key, strlen( $checkbox_parts[0] ) + 1 );
// Compare the hash with the expected hash.
if ( md5( $hash ) === $checkbox_parts[1] && ! empty( $value ) ) {
return $value;
}
}
}
return $original_value;
}
Changelog
| Version | Description |
|---|---|
| 5.10.2 | Introduced. |