google_auth( $code ); break; } do_action('timetics_integration_auth', $query_var, $code ); $redirect_url = admin_url('admin.php?page=timetics#/my-profile'); if ( current_user_can('manage_options') ) { $redirect_url = admin_url('admin.php?page=timetics#/settings'); } wp_safe_redirect( $redirect_url ); exit; } /** * Authentication for google * * @param string $code * * @return void */ public function google_auth( $code = '' ) { $client = timetics_get_google_client(); // If no code is provided, redirect to Google's authorization page. if ( empty( $code ) ) { $state = wp_create_nonce( 'timetics_auth_callback' ); $client->add_scope( Calendar::scope() ); $auth_url = $client->get_auth_url( $state ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- Redirecting to external Google OAuth URL. wp_redirect( $auth_url ); exit; } try { $client->add_scope( Calendar::scope() ); $data = $client->fetch_access_token_with_auth_code( $code ); $data['code'] = $code; timetics_update_google_auth( get_current_user_id(), $data ); wp_safe_redirect(admin_url('admin.php?page=timetics#/settings')); exit; } catch (\Exception $e) { $error_message = sprintf( '

%s

Go Back

', esc_html( $e->getMessage() ), esc_url( admin_url('admin.php?page=timetics#/settings') ) ); wp_die( wp_kses_post( $error_message ), esc_html__('Google Auth Error', 'timetics'), array('back_link' => true)); } } /** * Authentication for zoom * * @param string $code * * @return void */ public function zoom_auth( $code = '' ) { // Override this function to authenticate zoom } }