if( isset( $_POST['api_nonce_field'] ) && wp_verify_nonce( $_POST['api_nonce_field'], 'api_nonce' ) && !empty($_POST['key'])){
$purchase_key = $_POST['key'];
$item_id = 19386460;
//'c8f37d37-52e2-4fed-b0ac-e470ba475772'
$purchase_data = verify_envato_purchase_code( $purchase_key );
if( isset($purchase_data['verify-purchase']['buyer']) && $purchase_data['verify-purchase']['item_id'] == $item_id) {
update_option( 'theme_activation', 'activated' );
echo '<p class="successful"> '.__( 'Valid License Key!', 'sample-text-domain' ).' </p>';
} else{
echo '<p class="error"> '.__( 'Invalid license key', 'sample-text-domain' ).' </p>';
}
}
echo '</div>';
}
$status = get_option( 'theme_activation' );
if(empty($status) || $status != 'activated'){
add_action( 'admin_notices', 'Listingpro_activation' );
}
}
function verify_envato_purchase_code($code_to_verify) {
// Your Username
$username = 'CridioStudio';
// Set API Key
$api_key = 'd22l6udt6rk9s36spidjjlah3nhnxw77';
// Open cURL channel
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, "http://marketplace.envato.com/api/edge/". $username ."/". $api_key ."/verify-purchase:". $code_to_verify .".json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Set the user agent
$agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)';
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
// Decode returned JSON
$output = json_decode(curl_exec($ch), true);
// Close Channel
curl_close($ch);
// Return output
return $output;
}