/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/Import.php (7881B)
importers = ( new Importers() )->get_importers();
}
/**
* Get view label.
*
* @since 1.6.6
*
* @return string
*/
public function get_label() {
return esc_html__( 'Import', 'wpforms-lite' );
}
/**
* Import process.
*
* @since 1.6.6
*/
public function import_process() {
if (
empty( $_POST['action'] ) || //phpcs:ignore WordPress.Security.NonceVerification
$_POST['action'] !== 'import_form' || //phpcs:ignore WordPress.Security.NonceVerification
empty( $_FILES['file']['tmp_name'] ) ||
! isset( $_POST['submit-import'] ) || //phpcs:ignore WordPress.Security.NonceVerification
! $this->verify_nonce()
) {
return;
}
$this->process();
}
/**
* Import view content.
*
* @since 1.6.6
*/
public function display() {
$this->success_import_message();
$this->wpforms_block();
$this->other_forms_block();
}
/**
* Success import message.
*
* @since 1.6.6
*/
private function success_import_message() {
if ( isset( $_GET['wpforms_notice'] ) && $_GET['wpforms_notice'] === 'forms-imported' ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
?>
check your forms.', 'wpforms-lite' ),
[ 'a' => [ 'href' => [] ] ]
),
esc_url( admin_url( 'admin.php?page=wpforms-overview' ) )
);
}
?>
400,
]
);
}
$tmp_name = isset( $_FILES['file']['tmp_name'] ) ? sanitize_text_field( $_FILES['file']['tmp_name'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- wp_unslash() breaks upload on Windows.
$forms = json_decode( File::remove_utf8_bom( file_get_contents( $tmp_name ) ), true );
if ( empty( $forms ) || ! is_array( $forms ) ) {
wp_die(
esc_html__( 'Form data cannot be imported.', 'wpforms-lite' ),
esc_html__( 'Error', 'wpforms-lite' ),
[
'response' => 400,
]
);
}
foreach ( $forms as $form ) {
$title = ! empty( $form['settings']['form_title'] ) ? $form['settings']['form_title'] : '';
$desc = ! empty( $form['settings']['form_desc'] ) ? $form['settings']['form_desc'] : '';
$new_id = wp_insert_post(
[
'post_title' => $title,
'post_status' => 'publish',
'post_type' => 'wpforms',
'post_excerpt' => $desc,
]
);
if ( $new_id ) {
$form['id'] = $new_id;
wp_update_post(
[
'ID' => $new_id,
'post_content' => wpforms_encode( $form ),
]
);
}
if ( ! empty( $form['settings']['form_tags'] ) ) {
wp_set_post_terms(
$new_id,
implode( ',', (array) $form['settings']['form_tags'] ),
WPForms_Form_Handler::TAGS_TAXONOMY
);
}
}
wp_safe_redirect( add_query_arg( [ 'wpforms_notice' => 'forms-imported' ] ) );
exit;
}
}