public function activate() {
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
$product_init = isset( $_REQUEST['product_init'] ) ? sanitize_text_field( $_REQUEST['product_init'] ) : '';
$product = $product_init ? $this->get_product( $product_init ) : false;
$body = false;
$activated = false;
if ( $product ) {
$args = array(
'email' => isset( $_REQUEST['email'] ) ? sanitize_email( $_REQUEST['email'] ) : '',
'licence_key' => isset( $_REQUEST['licence_key'] ) ? sanitize_text_field( $_REQUEST['licence_key'] ) : '',
'product_id' => isset( $product['product_id'] ) ? sanitize_text_field( $product['product_id'] ) : '',
'secret_key' => isset( $product['secret_key'] ) ? sanitize_text_field( $product['secret_key'] ) : '',
'instance' => $this->get_home_url(),
'request' => 'activation',
);
$response = $this->do_request( $this->get_api_uri( 'activation' ), $args );
if ( ! is_wp_error( $response ) ) {
$body = json_decode( $response['body'] );
$body = is_object( $body ) ? get_object_vars( $body ) : false;
}
if ( $body && is_array( $body ) && isset( $body['activated'] ) && $body['activated'] ) {
$license = array(
'email' => urldecode( $args['email'] ),
'licence_key' => $args['licence_key'],
'licence_expires' => $body['licence_expires'],
'message' => $body['message'],
'activated' => true,
'activation_limit' => $body['activation_limit'],
'activation_remaining' => $body['activation_remaining'],
'is_membership' => isset( $body['is_membership'] ) ? $body['is_membership'] : false,
'marketplace' => isset( $body['marketplace'] ) ? $body['marketplace'] : 'yith',
);
$option[ $product['product_id'] ] = $license;
$activated = true;
/* === Check for other plugins activation === */
$options = $this->get_licence();
$options[ $product['product_id'] ] = $option[ $product['product_id'] ];
update_option( $this->licence_option, $options );
/* === Update Plugin Licence Information === */
yith_plugin_fw_force_regenerate_plugin_update_transient();
$licenses = $this->get_licence();
$info = $licenses[ $product['product_id'] ];
$info['init'] = $product_init;
$info['licence'] = $license;
$info = array_merge( $info, $product );
/* === Licence Activation Template === */
$body['template'] = $this->show_activation_row( $info, true );
$body['code'] = 200;
$body['activation_message'] = $this->get_response_code_message( 200 );
}
if ( ! empty( $_REQUEST['debug'] ) ) {
$body = is_array( $body ) ? $body : array();
$body['debug'] = array( 'response' => $response );
if ( 'print_r' === $_REQUEST['debug'] ) {
$body['debug'] = print_r( $body['debug'], true );
}
}
do_action( "yith_{$this->product_type}_licence_check", $product_init, $activated, $this->product_type );
}
wp_send_json( $body );
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
}