Skip to content

Instantly share code, notes, and snippets.

@thaboklass
Created June 17, 2021 11:35
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 thaboklass/a7e61079d3d5c0bf1d28369d402986cc to your computer and use it in GitHub Desktop.
Save thaboklass/a7e61079d3d5c0bf1d28369d402986cc to your computer and use it in GitHub Desktop.
<?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