Created
June 17, 2021 11:35
-
-
Save thaboklass/a7e61079d3d5c0bf1d28369d402986cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Connect the widget to the user's RobberBaron account by | |
* sending a JSON reguest that will return the user's IS | |
* | |
* @param none | |
* @return none | |
*/ | |
function robber_baron_tv_connect() { | |
// Validate email | |
$robber_baron_tv_from_email = is_email($this->robber_baron_tv_email_address); | |
if ($robber_baron_tv_from_email) { | |
// Construct a JSON object | |
$robber_baron_email_object = (object) [ | |
'email' => $this->robber_baron_tv_email_address | |
]; | |
// Encode it to actual JSON | |
$robber_baron_JSON = json_encode($robber_baron_email_object); | |
// Initiate the JSON request | |
$data = wp_remote_post('https://robberbaron.tv/api/v1/getuserid', array( | |
'headers' => array('Content-Type' => 'application/json; charset=utf-8'), | |
'body' => $robber_baron_JSON, | |
'method' => 'POST', | |
'data_format' => 'body', | |
)); | |
// Parse the response | |
$response_array = json_decode($data['body'], true); | |
// If the response is 'not found', the email was wrong | |
if ($response_array['uid'] != 'not found') { | |
update_option('robber_baron_tv_connected', 'true'); | |
update_option('robber_baron_tv_user_id', $response_array['uid']); | |
} else { | |
update_option('robber_baron_tv_user_id', ''); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment