Skip to content

Instantly share code, notes, and snippets.

@jan-koch
Created March 25, 2017 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jan-koch/1265a3ccbcf4d03a731aeec995d3d3c8 to your computer and use it in GitHub Desktop.
Save jan-koch/1265a3ccbcf4d03a731aeec995d3d3c8 to your computer and use it in GitHub Desktop.
function wpi_s2_cancellation_notification() {
if ( !empty( $_GET['yourauthenticationtoken']) && 'yes' === $_GET['yourauthenticationtoken'] ) {
// in the URL, I have '?yourauthenticationtoken=yes', that's what I'm looking for here.
// Only process requests for valid users
if ( !empty( $_GET['user_id'] ) ) {
$user_id = (integer) esc_attr( $_GET['user_id'] );
$user = new WP_User($user_id);
$email = $user->user_email;
// Load the Software License Manager table
// and grab the license key for the user
global $wpdb;
$license_table = $wpdb->prefix . 'lic_key_tbl';
$data = $wpdb->get_results(
$wpdb->prepare(
"SELECT license_key
FROM $license_table
WHERE email LIKE %s",
$email
)
);
// if a license was found
if ( !empty( $data) ) {
// I have set the plugin to allow only one license per user,
// so the license is always in the first element of the response.
// Adapt to your needs if necessary.
$license = $data[0]->license_key;
// Generate the request to deactivate the license key
$api_params = array(
'slm_action' => 'slm_deactivate',
'secret_key' => '58d24fd20c63f5.84017322',
'license_key' => $license
);
// Send query to license manager server
// to deactivate the license
$response = wp_remote_get(
add_query_arg(
$api_params,
'https://wp.immo'
),
array(
'timeout' => 20,
'ssl_verify' => false
)
);
// Check for error in the response
if (is_wp_error($response)){
echo "Unexpected Error! The query returned with an error.";
}
// You could analyze the response and communicate
// with your customer based on the response.
// In my case, S2 Member handles all communication.
}
}
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment