/home/techb158/on-time-movers.com/wp-content/plugins/wpforms/src/Admin/Tools/Views
Edit: /home/techb158/on-time-movers.com/wp-content/plugins/wpforms/src/Admin/Tools/Views/Export.php (8834B)
verify_nonce()
) {
return;
}
if ( $_POST['action'] === 'export_form' && ! empty( $_POST['forms'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification
$this->process_form();
}
if ( $_POST['action'] === 'export_template' && ! empty( $_POST['form'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification
$this->process_template();
}
}
/**
* Checking user capability to view.
*
* @since 1.6.6
*
* @return bool
*/
public function check_capability() {
return wpforms_current_user_can( [ 'edit_forms', 'view_entries' ] );
}
/**
* Get available forms.
*
* @since 1.6.6
*
* @return array
*/
public function get_forms() {
$forms = wpforms()->form->get( '', [ 'orderby' => 'title' ] );
return ! empty( $forms ) ? $forms : [];
}
/**
* Export view content.
*
* @since 1.6.6
*/
public function display() {
$this->forms = $this->get_forms();
if ( empty( $this->forms ) ) {
echo wpforms_render( 'admin/empty-states/no-forms' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
return;
}
do_action( 'wpforms_admin_tools_export_top' );
$this->forms_export_block();
$this->form_template_export_block();
do_action( 'wpforms_admin_tools_export_bottom' );
}
/**
* Forms export block.
*
* @since 1.6.6
*/
private function forms_export_block() {
?>
'wpforms',
'nopaging' => true,
'post__in' => isset( $_POST['forms'] ) ? array_map( 'intval', $_POST['forms'] ) : [], //phpcs:ignore WordPress.Security.NonceVerification
]
);
foreach ( $forms as $form ) {
$export[] = wpforms_decode( $form->post_content );
}
ignore_user_abort( true );
wpforms_set_time_limit();
nocache_headers();
header( 'Content-Type: application/json; charset=utf-8' );
header( 'Content-Disposition: attachment; filename=wpforms-form-export-' . current_time( 'm-d-Y' ) . '.json' );
header( 'Expires: 0' );
echo wp_json_encode( $export );
exit;
}
/**
* Export template processing.
*
* @since 1.6.6
*/
private function process_template() {
$form_data = false;
if ( isset( $_POST['form'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification
$form_data = wpforms()->form->get(
absint( $_POST['form'] ), //phpcs:ignore WordPress.Security.NonceVerification
[ 'content_only' => true ]
);
}
if ( ! $form_data ) {
return;
}
// Define basic data.
$name = sanitize_text_field( $form_data['settings']['form_title'] );
$desc = sanitize_text_field( $form_data['settings']['form_desc'] );
$slug = sanitize_key( str_replace( [ ' ', '-' ], '_', $form_data['settings']['form_title'] ) );
$class = 'WPForms_Template_' . $slug;
// Format template field and settings data.
$data = $form_data;
$data['meta']['template'] = $slug;
$data['fields'] = isset( $data['fields'] ) ? wpforms_array_remove_empty_strings( $data['fields'] ) : [];
$data['settings'] = wpforms_array_remove_empty_strings( $data['settings'] );
unset( $data['id'] );
$data = var_export( $data, true ); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
$data = str_replace( ' ', "\t", $data );
$data = preg_replace( '/([\t\r\n]+?)array/', 'array', $data );
// Build the final template string.
$this->template = <<
name = '{$name}';
// Template slug
\$this->slug = '{$slug}';
// Template description
\$this->description = '{$desc}';
// Template field and settings
\$this->data = {$data};
}
}
new {$class}();
endif;
EOT;
}
}