HEX
Server: Apache
System: Linux efa57bbe-abb1-400d-2985-3b056fbc2701.secureserver.net 6.1.147-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jul 24 12:33:32 EDT 2025 x86_64
User: root (0)
PHP: 8.0.30.4
Disabled: NONE
Upload Files
File: /var/www/wp-content/plugins/ocean-extra/includes/panel/classes/importers/class-wpforms-importer.php
<?php
/**
 * Class for the WPForms importer.
 *
 * Thank you very much to SiteGround for the code.
 */

if ( ! class_exists( 'WPForms' ) ) {
	return;
}

class OWP_WPForms_Importer {

	/**
	 * Process import file - this parses the widget data and returns it.
	 *
	 * @param string $file path to json file.
	 * @global string $widget_import_results
	 */
	public function process_import_file( $file ) {

		// Get file contents.
		$data = OWP_Demos_Helpers::get_remote( $file );

		// Return from this function if there was an error.
		if ( is_wp_error( $data ) ) {
			return $data;
		}

		// Decode file contents.
		$data = json_decode( $data, true );

		// Import the widget data
		return $this->import_json( $data );

	}

	public function import_json( $forms ) {

		if ( ! function_exists( 'wpforms' ) ) {
			return;
		}

		foreach ( $forms as $form ) {

			// Create empty form so we have an ID to work with.
			$form_id = wp_insert_post(
				array(
					'post_status' => 'publish',
					'post_type'   => 'wpforms',
				)
			);

			// Bail if post creation has failed.
			if ( empty( $form_id )
				|| is_wp_error( $form_id ) ) {
				continue;
			}

			$form['id'] = $form_id;

			// Update the form with all our compiled data.
			wpforms()->form->update( $form['id'], $form );
		}
	}
}