| @@ -13,9 +13,9 @@ | ||
| 13 | 13 | */ |
| 14 | 14 | class FrmFormState { |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * @var FrmFormState | |
| 17 | + * @var FrmFormState|null | |
| 18 | 18 | */ |
| 19 | 19 | private static $instance; |
| 20 | 20 | |
| 21 | 21 | /** |
| @@ -46,9 +46,9 @@ | ||
| 46 | 46 | /** |
| 47 | 47 | * @return bool true if just initialized. |
| 48 | 48 | */ |
| 49 | 49 | private static function maybe_initialize() { |
| 50 | - if ( empty( self::$instance ) ) { | |
| 50 | + if ( ! self::$instance ) { | |
| 51 | 51 | self::$instance = new self(); |
| 52 | 52 | return true; |
| 53 | 53 | } |
| 54 | 54 | return false; |
| @@ -102,9 +102,9 @@ | ||
| 102 | 102 | // This way we can also avoid duplicate state fields if Pro isn't up to date. |
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - if ( empty( self::$instance ) && ! self::get_state_from_request() ) { | |
| 106 | + if ( ! self::$instance && ! self::get_state_from_request() ) { | |
| 107 | 107 | return; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | $honeypot_field_id = self::$instance->get( 'honeypot_field_id', 0 ); |
| @@ -152,8 +152,9 @@ | ||
| 152 | 152 | |
| 153 | 153 | foreach ( $decoded_state as $key => $value ) { |
| 154 | 154 | self::set_initial_value( self::decompressed_key( $key ), $value ); |
| 155 | 155 | } |
| 156 | + | |
| 156 | 157 | return true; |
| 157 | 158 | } |
| 158 | 159 | |
| 159 | 160 | /** |
| @@ -167,10 +168,9 @@ | ||
| 167 | 168 | if ( ! $this->state && ! self::get_state_from_request() ) { |
| 168 | 169 | return; |
| 169 | 170 | } |
| 170 | 171 | |
| 171 | - $state_string = $this->get_state_string(); | |
| 172 | - echo '<input name="frm_state" type="hidden" value="' . esc_attr( $state_string ) . '" />'; | |
| 172 | + echo '<input name="frm_state" type="hidden" value="' . esc_attr( $this->get_state_string() ) . '" />'; | |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
| 176 | 176 | * @return string |
| @@ -179,13 +179,11 @@ | ||
| 179 | 179 | if ( ! self::open_ssl_is_installed() ) { |
| 180 | 180 | return ''; |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - $secret = self::get_encryption_secret(); | |
| 184 | - $compressed_state = $this->compressed_state(); | |
| 185 | - $json_encoded = json_encode( $compressed_state ); | |
| 186 | - $encrypted = openssl_encrypt( $json_encoded, 'AES-128-ECB', $secret ); | |
| 187 | - return $encrypted; | |
| 183 | + $secret = self::get_encryption_secret(); | |
| 184 | + $json_encoded = json_encode( $this->compressed_state() ); | |
| 185 | + return openssl_encrypt( $json_encoded, 'AES-128-ECB', $secret ); | |
| 188 | 186 | } |
| 189 | 187 | |
| 190 | 188 | /** |
| 191 | 189 | * Returns true if open SSL is installed. |
| @@ -208,8 +206,9 @@ | ||
| 208 | 206 | |
| 209 | 207 | foreach ( $this->state as $key => $value ) { |
| 210 | 208 | $compressed[ self::compressed_key( $key ) ] = $value; |
| 211 | 209 | } |
| 210 | + | |
| 212 | 211 | return $compressed; |
| 213 | 212 | } |
| 214 | 213 | |
| 215 | 214 | /** |
| @@ -258,9 +257,9 @@ | ||
| 258 | 257 | } |
| 259 | 258 | |
| 260 | 259 | // We don't have a secret, so let's generate one. |
| 261 | 260 | $secret_key = is_callable( 'sodium_crypto_secretbox_keygen' ) ? sodium_crypto_secretbox_keygen() : wp_generate_password( 32, true, true ); |
| 262 | - update_option( 'frm_form_state_key', base64_encode( $secret_key ), 'no' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode | |
| 261 | + update_option( 'frm_form_state_key', base64_encode( $secret_key ), false ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode | |
| 263 | 262 | |
| 264 | 263 | return $secret_key; |
| 265 | 264 | } |
| 266 | 265 | } |