PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.24
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.24
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmFormState.php +28 -8 6.46.24 View file →
@@ -13,9 +13,9 @@
13 13 */
14 14 class FrmFormState {
15 15
16 16 /**
17 - * @var FrmFormState $instance
17 + * @var FrmFormState
18 18 */
19 19 private static $instance;
20 20
21 21 /**
@@ -45,9 +45,9 @@
45 45 /**
46 46 * @return bool true if just initialized.
47 47 */
48 48 private static function maybe_initialize() {
49 - if ( ! isset( self::$instance ) ) {
49 + if ( empty( self::$instance ) ) {
50 50 self::$instance = new self();
51 51 return true;
52 52 }
53 53 return false;
@@ -95,14 +95,16 @@
95 95 // This way we can also avoid duplicate state fields if Pro isn't up to date.
96 96 return;
97 97 }
98 98
99 - if ( empty( $form->options['ajax_submit'] ) ) {
100 - // This is only required for AJAX submit.
99 + if ( empty( self::$instance ) && ! self::get_state_from_request() ) {
101 100 return;
102 101 }
103 102
104 - if ( empty( self::$instance ) && ! self::get_state_from_request() ) {
103 + $honeypot_field_id = self::$instance->get( 'honeypot_field_id', 0 );
104 +
105 + if ( empty( $form->options['ajax_submit'] ) && ! $honeypot_field_id ) {
106 + // This is only required for AJAX submit, or when the honeypot field is on the page.
105 107 return;
106 108 }
107 109
108 110 $state_title = ! empty( self::$instance->state['title'] ) ? 1 : 0;
@@ -109,10 +111,10 @@
109 111 $state_description = ! empty( self::$instance->state['description'] ) ? 1 : 0;
110 112 $settings_title = ! empty( $form->options['show_title'] ) ? 1 : 0;
111 113 $settings_description = ! empty( $form->options['show_description'] ) ? 1 : 0;
112 114
113 - if ( $state_title === $settings_title && $state_description === $settings_description ) {
114 - // Avoid state field if it matches form settings.
115 + if ( $state_title === $settings_title && $state_description === $settings_description && ! $honeypot_field_id ) {
116 + // Avoid state field if it matches form settings and there is no honeypot.
115 117 return;
116 118 }
117 119
118 120 self::$instance->render_state_field();
@@ -144,8 +146,11 @@
144 146 /**
145 147 * @return void
146 148 */
147 149 public function render_state_field() {
150 + if ( ! self::open_ssl_is_installed() ) {
151 + return;
152 + }
148 153 if ( ! $this->state && ! self::get_state_from_request() ) {
149 154 return;
150 155 }
151 156 $state_string = $this->get_state_string();
@@ -155,8 +160,11 @@
155 160 /**
156 161 * @return string
157 162 */
158 163 private function get_state_string() {
164 + if ( ! self::open_ssl_is_installed() ) {
165 + return '';
166 + }
159 167 $secret = self::get_encryption_secret();
160 168 $compressed_state = $this->compressed_state();
161 169 $json_encoded = json_encode( $compressed_state );
162 170 $encrypted = openssl_encrypt( $json_encoded, 'AES-128-ECB', $secret );
@@ -163,8 +171,18 @@
163 171 return $encrypted;
164 172 }
165 173
166 174 /**
175 + * Returns true if open SSL is installed.
176 + *
177 + * @since 6.12
178 + * @return bool
179 + */
180 + private static function open_ssl_is_installed() {
181 + return function_exists( 'openssl_encrypt' );
182 + }
183 +
184 + /**
167 185 * Return state but with shorter keys to use for the state string.
168 186 *
169 187 * @return array
170 188 */
@@ -201,8 +219,10 @@
201 219 case 'd':
202 220 return 'description';
203 221 case 't':
204 222 return 'title';
223 + case 'h':
224 + return 'honeypot_field_id';
205 225 }
206 226 return $key;
207 227 }
208 228
@@ -218,9 +238,9 @@
218 238 }
219 239
220 240 // We don't have a secret, so let's generate one.
221 241 $secret_key = is_callable( 'sodium_crypto_secretbox_keygen' ) ? sodium_crypto_secretbox_keygen() : wp_generate_password( 32, true, true );
222 - add_option( 'frm_form_state_key', base64_encode( $secret_key ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
242 + update_option( 'frm_form_state_key', base64_encode( $secret_key ), 'no' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
223 243
224 244 return $secret_key;
225 245 }
226 246 }