jQuery(document).ready(function($) { window.onTelegramAuth = function(user) { $.ajax({ type: 'POST', url: telegram_auth_params.ajax_url, data: { action: 'ontelegramauth', userid: user.id, username: user.username || '', fname: user.first_name || '', lname: user.last_name || '', photo_url: user.photo_url || '', auth_date: user.auth_date, hash: user.hash }, success: function(response) { if (response.success) { window.location.href = telegram_auth_params.my_account_url; } else { alert(telegram_auth_params.i18n_error + ': ' + (response.data.message || 'Unknown error')); } }, error: function() { alert(telegram_auth_params.i18n_error); } }); }; window.linkTelegram = function(user) { $.ajax({ type: 'POST', url: telegram_auth_params.ajax_url, data: { action: 'linktelegram', userid: user.id, username: user.username || '', fname: user.first_name || '', lname: user.last_name || '', photo_url: user.photo_url || '', auth_date: user.auth_date, hash: user.hash }, success: function(response) { if (response.success) { $('.cabinet-accounts').html(''); } else { alert(telegram_auth_params.i18n_error_link + ': ' + (response.data.message || 'Unknown error')); } }, error: function() { alert(telegram_auth_params.i18n_error_link); } }); }; });