payment_meta->get_meta_type() . '_id'; $form_id = isset( $_POST['form_id'] ) ? absint( $_POST['form_id'] ) : ''; if ( empty( $form_id ) ) { wp_send_json_error(); } $args = [ 'give_forms' => [ $form_id ], 'posts_per_page' => - 1, 'fields' => 'ids', ]; $donation_list = implode( ',', (array) give_get_payments( $args ) ); $query_and = sprintf( "AND $wpdb->posts.ID IN (%s) AND $wpdb->donationmeta.meta_key != '' AND $wpdb->donationmeta.meta_key NOT RegExp '(^[_0-9].+$)'", $donation_list ); $query = " SELECT DISTINCT($wpdb->donationmeta.meta_key) FROM $wpdb->posts LEFT JOIN $wpdb->donationmeta ON $wpdb->posts.ID = {$wpdb->donationmeta}.{$donationmeta_table_key} WHERE $wpdb->posts.post_type = '%s' " . $query_and; $meta_keys = $wpdb->get_col( $wpdb->prepare( $query, $post_type ) ); if ( ! empty( $meta_keys ) ) { $responses['standard_fields'] = array_values( $meta_keys ); } $query_and = sprintf( "AND $wpdb->posts.ID IN (%s) AND $wpdb->donationmeta.meta_key != '' AND $wpdb->donationmeta.meta_key NOT RegExp '^[^_]'", $donation_list ); $query = " SELECT DISTINCT($wpdb->donationmeta.meta_key) FROM $wpdb->posts LEFT JOIN $wpdb->donationmeta ON $wpdb->posts.ID = {$wpdb->donationmeta}.{$donationmeta_table_key} WHERE $wpdb->posts.post_type = '%s' " . $query_and; $hidden_meta_keys = $wpdb->get_col( $wpdb->prepare( $query, $post_type ) ); /** * Filter to modify hidden keys that are going to be ignore when displaying the hidden keys * * @param array $ignore_hidden_keys Hidden keys that are going to be ignore * @param array $form_id Donation form id * * @return array $ignore_hidden_keys Hidden keys that are going to be ignore * @since 2.1 */ $ignore_hidden_keys = apply_filters( 'give_export_donations_ignore_hidden_keys', [ '_give_payment_meta', '_give_payment_gateway', '_give_payment_mode', '_give_payment_form_title', '_give_payment_form_id', '_give_payment_price_id', '_give_payment_user_id', '_give_payment_user_email', '_give_payment_user_ip', '_give_payment_customer_id', '_give_payment_total', '_give_completed_date', '_give_donation_company', '_give_donor_billing_first_name', '_give_donor_billing_last_name', '_give_payment_donor_email', '_give_payment_donor_id', '_give_payment_date', '_give_donor_billing_address1', '_give_donor_billing_address2', '_give_donor_billing_city', '_give_donor_billing_zip', '_give_donor_billing_state', '_give_donor_billing_country', '_give_payment_import', '_give_payment_currency', '_give_payment_import_id', '_give_payment_donor_ip', '_give_payment_donor_title_prefix', ], $form_id ); // Unset ignored hidden keys. foreach ( $ignore_hidden_keys as $key ) { if ( ( $key = array_search( $key, $hidden_meta_keys ) ) !== false ) { unset( $hidden_meta_keys[ $key ] ); } } if ( ! empty( $hidden_meta_keys ) ) { $responses['hidden_fields'] = array_values( $hidden_meta_keys ); } /** * Filter to modify custom fields when select donation forms, * * @param array $responses Contain all the fields that need to be display when donation form is display * @param int $form_id Donation Form ID * * @return array $responses * @since 2.1 */ wp_send_json( (array) apply_filters( 'give_export_donations_get_custom_fields', $responses, $form_id ) ); } add_action( 'wp_ajax_give_export_donations_get_custom_fields', 'give_export_donations_get_custom_fields' ); /** * Register the payments batch exporter * * @since 1.0 */ function give_register_export_donations_batch_export() { add_action( 'give_batch_export_class_include', 'give_export_donations_include_export_class', 10, 1 ); } add_action( 'give_register_batch_exporter', 'give_register_export_donations_batch_export', 10 ); /** * Includes the Give Export Donations Custom Exporter Class. * * @param $class Give_Export_Donations_CSV */ function give_export_donations_include_export_class( $class ) { if ( 'Give_Export_Donations_CSV' === $class ) { require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/give-export-donations-exporter.php'; } } /** * Create column key. * * @param $string * * @return string */ function give_export_donations_create_column_key( $string ) { return sanitize_key( str_replace( ' ', '_', $string ) ); } /** * Filter to modify donation search form when search through AJAX * * @since 2.1 * * @param $args * * @return array */ function give_export_donation_form_search_args( $args ) { if ( empty( $_POST['fields'] ) ) { return $args; } $fields = isset( $_POST['fields'] ) ? $_POST['fields'] : ''; $fields = array_map( 'give_clean', wp_parse_args( $fields, [] ) ); if ( ! empty( $fields['give_forms_categories'] ) || ! empty( $fields['give_forms_tags'] ) ) { $args['posts_per_page'] = - 1; } if ( ! empty( $fields['give_forms_categories'] ) && ! empty( $fields['give_forms_tags'] ) ) { $args['tax_query']['relation'] = 'AND'; } if ( ! empty( $fields['give_forms_categories'] ) ) { $args['tax_query'][] = [ 'taxonomy' => 'give_forms_category', 'field' => 'term_id', 'terms' => $fields['give_forms_categories'], 'operator' => 'AND', ]; } if ( ! empty( $fields['give_forms_tags'] ) ) { $args['tax_query'][] = [ 'taxonomy' => 'give_forms_tag', 'field' => 'term_id', 'terms' => $fields['give_forms_tags'], 'operator' => 'AND', ]; } return $args; } add_filter( 'give_ajax_form_search_args', 'give_export_donation_form_search_args' ); /** * Add Donation standard fields in export donation page * * @since 3.12.1 add Donor Phone Number to donor fields. * @since 2.1 */ function give_export_donation_standard_fields() { ?>
Hidden fields are generally used for programming logic, but may contain data you would like to export.', 'give' ); ?>