Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak - Select all forms option #1377

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 50 additions & 21 deletions includes/admin/class-evf-admin-import-export.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['everest-forms-export-nonce'] ) ), 'everest_forms_export_nonce' ) ) {
wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'everest-forms' ) );
}

$form_ids = isset( $_POST['form_ids'] ) ? wp_unslash( $_POST['form_ids'] ) : array(); //phpcs:ignore

// Return if form id is not set and current user doesnot have export capability.
Expand All @@ -43,31 +44,59 @@
$export_all_forms = array();
$file_name = 'evf-export-forms-' . current_time( 'Y-m-d_H:i:s' ) . '.json';

foreach ( $form_ids as $key => $form_id ) {
$form_id = absint( wp_unslash( $form_id ) );
$form_post = get_post( $form_id );
$export_data = array(
'form_post' => array(
'post_content' => $form_post->post_content,
'post_title' => $form_post->post_title,
'post_name' => $form_post->post_name,
'post_type' => $form_post->post_type,
'post_status' => $form_post->post_status,
),
);
// Export form styles if found.
$form_styles = get_option( 'everest_forms_styles', array() );
if ( ! empty( $form_styles[ $form_id ] ) ) {
$export_data['form_styles'] = wp_json_encode( $form_styles[ $form_id ] );
}
if ( isset( $form_ids[0] ) && 'select_all_forms' === $form_ids[0] ) {
$all_forms = evf_get_all_forms();

foreach ( $all_forms as $key => $form_id ) {
$form_id = absint( wp_unslash( $key ) );
$form_post = get_post( $key );
$export_data = array(
'form_post' => array(
'post_content' => $form_post->post_content,
'post_title' => $form_post->post_title,
'post_name' => $form_post->post_name,
'post_type' => $form_post->post_type,
'post_status' => $form_post->post_status,
),
);
// Export form styles if found.
$form_styles = get_option( 'everest_forms_styles', array() );
if ( ! empty( $form_styles[ $form_id ] ) ) {
$export_data['form_styles'] = wp_json_encode( $form_styles[ $form_id ] );
}

if ( ob_get_contents() ) {
ob_clean();
}

if ( ob_get_contents() ) {
ob_clean();
$export_all_forms[] = $export_data;
}
} else {
foreach ( $form_ids as $key => $form_id ) {
$form_id = absint( wp_unslash( $form_id ) );
$form_post = get_post( $form_id );
$export_data = array(
'form_post' => array(
'post_content' => $form_post->post_content,
'post_title' => $form_post->post_title,
'post_name' => $form_post->post_name,
'post_type' => $form_post->post_type,
'post_status' => $form_post->post_status,
),
);
// Export form styles if found.
$form_styles = get_option( 'everest_forms_styles', array() );
if ( ! empty( $form_styles[ $form_id ] ) ) {
$export_data['form_styles'] = wp_json_encode( $form_styles[ $form_id ] );
}

$export_all_forms[] = $export_data;
}
if ( ob_get_contents() ) {
ob_clean();
}

$export_all_forms[] = $export_data;
}
}
$forms['forms'] = $export_all_forms;

// Force download.
Expand All @@ -84,8 +113,8 @@
*/
public static function import_forms() {
// Check for $_FILES set or not.
if ( isset( $_FILES['jsonfile']['name'], $_FILES['jsonfile']['tmp_name'] ) ) {

Check failure on line 116 in includes/admin/class-evf-admin-import-export.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4 , WP Latest)

Processing form data without nonce verification.

Check failure on line 116 in includes/admin/class-evf-admin-import-export.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4 , WP Latest)

Processing form data without nonce verification.
$filename = sanitize_file_name( wp_unslash( $_FILES['jsonfile']['name'] ) );

Check failure on line 117 in includes/admin/class-evf-admin-import-export.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4 , WP Latest)

Processing form data without nonce verification.
$extension = pathinfo( $filename, PATHINFO_EXTENSION );

// Check for file format.
Expand Down
1 change: 1 addition & 0 deletions includes/admin/views/html-admin-page-export.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
$forms = evf_get_all_forms( true, false );
if ( ! empty( $forms ) ) {
echo '<select id="everest-forms-form-export" class="evf-enhanced-select" style="min-width: 350px;" name="form_ids[]" data-placeholder="' . esc_attr__( 'Select Form(s)', 'everest-forms' ) . '" multiple>';
echo '<option value="select_all_forms">' . esc_html__( 'Select all Forms', 'everest-forms' ) . '</option>';
foreach ( $forms as $id => $form ) { // phpcs:ignore WordPress.WP.GlobalVariablesOverride
echo '<option value="' . esc_attr( $id ) . '">' . esc_html( $form ) . '</option>';
}
Expand Down
Loading