Last active
March 4, 2024 22:33
-
-
Save rafsuntaskin/d1e58c074e67bf28ef752a8bd635d1fb to your computer and use it in GitHub Desktop.
CSV export patch for checkboxes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'tribe_events_tickets_attendees_table_column', 'tec_et_csv_override_checkbox_patch', 99, 3 ); | |
function tec_et_csv_override_checkbox_patch( $existing, $item, $column ) { | |
$meta_data = get_post_meta( $item['attendee_id'], Tribe__Tickets_Plus__Meta::META_KEY, true ); | |
/** | |
* Allow plugins to remove support for checkbox field values being displayed or override the text shown. | |
* | |
* @since 4.10.4 | |
* | |
* @param string|false $checkbox_label Label value of checkbox that is checked, return false to turn off label support. | |
*/ | |
$checkbox_label = apply_filters( 'tribe_events_tickets_plus_attendees_list_checkbox_label', __( 'Checked', 'event-tickets-plus' ) ); | |
if ( false === $checkbox_label ) { | |
return $existing; | |
} | |
// Validate if Checkbox type. | |
$checkbox_parts = explode( '_', $column ); | |
if ( 2 !== count( $checkbox_parts ) ) { | |
return $existing; | |
} | |
if ( isset( $meta_data[ $column ] ) ) { | |
return $checkbox_label; | |
} | |
$key = $checkbox_parts[0] . '_' . md5( $checkbox_parts[1] ); | |
if ( isset( $meta_data[ $key ] ) ) { | |
return $checkbox_label; | |
} | |
// check for non-hashed data. | |
foreach ( $meta_data as $key => $value ) { | |
if ( strpos( $key, $checkbox_parts[0] ) !== false ) { | |
$key_parts = explode( '_', $key ); | |
if ( ( md5( $key_parts[1] ) === $checkbox_parts[1] ) && ! empty( $value ) ) { | |
return $checkbox_label; | |
} | |
} | |
} | |
return $existing; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment