PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 3.1.13
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v3.1.13
3.1.13 3.1.12 3.1.11 3.1.10 3.1.9 3.1.8 3.1.7 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 All 122 releases
firebox / Inc / Core / Helpers / Form / Submission.php

Submission.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 3.1.13, at Inc/Core/Helpers/Form/Submission.php

154 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package FireBox
4 * @version 3.1.13 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2026 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\Helpers\Form;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 class Submission
20 {
21 /**
22 * Create submission.
23 *
24 * @param string $form_id
25 * @param int $state
26 * @param bool $save
27 *
28 * @return array
29 */
30 public static function create($form_id = null, $state = 1, $save = true)
31 {
32 if (!$form_id)
33 {
34 return;
35 }
36
37 $factory = new \FPFramework\Base\Factory();
38
39 $submission_payload = [
40 'form_id' => str_replace('form-', '', $form_id),
41 'visitor_id' => $factory->getVisitorID(),
42 'user_id' => get_current_user_id(),
43 'state' => $state,
44 'created_at' => gmdate('Y-m-d H:i:s'),
45 'modified_at' => null
46 ];
47
48 if ($save)
49 {
50 if (!$submission_id = firebox()->tables->submission->insert($submission_payload))
51 {
52 return;
53 }
54 }
55 else
56 {
57 $submission_id = 0;
58 }
59
60 return array_merge($submission_payload, [
61 'id' => $submission_id,
62 ]);
63 }
64
65 /**
66 * Updates the submission state.
67 *
68 * @param int $submission_id
69 * @param int $state
70 *
71 * @return bool
72 */
73 public static function updateState($submission_id = null, $state = null)
74 {
75 if (!$submission_id || !in_array($state, [0, 1], true))
76 {
77 return;
78 }
79
80 $data = [
81 'state' => $state
82 ];
83
84 $where = [
85 'id' => $submission_id
86 ];
87
88 return firebox()->tables->submission->update($data, $where);
89 }
90
91 /**
92 * Returns whether a submission exists.
93 *
94 * Deliberately does not go through get(), which reads with caching enabled — calling
95 * that before a write would cache the pre-write row and make the update look like it
96 * had not happened.
97 *
98 * @param int $id
99 *
100 * @return bool
101 */
102 public static function exists($id = null)
103 {
104 $id = (int) $id;
105
106 if ($id <= 0)
107 {
108 return false;
109 }
110
111 global $wpdb;
112
113 $table = firebox()->tables->submission->getFullTableName();
114
115 return (bool) $wpdb->get_var($wpdb->prepare(
116 "SELECT 1 FROM `{$table}` WHERE id = %d LIMIT 1",// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
117 $id
118 ));
119 }
120
121 /**
122 * Returns the submission details given its ID.
123 *
124 * @param int $id
125 *
126 * @return bool
127 */
128 public static function get($id = null)
129 {
130 if (!$id)
131 {
132 return;
133 }
134
135 $submission = firebox()->tables->submission->getResults([
136 'where' => [
137 'id = ' => "'" . sanitize_key($id) . "'"
138 ]
139 ], true);
140
141 if (!$submission)
142 {
143 return;
144 }
145
146 $submission = $submission[0];
147
148 $submission->form = Form::getFormByID($submission->form_id, true);
149
150 $submission->meta = SubmissionMeta::getMeta($id);
151
152 return $submission;
153 }
154 }