Import JSON file

__( 'Select File', 'advanced-forms' ), 'type' => 'file', 'name' => 'af_import_json_file', 'value' => false, 'uploader' => 'basic', )); ?>
true ) ); } // Verify the nonce rendered on the import page. $nonce = isset( $_POST['af_import_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['af_import_nonce'] ) ) : ''; if ( ! wp_verify_nonce( $nonce, 'af_import_form' ) ) { wp_die( __( 'Form could not be imported due to a missing or invalid nonce.', 'advanced-forms' ), __( 'Error: Invalid nonce', 'advanced-forms' ), array( 'back_link' => true ) ); } if ( empty( $_FILES['af_import_json_file']['size'] ) ) { return acf_add_admin_notice( __( 'No files selected', 'advanced-forms' ) ); } $file = $_FILES['af_import_json_file']; $json = file_get_contents( $file['tmp_name'] ); $json = json_decode( $json, true ); // Bail if the uploaded file isn't a JSON object describing a form. if ( ! is_array( $json ) || empty( $json['key'] ) ) { return acf_add_admin_notice( __( 'The selected file is not a valid form export.', 'advanced-forms' ) ); } $post = af_import_form( $json ); if ( $post ) { /* translators: The ACF field key */ $message = sprintf( __( 'Form with key %s imported.', 'advanced-forms' ), $json['key'] ); $link = sprintf( '%s', get_edit_post_link( $post ), __( 'Edit form', 'advanced-forms' ) ); acf_add_admin_notice( $message . ' ' . $link, 'success' ); } else { acf_add_admin_notice( __( 'Failed to import form', 'advanced-forms' ) ); } } /** * Wordpress won't display a page title, probably because of the submenu hack in register_admin_page. * This function is hooked to the admin_title filter and fixes the issue. * * @since 1.6.5 * */ function fix_admin_title( $admin_title, $title ) { if ( get_current_screen()->id != 'admin_page_af_import_form' ) { return $admin_title; } return __( 'Import form', 'advanced-forms' ) . $admin_title; } } return new AF_Admin_Forms_Import();