PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.5.2
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.5.2
3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / includes / class-evf-background-process-import-entries.php
everest-forms / includes Last commit date
Helpers 1 year ago Integrations 3 weeks ago RestApi 1 week ago abilities 4 weeks ago abstracts 1 week ago admin 1 week ago blocks 1 year ago elementor 2 years ago export 2 months ago fields 4 weeks ago interfaces 8 years ago libraries 2 years ago log-handlers 1 year ago shortcodes 4 weeks ago stats 5 months ago templates 3 months ago traits 4 weeks ago class-everest-forms.php 1 week ago class-evf-addon-upsell.php 4 weeks ago class-evf-ajax.php 4 weeks ago class-evf-autoloader.php 8 years ago class-evf-background-process-import-entries.php 2 years ago class-evf-background-updater.php 8 years ago class-evf-cache-helper.php 2 months ago class-evf-cron.php 2 years ago class-evf-deprecated-action-hooks.php 6 years ago class-evf-deprecated-filter-hooks.php 5 years ago class-evf-email-entries-report.php 3 months ago class-evf-emails.php 4 weeks ago class-evf-fields.php 4 weeks ago class-evf-form-handler.php 4 weeks ago class-evf-form-task.php 4 weeks ago class-evf-forms-features.php 4 weeks ago class-evf-frontend-scripts.php 4 weeks ago class-evf-install.php 2 months ago class-evf-integrations.php 3 months ago class-evf-log-levels.php 8 years ago class-evf-logger.php 5 years ago class-evf-post-types.php 1 year ago class-evf-privacy.php 6 years ago class-evf-report-cron.php 2 months ago class-evf-reporting.php 2 months ago class-evf-session-handler.php 7 years ago class-evf-shortcodes.php 1 year ago class-evf-smart-tags.php 9 months ago class-evf-template-loader.php 1 year ago class-evf-validation.php 6 years ago evf-conditional-functions.php 6 years ago evf-core-functions.php 4 weeks ago evf-deprecated-functions.php 6 years ago evf-entry-functions.php 4 months ago evf-formatting-functions.php 4 years ago evf-notice-functions.php 4 years ago evf-template-functions.php 4 years ago evf-template-hooks.php 8 years ago evf-update-functions.php 5 years ago
class-evf-background-process-import-entries.php
168 lines
1 <?php
2 /**
3 * EVF_Background_Process_Import_Entries
4 *
5 * @package EverestForms\Classes
6 * @since 3.0.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 if ( ! class_exists( 'WP_Async_Request', false ) ) {
12 include_once dirname( EVF_PLUGIN_FILE ) . '/includes/libraries/wp-async-request.php';
13 }
14
15 if ( ! class_exists( 'WP_Background_Process', false ) ) {
16 include_once dirname( EVF_PLUGIN_FILE ) . '/includes/libraries/wp-background-process.php';
17 }
18
19 /**
20 * EVF_Background_Process_Import_Entries Class.
21 */
22 class EVF_Background_Process_Import_Entries extends WP_Background_Process {
23
24 /**
25 * Action Name.
26 *
27 * @var string
28 */
29 protected $action = 'evf_import_entries';
30
31 /**
32 * Perform task with queued item.
33 *
34 * Override this method to perform any actions required on each
35 * queue item. Return the modified item for further processing
36 * in the next pass through. Or, return false to remove the
37 * item from the queue.
38 *
39 * @since 3.0.0
40 *
41 * @param mixed $item Queue item to iterate over.
42 */
43 protected function task( $item ) {
44 // Actions to perform.
45 self::import_entry_to_form( $item );
46 return false;
47 }
48
49 /**
50 * Schedule fallback event.
51 *
52 * @since 3.0.0
53 */
54 protected function schedule_event() {
55 if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) {
56 wp_schedule_event( time() + 10, $this->cron_interval_identifier, $this->cron_hook_identifier );
57 }
58 }
59
60 /**
61 * Is the updater running?
62 *
63 * @since 3.0.0
64 */
65 public function is_updating() {
66 return false === $this->is_queue_empty();
67 }
68
69
70 /**
71 * Imports an entry to a form.
72 *
73 * This function imports an entry to a form based on the provided data. It retrieves the mapping data and CSV column titles from the options. It then retrieves the form fields using the form ID from the mapping data. The function iterates over the mapping data and checks if the field ID exists in the form fields. If it does, it retrieves the corresponding CSV column title and sanitizes the data from the provided data array. The sanitized data is stored in the entry data array. If the entry data array is not empty, the function creates an entry array with the necessary data and saves it using the save_entry method.
74 *
75 * @since 3.0.0
76 *
77 * @param array $data The data to import the entry from.
78 */
79 public static function import_entry_to_form( $data ) {
80 $map_fields_array = get_option( 'everest_forms_mapping_fields_array', array() );
81 $csv_column_title = get_option( 'everest_forms_csv_titles', array() );
82 $evf_fields = ! empty( $map_fields_array ) ? evf_get_form_fields( $map_fields_array['form_id'] ) : array();
83 $entry_data = array();
84 $entry = array();
85
86 if ( empty( $evf_fields ) ) {
87 return;
88 }
89
90 foreach ( $map_fields_array as $value ) {
91 if ( is_array( $value ) ) {
92 if ( isset( $evf_fields[ $value['field_id'] ] ) ) {
93 $key = array_search( trim( str_replace( '"', '', $value['map_csv_column'] ) ), $csv_column_title, true );
94 $entry_data[ $value['field_id'] ] = array(
95 'id' => sanitize_text_field( wp_unslash( $value['field_id'] ) ),
96 'type' => sanitize_text_field( wp_unslash( $evf_fields[ $value['field_id'] ]['type'] ) ),
97 'meta_key' => $evf_fields[ $value['field_id'] ]['meta-key'],
98 'value' => sanitize_text_field( wp_unslash( $data[ $key ] ) ),
99 'name' => sanitize_text_field( wp_unslash( $evf_fields[ $value['field_id'] ]['label'] ) ),
100 );
101 }
102 }
103 }
104
105 if ( ! empty( $entry_data ) ) {
106 $entry['user_id'] = get_current_user_id();
107 $entry['user_device'] = '';
108 $entry['user_ip_address'] = '';
109 $entry['form_id'] = $map_fields_array['form_id'];
110 $entry['referer'] = '';
111 $entry['fields'] = wp_json_encode( $entry_data );
112 $entry['status'] = 'publish';
113 $entry['viewed'] = 0;
114 $entry['starred'] = 0;
115 $entry['date_created'] = gmdate( 'Y-m-d H:i:s' );
116 self::save_entry( $entry, $entry_data );
117 }
118 }
119
120 /**
121 * Save an entry to the database.
122 *
123 * This function saves an entry to the database by inserting the entry data into the 'evf_entries' table.
124 * It also inserts the entry meta data into the 'evf_entrymeta' table.
125 *
126 * @since 3.0.0
127 *
128 * @param array $entry The entry data to be saved.
129 * @param array $entry_data The entry meta data to be saved.
130 */
131 public static function save_entry( $entry, $entry_data ) {
132 global $wpdb;
133
134 $result = $wpdb->insert( $wpdb->prefix . 'evf_entries', $entry );
135
136 if ( is_wp_error( $result ) || ! $result ) {
137 return false;
138 }
139
140 $entry_id = $wpdb->insert_id;
141
142 if ( ! empty( $entry_id ) ) {
143 $entry_meta = array();
144 foreach ( $entry_data as $key => $data ) {
145 $entry_meta = array(
146 'entry_id' => $entry_id,
147 'meta_key' => $data['meta_key'],
148 'meta_value' => maybe_serialize( $data['value'] ),
149 );
150 $wpdb->insert( $wpdb->prefix . 'evf_entrymeta', $entry_meta );
151 }
152 }
153 }
154
155
156 /**
157 * Complete
158 *
159 * Override if applicable, but ensure that the below actions are
160 * performed, or, call parent::complete().
161 */
162 protected function complete() {
163 delete_option( 'everest_forms_mapping_fields_array' );
164 delete_option( 'everest_forms_csv_titles' );
165 parent::complete();
166 }
167 }
168