add_action(
'gform_export_page_export_forms_as_text',
function () {
if ( ! GFCommon::current_user_can_any( 'gravityforms_edit_forms' ) ) {
wp_die( 'You do not have permission to access this page' );
}
GFExport::page_header();
?>
label;
}
foreach ( $form['confirmations'] as $confirmation ) {
$forms_text_array[ $form_title ]['confirmations'][] = $confirmation['name'] . PHP_EOL . $confirmation['message'];
}
foreach ( $form['notifications'] as $notification ) {
$forms_text_array[ $form_title ]['notifications'][] = $notification['name'] . PHP_EOL . 'To: ' . $notification['toEmail'] . PHP_EOL . 'Event: ' . $notification['event'] .
PHP_EOL . 'Subject: ' . $notification['subject'] . PHP_EOL . 'Message: ' . $notification['message'] . PHP_EOL . 'Is Active: ' .
( isset( $notification['isActive'] ) ? 'false' : 'true' ) . PHP_EOL;
}
$steps = gravity_flow()->get_steps( $form['id'] );
foreach ( $steps as $step ) {
if ( $step->get_type() == 'notification' ) {
$forms_text_array[ $form_title ]['workflow_notifications'][] = 'Step name: ' . $step->__get( 'step_name' ) . PHP_EOL . 'Subject: ' . $step->__get( 'workflow_notification_subject' ) .
PHP_EOL . 'Message: ' . $step->__get( 'workflow_notification_message' ) . PHP_EOL;
}
}
}
$filename = 'gravityforms_export_as_text' . date( 'Y-m-d' ) . '.txt';
$filename = sanitize_file_name( $filename );
header( 'Content-Description: File Transfer' );
header( "Content-Disposition: attachment; filename=$filename" );
header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ), true );
$forms_text = '';
foreach ( $forms_text_array as $form_name => $form ) {
$forms_text .= $form_name . PHP_EOL;
$index = 1;
foreach ( $form as $name => $form_data ) {
$forms_text .= $name . PHP_EOL;// . implode( PHP_EOL, $form_data ) . PHP_EOL;
foreach ( $form_data as $index => $data_piece ) {
$forms_text .= ( $index + 1 ) . ": $data_piece" . PHP_EOL;
}
$forms_text .= PHP_EOL;
}
$forms_text .= PHP_EOL . PHP_EOL;
}
echo $forms_text;
die();
}
add_action(
'gform_loaded',
function () {
if ( isset( $_POST['export_forms_as_text'] ) ) {
check_admin_referer( 'gf_export_forms_as_text', 'gf_export_forms_as_text_nonce' );
$selected_forms = rgpost( 'gf_form_id' );
if ( empty( $selected_forms ) ) {
GFCommon::add_error_message( __( 'Please select the forms to be exported', 'gravityforms' ) );
return;
}
export_forms_as_text( $selected_forms );
}
}
);
add_filter(
'gform_export_menu',
function ( $setting_tabs ) {
if ( GFCommon::current_user_can_any( 'gravityforms_edit_forms' ) ) {
$icon = 'export forms as text ';
$setting_tabs['40'] = array(
'name' => 'export_forms_as_text',
'label' => __( 'Export Forms As Text', 'gravityforms' ),
'icon' => $icon,
);
}
return $setting_tabs;
}
);