Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save previous license upon deactivation #2676

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ) ? get_option( 'job_manager_previous_license_' . $product_slug ) : '';
mikeyarce marked this conversation as resolved.
Show resolved Hide resolved
?>
<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
Loading