__( 'Google Sheets', 'contact-form-7' ),
'callback' => array( $this, 'cf7_editor_panel_google_sheet' )
);
}
return $panels;
}
/**
* Set Google sheet settings with contact form
* @since 1.0
*/
public function save_gs_settings( $post ) {
$default = array(
"sheet-name" => "",
"sheet-id" => "",
"sheet-tab-name" => "",
"tab-id" => ""
);
$sheet_data = isset( $_POST['cf7-gs'] ) ? $_POST['cf7-gs'] : $default;
update_post_meta( $post->id(), 'gs_settings', $sheet_data );
}
/**
* Function - To send contact form data to google spreadsheet
* @param object $form
* @since 1.0
*/
public function cf7_save_to_google_sheets( $form ) {
$submission = WPCF7_Submission::get_instance();
// get form data
$form_id = $form->id();
$form_data = get_post_meta( $form_id, 'gs_settings' );
$data = array();
// if contact form sheet name and tab name is not empty than send data to spreedsheet
if ( $submission && (! empty( $form_data[0]['sheet-name'] ) ) && (! empty( $form_data[0]['sheet-tab-name'] ) ) ) {
$posted_data = $submission->get_posted_data();
// make sure the form ID matches the setting otherwise don't do anything
try {
include_once( GS_CONNECTOR_ROOT . "/lib/google-sheets.php" );
$doc = new cf7gsc_googlesheet();
$doc->auth();
$doc->setSpreadsheetId( $form_data[0]['sheet-id'] );
$doc->setWorkTabId( $form_data[0]['tab-id'] );
// Special Mail Tags
$meta = array();
$special_mail_tags = array( 'serial_number', 'remote_ip', 'user_agent', 'url', 'date', 'time', 'post_id', 'post_name', 'post_title', 'post_url', 'post_author', 'post_author_email', 'site_title', 'site_description', 'site_url', 'site_admin_email', 'user_login', 'user_email', 'user_url', 'user_first_name', 'user_last_name', 'user_nickname', 'user_display_name' );
foreach ( $special_mail_tags as $smt ) {
$meta[$smt] = apply_filters( 'wpcf7_special_mail_tags', '', sprintf( '_%s', $smt ), '', false );
}
if ( ! empty( $meta ) ) {
$data["date"] = $meta["date"];
$data["time"] = $meta["time"];
$data["serial-number"] = $meta["serial_number"];
$data["remote-ip"] = $meta["remote_ip"];
$data["user-agent"] = $meta["user_agent"];
$data["url"] = $meta["url"];
$data["post-id"] = $meta["post_id"];
$data["post-name"] = $meta["post_name"];
$data["post-title"] = $meta["post_title"];
$data["post-url"] = $meta["post_url"];
$data["post-author"] = $meta["post_author"];
$data["post-author-email"] = $meta["post_author_email"];
$data["site-title"] = $meta["site_title"];
$data["site-description"] = $meta["site_description"];
$data["site-url"] = $meta["site_url"];
$data["site-admin-email"] = $meta["site_admin_email"];
$data["user-login"] = $meta["user_login"];
$data["user-email"] = $meta["user_email"];
$data["user-url"] = $meta["user_url"];
$data["user-first-name"] = $meta["user_first_name"];
$data["user-last-name"] = $meta["user_last_name"];
$data["user-nickname"] = $meta["user_nickname"];
$data["user-display-name"] = $meta["user_display_name"];
}
foreach ( $posted_data as $key => $value ) {
// exclude the default wpcf7 fields in object
if ( strpos( $key, '_wpcf7' ) !== false || strpos( $key, '_wpnonce' ) !== false ) {
// do nothing
} else {
// handle strings and array elements
if ( is_array( $value ) ) {
$data[$key] = implode( ', ', $value );
} else {
$data[$key] = stripcslashes( $value );
}
}
}
$doc->add_row( $data );
} catch ( Exception $e ) {
$data['ERROR_MSG'] = $e->getMessage();
$data['TRACE_STK'] = $e->getTraceAsString();
Gs_Connector_Utility::gs_debug_log( $data );
}
}
}
/*
* Google sheet settings page
* @since 1.0
*/
public function cf7_editor_panel_google_sheet( $post ) {
$form_id = sanitize_text_field( $_GET['post'] );
$form_data = get_post_meta( $form_id, 'gs_settings' );
?>
get_results("SELECT ID, post_title, meta_value from ".$wpdb->prefix."posts as p JOIN ".$wpdb->prefix."postmeta as pm on p.ID = pm.post_id where pm.meta_key='gs_settings' AND p.post_type='wpcf7_contact_form' ORDER BY p.ID");
return $query;
}
/**
* Function - display contact form fields to be mapped to google sheet
* @param int $form_id
* @since 1.0
*/
public function display_form_fields( $form_id ) { ?>
get_contact_form_fields( $meta );
if( $fields ) {
foreach ( $fields as $field ) {
$single = $this->get_field_assoc( $field );
if ( $single ) {
$assoc_arr[] = $single;
}
}
}
if( ! empty( $assoc_arr ) ) {
?>
';
$upgrade_text .= 'CF7 Google Sheet Connector ';
$upgrade_text .= 'version 4.0 would required you to reauthenticate with your Google Account again due to update of Google API V3 to V4.
';
$upgrade_text .= 'To avoid any loss of data redo the Google Sheet settings of each Contact Forms again with required sheet and tab details.';
$upgrade_text .= '