PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.14.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.14.0
2.14.0 2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 81 releases
← All changes | includes/blocks/form-builder/actions/save-form-data.php +78 -2 2.9.1 → 2.14.0 View file →
@@ -51,20 +51,26 @@
51 51 $settings = $this->validateformdata->form_info['info']['config']['submissionMetaData'] ?? [];
52 52
53 53 $ip = '';
54 54 if ( in_array( 'userIp', $settings, true ) ) {
55 - $ip = sanitize_text_field(
55 + $ip = wp_unslash(
56 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
56 57 $_SERVER['HTTP_CF_CONNECTING_IP'] ??
58 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
57 59 $_SERVER['HTTP_CLIENT_IP'] ??
60 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
58 61 $_SERVER['HTTP_X_FORWARDED_FOR'] ??
62 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
59 63 $_SERVER['REMOTE_ADDR'] ?? ''
60 64 );
65 + $ip = sanitize_text_field( $ip );
61 66 }
62 67
63 68 $user_agents = '';
64 69 if ( in_array( 'userAgent', $settings, true ) ) {
65 70 $user_agents = sanitize_text_field(
66 - $_SERVER['HTTP_USER_AGENT'] ?? ''
71 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
72 + wp_unslash( $_SERVER['HTTP_USER_AGENT'] ?? '' )
67 73 );
68 74 }
69 75
70 76 // insert data to entry
@@ -81,9 +87,79 @@
81 87
82 88 if ( $id ) {
83 89 $this->validateformdata->state_data['submission_id'] = $id;
84 90 $this->validateformdata->set_message( __( 'Success!', 'ablocks' ) );
91 +
92 + if (
93 + 'subscription' === $this->validateformdata->form_info['info']['type'] &&
94 + isset($this->validateformdata->form_info['info']['config']['subscriberToUser']) &&
95 + (bool) $this->validateformdata->form_info['info']['config']['subscriberToUser'] === true
96 + ) {
97 + $this->create_user(
98 + $this->validateformdata->form_info['data']
99 + );
100 + }
85 101 return;
86 102 }
87 103 $this->validateformdata->set_error_message( __( 'Failed to save data', 'ablocks' ) );
88 104 }
105 +
106 + function create_user( array $data ) : ?int {
107 + if ( ! isset( $data['email']['value'] ) || ! is_email( $data['email']['value'] ) ) {
108 + return null;
109 + }
110 + if ( email_exists( $data['email']['value'] ) ) {
111 + return null;
112 + }
113 +
114 + $username = sanitize_user( $data['email']['value'] );
115 +
116 + $user_data = [
117 + 'user_login' => $username,
118 + 'user_email' => $data['email']['value'],
119 + 'user_pass' => isset( $data['password']['value'] ) ? $data['password']['value'] : wp_generate_password(),
120 + 'role' => 'subscriber',
121 + ];
122 +
123 + if ( isset( $data['first_name']['value'] ) ) {
124 + $user_data['first_name'] = sanitize_text_field( $data['first_name']['value'] );
125 + }
126 +
127 + if ( isset( $data['last_name']['value'] ) ) {
128 + $user_data['last_name'] = sanitize_text_field( $data['last_name']['value'] );
129 + }
130 +
131 + $user_id = wp_insert_user( $user_data );
132 +
133 + if ( is_wp_error( $user_id ) ) {
134 + return null;
135 + }
136 +
137 + $user = get_user_by( 'id', $user_id );
138 + $password = $user_data['user_pass'];
139 +
140 + $subject = 'Your New Account Credentials';
141 + $message = sprintf( 'Hello %s,
142 +
143 + Your account has been created successfully. Below are your login details:
144 +
145 + Username: %s
146 + Password: %s
147 +
148 + You can log in to your account here: %s
149 +
150 + If you did not create this account, please contact us immediately.',
151 + $user->first_name ? $user->first_name : 'User',
152 + $user->user_login,
153 + $password,
154 + wp_login_url()
155 + );
156 +
157 + $headers = [
158 + 'Content-Type: text/html; charset=UTF-8',
159 + ];
160 +
161 + $mail_sent = wp_mail( $user->user_email, $subject, nl2br( $message ), $headers );
162 + return $user_id;
163 + }
164 +
89 165 }