should_handle_auth_code() ) { return; } $code = sanitize_text_field( $_GET['code'] ); $state = sanitize_text_field( $_GET['state'] ); // Check if the state is valid $this->validate_nonce( $state ); // Exchange the code for an access token and store it Service::get_token( GrantTypes::AUTHORIZATION_CODE, $code ); // Redirect to the redirect URI wp_redirect( Utils::get_redirect_uri() ); exit; } /** * Handler constructor. */ public function __construct() { add_action( 'admin_init', [ $this, 'handle_auth_code' ] ); } }