From 9e27664045e6e7184afcd88e2cc1420eca75d90a Mon Sep 17 00:00:00 2001 From: Mikey Arce Date: Mon, 11 Dec 2023 11:03:00 -0800 Subject: [PATCH] Save previous license upon deactivation (#2676) * Save previous license upon deactivation --- .../helper/class-wp-job-manager-helper-options.php | 12 ++++++++++++ includes/helper/class-wp-job-manager-helper.php | 1 + includes/helper/views/html-licenses.php | 5 +++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/includes/helper/class-wp-job-manager-helper-options.php b/includes/helper/class-wp-job-manager-helper-options.php index f03c92195..9b97f9dd7 100644 --- a/includes/helper/class-wp-job-manager-helper-options.php +++ b/includes/helper/class-wp-job-manager-helper-options.php @@ -84,6 +84,18 @@ public static function delete( $product_slug, $key ) { return self::update_license_option( $options ); } + /** + * Save the previous license key for a product. + * + * @param string $product_slug + * @param string $key + * + * @return void + */ + public static function set_previous_license_key( $product_slug, $key ) { + update_option( 'job_manager_previous_license_' . $product_slug, $key ); + } + /** * Attempt to retrieve license data from legacy storage. * diff --git a/includes/helper/class-wp-job-manager-helper.php b/includes/helper/class-wp-job-manager-helper.php index 643a1b4f8..e22bca4f8 100644 --- a/includes/helper/class-wp-job-manager-helper.php +++ b/includes/helper/class-wp-job-manager-helper.php @@ -934,6 +934,7 @@ private function deactivate_license( $product_slug, $silently = false ) { return; } + WP_Job_Manager_Helper_Options::set_previous_license_key( $product_slug, $license['license_key'] ); WP_Job_Manager_Helper_Options::delete( $product_slug, 'license_key' ); WP_Job_Manager_Helper_Options::delete( $product_slug, 'email' ); WP_Job_Manager_Helper_Options::delete( $product_slug, 'errors' ); diff --git a/includes/helper/views/html-licenses.php b/includes/helper/views/html-licenses.php index 1b6802ef6..641fa8485 100644 --- a/includes/helper/views/html-licenses.php +++ b/includes/helper/views/html-licenses.php @@ -159,14 +159,15 @@ } } if ( apply_filters( 'wpjm_display_license_form_for_addon', true, $product_slug ) ) { - $has_error = in_array( 'error', array_column( $notices, 'type' ), true ); + $has_error = in_array( 'error', array_column( $notices, 'type' ), true ); + $previous_license_key = get_option( 'job_manager_previous_license_' . $product_slug, null ) ?? ''; ?>
- +