diff --git a/src/Admin/Settings.php b/src/Admin/Settings.php index 6b2d24da..c552d033 100644 --- a/src/Admin/Settings.php +++ b/src/Admin/Settings.php @@ -87,6 +87,14 @@ public function get_settings( $tab ) { 'default' => 'no', 'type' => 'checkbox', ], + [ + 'title' => __( 'Disable encryption', 'wc-serial-numbers' ), + 'id' => 'wc_serial_numbers_disable_encryption', + 'desc' => __( 'Store serial keys in database as plaintext.', 'wc-serial-numbers' ), + 'desc_tip' => __( 'If this options is enabled, keys will not be stored in encrypted form.', 'wc-serial-numbers' ), + 'default' => 'no', + 'type' => 'checkbox', + ], [ 'type' => 'sectionend', 'id' => 'section_serial_numbers', diff --git a/src/Encryption.php b/src/Encryption.php index 5478fa65..00174c1a 100644 --- a/src/Encryption.php +++ b/src/Encryption.php @@ -65,11 +65,11 @@ public function __construct() { * @return false|string */ public static function maybeEncrypt( $key ) { - if ( ! self::isEncrypted( $key ) ) { - return self::encrypt( $key ); + if(self::isEncrypted( $key ) || 'yes' == wc_serial_numbers_encryption_disabled()) { + return $key; } - return $key; + return self::encrypt( $key ); } /** diff --git a/src/Installer.php b/src/Installer.php index cb015d18..195d0e87 100644 --- a/src/Installer.php +++ b/src/Installer.php @@ -279,6 +279,7 @@ protected function update_120() { $options = [ 'wc_serial_numbers_autocomplete_order' => $this->update_1_2_0_get_option( 'wsn_auto_complete_order', 'yes', 'wsn_delivery_settings' ), 'wc_serial_numbers_reuse_serial_number' => $this->update_1_2_0_get_option( 'wsn_re_use_serial', 'no', 'wsn_delivery_settings' ), + 'wc_serial_numbers_disable_encryption' => 'no', 'wc_serial_numbers_disable_software_support' => 'no', 'wc_serial_numbers_manual_delivery' => 'no', 'wc_serial_numbers_hide_serial_number' => 'yes', diff --git a/src/functions.php b/src/functions.php index d3ffa602..95409e0c 100644 --- a/src/functions.php +++ b/src/functions.php @@ -867,6 +867,18 @@ function wcsn_decrypt_key( $key ) { return Encryption::maybeDecrypt( $key ); } +/** + * Check if encryption is disabled (i.e, for real physical product serial numbers) + * + * @param $product_id + * + * @return bool + * @since 1.x.x + */ +function wc_serial_numbers_encryption_disabled() { + return 'yes' == get_option( 'wc_serial_numbers_disable_encryption' ); +} + /** * Get product stocks *