Created
November 14, 2018 18:18
-
-
Save mcorkum/74dd6b304516b331c05bf78cccb96cca to your computer and use it in GitHub Desktop.
Add custom meta to export
This file contains 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 custom metadata to the columns for export | |
* | |
* @param array $data Current data in the export | |
* @param array $payment Array containing payment metadata | |
* | |
* @return array $data - Modified data | |
*/ | |
function add_data_to_export( $data, $payment ) { | |
// This assumes meta value is already added to the donation. You could call another function here to get the value. | |
// If the meta is a part of the donation form you can get it using give_get_payment_form_id( id ); | |
$data['meta_name'] = ( isset( $payment->payment_meta['meta_name'] ) ) ? $payment->payment_meta['meta_name'] : 'N/A'; | |
return $data; | |
} | |
add_filter( 'give_export_donation_data', 'add_data_to_export' ); | |
/** | |
* Changes the column labels for custom metadata on export | |
* | |
* @param array $cols Actual column names in the export | |
* @param array $columns Array containing info about which columns have been selected for export | |
* | |
* @return array $cols Columns with modified names | |
*/ | |
function change_export_column_names( $cols, $columns ) { | |
$cols['meta_name'] = 'Column Title'; | |
return $cols; | |
} | |
add_filter( 'give_export_donation_get_columns_name', 'change_export_column_names', 99, 2 ); | |
/** | |
* Add HTML to the CSV on the admin CSV export page | |
* | |
* @since v1.0 | |
* | |
* @return void | |
*/ | |
function donation_extra_fields() { | |
?> | |
<li class="give-export-option-start"> | |
<label for="give-export-donation-meta-name"> | |
<input type="checkbox" checked | |
name="give_give_donations_export_option[meta_name]" | |
id="give-export-donation-meta-name"><?php _e( 'Label Name', 'give' ); ?> | |
</label> | |
</li> | |
<?php | |
} | |
add_action( 'give_export_donation_standard_payment_fields', 'donation_extra_fields' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment