function plugin_init() { if (is_admin()) { if (isset($_GET['action']) && $_GET['action'] == "oauth_grant") { if (isset($_GET['code'])) { $authCode = $_GET['code']; $accessToken = GmailXOAuth2::resetCredentials($authCode); if (isset($accessToken) && !empty($accessToken)) { //echo __('Access Granted Successfully!', 'gmail-smtp'); $_GET['gmail_smtp_access_granted'] = "yes"; } else { $_GET['gmail_smtp_access_granted'] = "no"; } } else { // If we don't have an authorization code then get one $authUrl_array = GmailXOAuth2::authenticate(); if (isset($authUrl_array['authorization_uri'])) { $authUrl = $authUrl_array['authorization_uri']; wp_redirect($authUrl); exit; } } // Unix timestamp of when the token will expire, and need refreshing // echo $token->expires; } } }