Skip to content

Commit 3280490

Browse files
committed
add activate_new_key() method
actors can activate a new key programmatically instead of relying on user action; useful for transparent upgrades
1 parent 726eb84 commit 3280490

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

wc-am-client.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,31 @@ public function validate_options( $input ) {
877877
return $options;
878878
}
879879

880+
/**
881+
* Allow other actors to activate a new key programmatically
882+
*
883+
* @param $api_key
884+
*
885+
* @return void
886+
* @since 2.9.2
887+
*/
888+
public function activate_new_key( $api_key ) {
889+
$result = $this->activate( [ 'api_key' => $api_key ] );
890+
if ( ! empty( $result ) ) {
891+
$result = json_decode( $result, true );
892+
if ( $result['success'] === true && $result['activated'] === true ) {
893+
update_option( 'wc_am_' . $this->product_id . '_activate_success', $result['message'] );
894+
update_option( $this->wc_am_activated_key, 'Activated' );
895+
update_option( $this->wc_am_deactivate_checkbox_key, 'off' );
896+
update_option( $this->data_key, [ "{$this->data_key}_api_key" => $api_key ] );
897+
} else {
898+
wc_get_logger()->error( print_r( $result, true ),
899+
array( 'source' => 'wc_product_sample' )
900+
);
901+
}
902+
}
903+
}
904+
880905
// Deactivates the API Key to allow key to be used on another blog
881906
public function wc_am_license_key_deactivation( $input ) {
882907
$activation_status = get_option( $this->wc_am_activated_key );

0 commit comments

Comments
 (0)