| @@ -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; |
| @@ -144,8 +144,11 @@ | ||
| 144 | 144 | /** |
| 145 | 145 | * @return void |
| 146 | 146 | */ |
| 147 | 147 | public function render_state_field() { |
| 148 | + if ( ! self::open_ssl_is_installed() ) { | |
| 149 | + return; | |
| 150 | + } | |
| 148 | 151 | if ( ! $this->state && ! self::get_state_from_request() ) { |
| 149 | 152 | return; |
| 150 | 153 | } |
| 151 | 154 | $state_string = $this->get_state_string(); |
| @@ -155,8 +158,11 @@ | ||
| 155 | 158 | /** |
| 156 | 159 | * @return string |
| 157 | 160 | */ |
| 158 | 161 | private function get_state_string() { |
| 162 | + if ( ! self::open_ssl_is_installed() ) { | |
| 163 | + return ''; | |
| 164 | + } | |
| 159 | 165 | $secret = self::get_encryption_secret(); |
| 160 | 166 | $compressed_state = $this->compressed_state(); |
| 161 | 167 | $json_encoded = json_encode( $compressed_state ); |
| 162 | 168 | $encrypted = openssl_encrypt( $json_encoded, 'AES-128-ECB', $secret ); |
| @@ -163,8 +169,18 @@ | ||
| 163 | 169 | return $encrypted; |
| 164 | 170 | } |
| 165 | 171 | |
| 166 | 172 | /** |
| 173 | + * Returns true if open SSL is installed. | |
| 174 | + * | |
| 175 | + * @since 6.12 | |
| 176 | + * @return bool | |
| 177 | + */ | |
| 178 | + private static function open_ssl_is_installed() { | |
| 179 | + return function_exists( 'openssl_encrypt' ); | |
| 180 | + } | |
| 181 | + | |
| 182 | + /** | |
| 167 | 183 | * Return state but with shorter keys to use for the state string. |
| 168 | 184 | * |
| 169 | 185 | * @return array |
| 170 | 186 | */ |
| @@ -218,9 +234,9 @@ | ||
| 218 | 234 | } |
| 219 | 235 | |
| 220 | 236 | // We don't have a secret, so let's generate one. |
| 221 | 237 | $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 | |
| 238 | + update_option( 'frm_form_state_key', base64_encode( $secret_key ), 'no' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode | |
| 223 | 239 | |
| 224 | 240 | return $secret_key; |
| 225 | 241 | } |
| 226 | 242 | } |