Skip to content

Commit

Permalink
Save previous license upon deactivation (#2676)
Browse files Browse the repository at this point in the history
* Save previous license upon deactivation
  • Loading branch information
mikeyarce authored Dec 11, 2023
1 parent 02dfcda commit 9e27664
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
12 changes: 12 additions & 0 deletions includes/helper/class-wp-job-manager-helper-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions includes/helper/class-wp-job-manager-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
5 changes: 3 additions & 2 deletions includes/helper/views/html-licenses.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ?? '';
?>
<form method="post" class='plugin-license-form'>
<?php wp_nonce_field( 'wpjm-manage-license' ); ?>
<input type="hidden" id="<?php echo esc_attr( sanitize_title( $product_slug ) ); ?>_action" name="action" value="activate"/>
<input type="hidden" id="<?php echo esc_attr( sanitize_title( $product_slug ) ); ?>_plugin" name="product_slug" value="<?php echo esc_attr( $product_slug ); ?>"/>
<label for="<?php echo esc_attr( sanitize_title( $product_slug ) ); ?>_license_key" class="plugin-license-label"><?php esc_html_e( 'LICENSE', 'wp-job-manager' ); ?></label>
<input type="text" id="<?php echo esc_attr( sanitize_title( $product_slug ) ); ?>_license_key" class="plugin-license-field<?php echo $has_error ? ' plugin-license-field--error' : ''; ?>" name="license_key" placeholder="XXXX-XXXX-XXXX-XXXX"/>
<input type="text" id="<?php echo esc_attr( sanitize_title( $product_slug ) ); ?>_license_key" class="plugin-license-field<?php echo $has_error ? ' plugin-license-field--error' : ''; ?>" name="license_key" placeholder="XXXX-XXXX-XXXX-XXXX" value="<?php echo esc_attr( $previous_license_key ); ?>"/>
<input type="submit" class="button plugin-license-button" name="submit" value="<?php esc_attr_e( 'Activate License', 'wp-job-manager' ); ?>" />
</form>
<?php
Expand Down

0 comments on commit 9e27664

Please sign in to comment.