'cf7wpa_data',
'posts_per_page' => -1
);
$exported_data = get_posts( $args );
if ( empty( $exported_data ) )
return;
/** CSV Export **/
$filename = 'cf7wpa-' . $form_id . '-' . time() . '.csv';
$header_row = array(
'_form_id' => 'Form ID/Name',
'_payer_email' => 'Payer Email Address',
'_transaction_id' => 'Transaction ID',
'_invoice_no' => 'Invoice ID',
'_amount' => 'Amount',
'_quantity' => 'Quantity',
'_total' => 'Total',
'_currency' => 'Currency code',
'_submit_time' => 'Submit Time',
'_request_Ip' => 'Request IP',
'_transaction_status' => 'Transaction status'
);
$data_rows = array();
if ( !empty( $exported_data ) ) {
foreach ( $exported_data as $entry ) {
$row = array();
if ( !empty( $header_row ) ) {
foreach ( $header_row as $key => $value ) {
if (
$key != '_transaction_status'
&& $key != '_submit_time'
) {
$row[$key] = __(
(
(
'_form_id' == $key
&& !empty( get_the_title( get_post_meta( $entry->ID, $key, true ) ) )
)
? get_the_title( get_post_meta( $entry->ID, $key, true ) )
: get_post_meta( $entry->ID, $key, true )
)
);
} else if ( $key == '_transaction_status' ) {
$row[$key] = __(
(
(
!empty( CF7WPA()->lib->response_status )
&& array_key_exists( get_post_meta( $entry->ID , $key, true ), CF7WPA()->lib->response_status )
)
? CF7WPA()->lib->response_status[get_post_meta( $entry->ID , $key, true )]
: get_post_meta( $entry->ID , $key, true )
)
);
} else if ( '_submit_time' == $key ) {
$row[$key] = __( get_the_date( 'd, M Y H:i:s', $entry->ID ) );
}
}
}
/* form_data */
$amount = (
(
!empty( $form_id )
)
? get_post_meta( $form_id, CF7WPA_META_PREFIX . 'amount', true )
: ''
) ;
$quantity = (
(
!empty( $form_id )
)
? get_post_meta( $form_id, CF7WPA_META_PREFIX . 'quantity', true )
: ''
) ;
$data = unserialize( get_post_meta( $entry->ID, '_form_data', true ) );
$hide_data = apply_filters( CF7WPA_PREFIX . '/hide-display', array( '_wpcf7', '_wpcf7_version', '_wpcf7_locale', '_wpcf7_unit_tag', '_wpcf7_container_post' ) );
foreach ( $hide_data as $key => $value ) {
if ( array_key_exists( $value, $data ) ) {
unset( $data[$value] );
}
}
if ( !empty( $data ) ) {
foreach ( $data as $key => $value ) {
if ( strpos( $key, 'authorize-' ) === false ) {
if ( !in_array( $key, $header_row ) ) {
$header_row[$key] = $key;
}
if(
!empty( $amount )
&& is_array($value)
&& $key == $amount
) {
$value2 = array_sum( $value );
}elseif (
!empty( $quantity )
&& is_array($value)
&& $key == $quantity
){
$value2 = array_sum( $value );
} else if ( is_array( $value ) ) {
$value2 = implode (", ", $value );
} else {
$value2 = $value;
}
$row[$key] = __( $value2 );
}
}
}
$data_rows[] = $row;
}
}
ob_start();
$fh = @fopen( 'php://output', 'w' );
fprintf( $fh, chr(0xEF) . chr(0xBB) . chr(0xBF) );
header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
header( 'Content-Description: File Transfer' );
header( 'Content-type: text/csv' );
header( "Content-Disposition: attachment; filename={$filename}" );
header( 'Expires: 0' );
header( 'Pragma: public' );
fputcsv( $fh, $header_row );
foreach ( $data_rows as $data_row ) {
fputcsv( $fh, $data_row );
}
fclose( $fh );
ob_end_flush();
die();
}
}
/**
* Action: add_meta_boxes
*
* - Add mes boxes for the CPT "cf7wpa_data"
*/
function action__add_meta_boxes() {
add_meta_box( 'cfwpa-data', __( 'From Data', 'contact-form-7-worldpay-addon' ), array( $this, 'cfwpa_show_from_data' ), 'cf7wpa_data', 'normal', 'high' );
add_meta_box( 'cfwpa-help', __( 'Do you need help for configuration?', 'contact-form-7-worldpay-addon' ), array( $this, 'cfwpa_show_help_data' ), 'cf7wpa_data', 'side', 'high' );
}
/**
* Save Worldpay field settings
*/
public function action__wpcf7_save_contact_form( $WPCF7_form ) {
$wpcf7 = WPCF7_ContactForm::get_current();
if ( !empty( $wpcf7 ) ) {
$post_id = $wpcf7->id;
}
$form_fields = array(
CF7WPA_META_PREFIX . 'use_worldpay',
CF7WPA_META_PREFIX . 'mode_sandbox',
CF7WPA_META_PREFIX . 'debug',
CF7WPA_META_PREFIX . 'installation_id',
CF7WPA_META_PREFIX . 'amount',
CF7WPA_META_PREFIX . 'quantity',
CF7WPA_META_PREFIX . 'email',
CF7WPA_META_PREFIX . 'description',
CF7WPA_META_PREFIX . 'currency',
CF7WPA_META_PREFIX . 'success_returnurl',
CF7WPA_META_PREFIX . 'cancel_returnurl',
);
/**
* Save custom form setting fields
*
* @var array $form_fields
*/
$form_fields = apply_filters( CF7WPA_PREFIX . '/save_fields', $form_fields );
if(!get_option('_exceed_cf7wpa_l')){
add_option('_exceed_cf7wpa_l', 'cf7wpa10');
}
if ( !empty( $form_fields ) ) {
foreach ( $form_fields as $key ) {
$keyval = sanitize_text_field( $_REQUEST[ $key ] );
update_post_meta( $post_id, $key, $keyval );
}
}
}
/**
* Action: manage_cf7wpa_data_posts_custom_column
*
* @method action__manage_cf7wpa_data_posts_custom_column
*
* @param string $column
* @param int $post_id
*
* @return string
*/
function action__manage_cf7wpa_data_posts_custom_column( $column, $post_id ) {
$data_ct = $this->cfwpa_check_data_ct( sanitize_text_field( $post_id ) );
switch ( $column ) {
case 'form_id' :
echo (
!empty( get_post_meta( $post_id , '_form_id', true ) )
? (
!empty( get_the_title( get_post_meta( $post_id , '_form_id', true ) ) )
? get_the_title( get_post_meta( $post_id , '_form_id', true ) )
: get_post_meta( $post_id , '_form_id', true )
)
: ''
);
break;
case 'transaction_status' :
if( $data_ct ){
echo 'To unlock more features consider upgrading to PRO';
}else{
echo (
!empty( get_post_meta( $post_id , '_transaction_status', true ) )
? (
(
!empty( CF7WPA()->lib->response_status )
&& array_key_exists( get_post_meta( $post_id , '_transaction_status', true ), CF7WPA()->lib->response_status)
)
? CF7WPA()->lib->response_status[get_post_meta( $post_id , '_transaction_status', true )]
: get_post_meta( $post_id , '_transaction_status', true )
)
: ''
);
}
break;
case 'total' :
if( $data_ct ){
echo 'To unlock more features consider upgrading to PRO';
}else{
echo ( !empty( get_post_meta( $post_id , '_total', true ) ) ? get_post_meta( $post_id , '_total', true ) : '' ) .' ' .
( !empty( get_post_meta( $post_id , '_currency', true ) ) ? get_post_meta( $post_id , '_currency', true ) : '' );
}
break;
}
}
/**
* Action: pre_get_posts
*
* - Used to perform order by into CPT List.
*
* @method action__pre_get_posts
*
* @param object $query WP_Query
*/
function action__pre_get_posts( $query ) {
if (
! is_admin()
|| !in_array ( $query->get( 'post_type' ), array( 'cf7wpa_data' ) )
)
return;
$orderby = $query->get( 'orderby' );
if ( '_transaction_status' == $orderby ) {
$query->set( 'meta_key', '_transaction_status' );
$query->set( 'orderby', 'meta_value_num' );
}
if ( '_form_id' == $orderby ) {
$query->set( 'meta_key', '_form_id' );
$query->set( 'orderby', 'meta_value_num' );
}
if ( '_total' == $orderby ) {
$query->set( 'meta_key', '_total' );
$query->set( 'orderby', 'meta_value_num' );
}
}
/**
* Action: restrict_manage_posts
*
* - Used to creat filter by form and export functionality.
*
* @method action__restrict_manage_posts
*
* @param string $post_type
*/
function action__restrict_manage_posts( $post_type ) {
if ( 'cf7wpa_data' != $post_type ) {
return;
}
$posts = get_posts(
array(
'post_type' => 'wpcf7_contact_form',
'post_status' => 'publish',
'suppress_filters' => false,
'posts_per_page' => -1
)
);
if ( empty( $posts ) ) {
return;
}
$selected = ( isset( $_GET['form-id'] ) ? sanitize_text_field($_GET['form-id']) : '' );
echo '';
echo '';
}
/**
* Action: parse_query
*
* - Filter data by form id.
*
* @method action__parse_query
*
* @param object $query WP_Query
*/
function action__parse_query( $query ) {
if (
! is_admin()
|| !in_array ( $query->get( 'post_type' ), array( 'cf7wpa_data' ) )
)
return;
if (
is_admin()
&& isset( $_GET['form-id'] )
&& 'all' != $_GET['form-id']
) {
$query->query_vars['meta_key'] = '_form_id';
$query->query_vars['meta_value'] = sanitize_text_field($_GET['form-id']);
$query->query_vars['meta_compare'] = '=';
}
}
/**
* Action: admin_notices
*
* - Added use notice when trying to export without selecting the form.
*
* @method action__cf7wp_admin_notices_export
*/
function action__cf7wp_admin_notices_export() {
echo '
' .
'
' .
__( 'Please select Form to export.', 'contact-form-7-worldpay-addon' ) .
'
' .
'
';
}
/**
* Action: CF7WPA_PREFIX /postbox
*
* - Added metabox for the setting fields in backend.
*
* @method action__acf7wpa_postbox
*/
function action__acf7wpa_postbox() {
echo '' .
apply_filters(
CF7WPA_PREFIX . '/help/postbox',
'
' . __( 'Do you need help for configuration?', 'contact-form-7-worldpay-addon' ) . '
' .
'
' .
'
' .
'- Refer the document.
' .
'- Contact Us
' .
'- Support
' .
'
'
) .
'
';
}
/*
######## ## ## ## ## ###### ######## #### ####### ## ## ######
## ## ## ### ## ## ## ## ## ## ## ### ## ## ##
## ## ## #### ## ## ## ## ## ## #### ## ##
###### ## ## ## ## ## ## ## ## ## ## ## ## ## ######
## ## ## ## #### ## ## ## ## ## ## #### ##
## ## ## ## ### ## ## ## ## ## ## ## ### ## ##
## ####### ## ## ###### ## #### ####### ## ## ######
*/
/**
* - Used to display the form data in CPT detail page.
*
* @method cfwpa_show_from_data
*
* @param object $post WP_Post
*/
function cfwpa_show_from_data( $post ) {
$fields = CF7WPA()->lib->data_fields;
$form_id = get_post_meta( $post->ID, '_form_id', true );
$data_ct = $this->cfwpa_check_data_ct( $post->ID );
if( $data_ct ) {
echo '';
}else{
echo '';
}
}
/**
* - Used to add meta box in CPT detail page.
*/
function cfwpa_show_help_data() {
echo '';
}
function cfwpa_check_data_ct( $post_id ){
$data = get_post_meta( $post_id, '_form_data', true );
if( !empty( get_post_meta( $post_id, '_form_data', true ) ) && isset( $data['_exceed_num_cfwpa'] ) && !empty( $data['_exceed_num_cfwpa'] ) ){
return $data['_exceed_num_cfwpa'];
}else{
return '';
}
}
}
add_action( 'plugins_loaded' , function() {
CF7WPA()->admin->action = new CF7WPA_Admin_Action;
} );
}