|
<?php |
|
|
|
class Optin_Form { |
|
|
|
public function __construct() { |
|
add_action( 'wp_ajax_process_optin_submission', array( $this, 'process' ) ); |
|
add_action( 'wp_ajax_nopriv_process_optin_submission', array( $this, 'process' ) ); |
|
} |
|
|
|
public function process() { |
|
if( ! wp_verify_nonce( $_POST['nonce'], 'ouibounce' ) ) |
|
return; |
|
|
|
$data = array( |
|
'email' => $_POST['email'] |
|
); |
|
|
|
$curl = curl_init(); |
|
curl_setopt_array( $curl, array( |
|
CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'Accept: application/json' ), // -H parameter |
|
CURLOPT_RETURNTRANSFER => 1, // so that we can catch the response in a variable |
|
CURLOPT_URL => 'http://reqr.es/api/users', // The endpoint |
|
CURLOPT_POST => 1, // -X POST |
|
CURLOPT_USERPWD => 'app_id:api_key', // -u parameter (not always needed) |
|
CURLOPT_POSTFIELDS => json_encode( $data ) // because we set Content-Type to JSON |
|
) ); |
|
|
|
$resp = curl_exec( $curl ); |
|
curl_close( $curl ); |
|
print_r( $resp ); |
|
wp_die(); |
|
|
|
} |
|
|
|
public function render() { ?> |
|
<div class="modal-cover" id="js-optin-wrap"> |
|
<div class="modal"> |
|
<div id="js-optin-step1"> |
|
<h1>Hey there!</h1> |
|
<p>Want to be <strong>awesome</strong>? Subscribe!</p> |
|
<form> |
|
<input type="text" id="js-optin-email" placeholder="Your email" /> |
|
<input type="submit" id="js-optin-submit" value="Sign me up!" /> |
|
</form> |
|
<br /> |
|
<a href="#" class="js-optin-close">No thanks.</a> |
|
</div> |
|
<div id="js-optin-step2" style="display:none;"> |
|
<h1>You've been subscribed!</h1> |
|
<br /> |
|
<a href="#" class="js-optin-close">Close.</a> |
|
</div> |
|
</div> |
|
</div> |
|
<?php |
|
} |
|
} |